Working on a project that interacts with objects around it usually requires you to select a distance or range finding sensor. For example, you might use distance sensors for human presence detection, robotics, or industrial applications. The application and environment in which the project will be deployed can be a significant guiding factor in deciding which sensor to look at, as some will have superior performance over other options in some conditions.
Depending on your application, you’d usually be choosing from three main classes for distance sensors:
Optical sensors typically work using a time of flight approach, timing how long a laser or other light source takes to hit the target. Some optical sensors work purely on the amount of light reflected back. Optical sensors perform best in darker environments rather than in direct sunlight, as it’s harder for a sensor to capture the light it’s emitting against the background light. Among them, reflectance sensors typically work best with white or light-colored objects, and the range sensed can vary significantly with the color of the object it is directed at.
There are a wide variety of sensing methods used in electromagnetic sensors. In industrial applications, you will commonly find inductance sensors being used for proximity detection. As a metal object comes close, it detunes the sensor’s coil, which can be used to measure proximity, although typically, with a very limited range.
Capacitive sensors are probably the distance sensor you interact with the most. Every time you interact with your phone’s touch-screen, you’re using a capacitive distance sensor. Capacitive touch/proximity sensors are very short-range sensors which lack the ability to measure exact distances. You won’t find a prebuilt capacitive distance sensor as you will with other types of sensors, instead you will find an IC that you need to connect to a couple of components and to a plate (PCB trace, polygon pour, or external) that will act as the capacitor, depending on the sensing range you require.
Using radio waves in radar-based sensors can give you very long ranges and incredibly precise measurements. When radar is mentioned, million-dollar weather, air traffic control, or similar radar installations with huge antenna arrays or dishes in a dome come to mind, but you can get a full radar sensor in a similarly sized and priced package to the other sensors discussed in this guide.
Acoustic sensors, such as sonar, operate almost exclusively in the ultrasound range. If they operated in a range which humans could hear, they would constantly buzz, driving us crazy when working with them. The ultrasound sensors you are probably most familiar with are the car parking aids beeping at you when the car thinks you are too close to something. The main drawbacks for ultrasonic sensors are the reduced performance in windy conditions, and the limited ability to use multiple sensors utilizing the same frequency at the same time. Additionally, the object being sensed needs to be approximately perpendicular to the sensor.
When selecting a distance sensor, there are a few criteria you’ll need to consider:
Most likely, your primary consideration will be sensing range, both minimum and maximum. Some applications, like the proximity sensor that turns off your phone’s screen during calls, may simply need to know that something is within range, whilst others might want to know a precise distance. You’ll find optical sensors that can measure from about five millimeters to around 40 meters, giving the most diverse range of possibilities in any of the possible technologies. Capacitive and inductive sensors are typically limited to tens of millimeters and ultrasonic sensors operate from tens of millimeters to a couple of meters.
As mentioned earlier, some sensors have environmental limitations beyond the typical temperature ranges that apply to most electronic components. Primarily, this applies to optical sensors, which can be affected by bright ambient light or by light directed at the sensor itself.
Most sensors have a cone-shaped sensing range, which may not be an issue for your application, but should be kept in mind. Typically, a longer range sensor has a narrower field of view. Like most electromagnetic radiation patterns, the maximum range is typically directly in front of the sensor, with falloff the more you approach the maximum field of view. If you are looking for presence detection in a wide area around your device or within a very narrow area, this might be critical to your application.
Parallax Ping))) Sensing Range (from datasheet)
If the sensor you are building needs to be on a board that is within an enclosure, this could strongly influence your choice. Optical sensors will typically need an infrared transparent window to ‘see’ through, which could be highly limiting to the enclosure design. Radar, capacitive, and inductive sensors need to be able to get electromagnetic waves out, which typically means you won’t be able to use metal and will have to resort to a plastic or fiberglass aperture of some sort. Ultrasound sensors almost always need to be completely exposed. While some have integrated covers, you will likely not be able to place any form of housing over the sensor.
Many sensors for range finding have an analog output that is either ratiometric or within a fixed range. More modern sensors utilize SPI, I2C, or offer a range of interfaces. If you are using the sensor for simple detection of an object entering its range, an analog output can be used with some basic circuitry to generate an interrupt for a sleeping microcontroller. Digital protocols, on the other hand, allow for more accurate distance sensing, as they will perform the conversion internally against a formula for the device’s response that is more accurate or complex than what you might be given in a datasheet or use on a microcontroller.
(up to 2 meters) (up to 4 meters)
The Sharp GP2Y0A series infrared reflectance distance sensors held the throne for low-cost optical sensors for many years, but ST’s new part easily steals it away. I have used the Sharp sensors in many projects, but I’ll be using the VL53 series for everything I would have used the Sharp sensors for in the past. These are tiny, cost-effective sensors which work behind glass—such as you’d find in a smartphone—and use phase measurement rather than reflectance. As mentioned earlier, reflectance is a real struggle to get accurate measurements from, due to the fact that a darker object will have less reflectance and therefore look further away than a white object at the same distance. By using time-of-flight instead, these sensors are able to precisely measure objects regardless of color or shade making them far more reliable. As they still can only function on the reflected infrared laser from the object, bright ambient light that includes an IR component (like sunlight) may reduce the effective range of these sensors.
These are very popular, as you’ll see from the large number of breakout board options in the links above. Furthermore, if you need very short-range sensing, there is also the VL61 sensor that is capable of reading a maximum of 100 millimeters.
The Panasonic GX series is a series of inductive proximity switches which offer a range of switching distances. I like the series over cheap Chinese sensors and other western brands as it offers the superior repeatability and precision needed for industrial equipment. It is more expensive than other alternatives, but for my applications, precision is much more important. You might use one of these in anything CNC related for non-contact homing or limit switches, for counting gear teeth as a means of encoding, or for 3D printer bed leveling.
If you’re not looking for a non-contact switch, then the TI LDC1101 lets you build the sensor you need. Attach a coil and a few passive components and you can quickly sense the size or distance of a metal object. You can also build very high count rotary encoders which work well in oily conditions or measure micrometers of travel for a metal object within the inductance field of your coil.
If you have a microcontroller, you can measure capacitance changes fairly crudely with just two pins, a resistor, and a large copper area.
If you’re looking for something more precise (far more!) than the crude method, TI’s capacitance-to-digital converter is a cost-effective way to build your own capacitive proximity sensor. As with the inductive part above, this allows you to build a circuit to requirements, using a capacitive plate rather than a coil. With a capacitive sensor, you can measure micron distance changes, or just the fact that a human is nearby. Capacitive sensors are great for lighting up a display or interface when a human reaches towards it. My car’s sat nav makes great use of capacitive proximity sensing by only displaying user interface buttons at the bottom of the screen when your hand is near it, otherwise, the map takes up the whole display.
I discovered this gem a few months ago, and as it turns out, it has been in development for a long time and they have put a lot of work into developing such a tiny radar unit. The usable range is limited to about two meters and a minimum distance of 60 millimeters, however, it does feature millimeter absolute accuracy with relative accuracy far lower than that. Because it uses radar, you can hide it behind a plastic or fiberglass enclosure without any externally visible signs of the presence of a sensor. If you’re building wearable electronics or interactive devices, this feature allows for a clean look. This sensor is one I’m very keen to use in upcoming projects!
Maxbotix’s range of ultrasonic sensors has been the industry standard for many years for good reasons. They are both easy to use and relatively precise, and there is a range of options that offer many sensing distances and fields of view. With just a single ultrasonic transceiver, they are easier to integrate into a product than the slightly cheaper dual transceiver modules such as the Parallax Ping units.
There are a wide variety of distance sensors suitable for an even wider variety of applications. Each of them has its advantages and drawbacks, and I hope this article has given you enough insight as to which suits your application the best. If you found this article helpful, feel free to check out some of my other articles on the blog, which discuss other aspects of building electronics products.
We hope you found this article useful! If you'd like to have content like this delivered to your inbox, sign up for our monthly newsletter!