Ultrasonic & Proximity Sensing: The Ultimate Guide
How robots feel their near field: ultrasonic ranging physics, inductive/capacitive/photoelectric proximity, specs, blind zones, and how to pick one.
Long before a robot resolves a room with LiDAR or reasons about a scene with a depth camera, it has to answer a cruder question hundreds of times a second: is something close, and roughly how close? That near-field band, from a few millimetres out to a few metres, is owned by a family of cheap, rugged, single-purpose sensors that rarely make the spec-sheet headlines but sit on nearly every machine that moves or handles parts. An autonomous mobile robot has a skirt of ultrasonic transducers watching for a chair leg the laser plane missed. A gripper has a photoelectric beam confirming the part actually arrived before it closes. A conveyor has an inductive barrel counting steel cans without ever touching one. These are the presence and proximity sensors, and they do the unglamorous work that keeps a robot from driving into furniture or grasping empty air.
This guide is about that layer. It covers ultrasonic ranging, where a robot times a pulse of sound, and the proximity-switch families (inductive, capacitive, photoelectric, and IR reflective or break-beam) that report presence within a fixed sensing distance. We go through the physics that makes each one work and the physics that makes each one fail: the speed of sound and its temperature dependence, the beam cone that sets angular resolution, the ring-down that creates a blind zone, the eddy currents that let a coil feel steel through a millimetre of air, the light budget that decides whether a photoelectric beam survives a dusty aisle. Then we get concrete about the specs that bind (range, blind zone, beam angle, response time, hysteresis), the environmental limits that ambush integrators, and how to choose. The long-range mapping sensors live in the LiDAR and depth cameras guide; this is the guide to everything shorter and simpler.
The take: ultrasonic and proximity sensors are the cheap near-field reflexes of a robot, and their value is exactly that they are cheap, rugged, and simple. An ultrasonic ring catches the acoustically reflective obstacles (glass, a table edge, a person in a dark aisle) that fool a laser, and a $15 inductive switch confirms a part is in a fixture far more reliably in a dirty cell than any camera. The engineering that matters here is knowing each sensor's blind zone, beam cone, target dependence, and failure surface, so you deploy the one whose physics matches the target and the environment rather than the one with the biggest number on the box.
Companion reading: robot sensors, LiDAR and depth cameras, mobile robots (AMR/AGV), industrial automation (PLC/SCADA/fieldbus), and cleaning and domestic robots.
Table of contents
- Key takeaways
- Where near-field sensing fits
- Ultrasonic ranging: how timing sound works
- The ultrasonic beam, blind zone, and crosstalk
- The proximity-switch families
- Inductive proximity sensors
- Capacitive proximity sensors
- Photoelectric and IR sensors
- The comparison table
- Specs that matter and reading a datasheet
- Environmental limits and failure modes
- Integration, wiring, and interfaces
- Selecting a near-field sensor
- Frequently asked questions
Where near-field sensing fits
A robot's exteroceptive sensing spans a range of scales. At the far end sit LiDAR and depth cameras building a metric 3D model of the room, covered in their own guide. At the near end, from a few millimetres to a few metres, sits a different job entirely: detecting presence and coarse distance cheaply, fast, and with brutal reliability. That is the domain of ultrasonic and proximity sensing.
The distinction is worth drawing because it drives architecture. A mapping sensor answers "what does the world look like"; a proximity sensor answers "is something in this specific spot right now." The second question is smaller, and because it is smaller it can be answered by a sensor that costs a few dollars, draws almost no power, survives coolant and dust, and gives a clean binary or a single distance number with no perception stack behind it. A robot vacuum uses a bump switch and a cliff sensor, not a segmentation network, to avoid falling down the stairs. An AMR uses an ultrasonic skirt, not a second LiDAR, to catch the glass door its scan plane sees straight through.
The two layers are complementary, and the common failure is trying to make one do the other's job. LiDAR is blind to a clear glass wall because the beam passes through it; ultrasonic sees the glass fine because sound reflects off it. A camera cannot reliably confirm a small steel part landed in a fixture in an oily, badly-lit cell; a $15 inductive switch does it every cycle for years. The near-field sensors are the reflexes that fill the gaps a mapping sensor leaves, and they earn their place precisely because they are cheap enough to scatter around a machine wherever a blind spot lives.
Rule of thumb: use a mapping sensor to understand the scene and a proximity sensor to guard a specific spot. If the question is "is there an obstacle somewhere in front of me," that is perception. If the question is "did the part arrive at station 4," that is a proximity switch, and a switch will outlast and out-reliable any camera you point at it.
Ultrasonic ranging: how timing sound works
An ultrasonic ranger emits a short burst of sound above the audible band (commonly 40 kHz for air-coupled sensors, up to hundreds of kHz for short-range precision units), then listens for the echo. Distance is half the round trip, because the sound travels out to the target and back:
Range: d = (c · t) / 2
c = speed of sound in air ≈ 343 m/s at 20 °C
t = round-trip time of flight
Example: an echo returns 5 ms after the ping
round-trip distance = 343 · 0.005 = 1.715 m
d = 1.715 / 2 ≈ 0.86 m
The transducer is usually a piezoelectric element: a ceramic disc that flexes when driven with an AC voltage (transmit) and generates a voltage when flexed by an incoming pressure wave (receive). Cheap modules use two separate elements, one to send and one to receive; compact and rugged units use a single element that does both, which is where the blind zone comes from (next section). Some automotive and industrial sensors are capacitive (electrostatic) transducers, which have wider bandwidth and a shorter ring-down at the cost of needing a bias voltage.
The temperature trap
The one physical fact that quietly wrecks ultrasonic accuracy is that the speed of sound changes with the medium's temperature:
Speed of sound in dry air:
c(T) ≈ 331.3 · sqrt(1 + T/273.15) m/s, T in °C
T = 0 °C → c ≈ 331.3 m/s
T = 20 °C → c ≈ 343.2 m/s
T = 40 °C → c ≈ 354.7 m/s
That is roughly +0.6 m/s for every degree Celsius, about +0.17% per °C. A ranger calibrated at 20 °C and used at 0 °C computes distance with a c that is 3.5% too high, so it over-reports range by 3.5%: a 1 m target reads as 1.035 m. Humidity adds a smaller correction (moist air is slightly faster), and altitude matters through temperature rather than pressure. For coarse obstacle detection the error is tolerable. For anything that must be accurate (tank level, precise positioning) you either put a temperature sensor next to the transducer and correct c in firmware, or you use a reference target at a known distance to self-calibrate. Industrial ultrasonic sensors almost always include internal temperature compensation for exactly this reason.
The other range limits
Two more effects cap ultrasonic range and accuracy. First, absorption: air attenuates ultrasound, and the attenuation rises steeply with frequency, so a 40 kHz sensor reaches several metres while a 200 kHz precision sensor reaches only tens of centimetres. Higher frequency buys a tighter beam and finer resolution but costs range. Second, the echo amplitude falls with distance and with the target's acoustic properties: a hard flat surface facing the sensor returns a strong echo, while a soft, angled, or sound-absorbing surface (foam, cloth, a person in a thick coat) returns little and can vanish into the noise floor before the datasheet's maximum range. The honest maximum range is always against a large flat perpendicular target; real obstacles fall short of it.
The ultrasonic beam, blind zone, and crosstalk
Three quirks of ultrasonic sensing trip up every first-time integrator: the beam is wide, there is a dead zone up close, and multiple sensors interfere with each other.
The beam is a cone
An ultrasonic transducer does not emit a pencil beam. It radiates a cone whose spread is set by diffraction: a wave of wavelength λ leaving an aperture of diameter D cannot be confined tighter than roughly
Beam half-angle: θ ≈ asin(1.22 · λ / D)
at 40 kHz: λ = c/f = 343 / 40000 ≈ 8.6 mm
a 16 mm transducer: θ ≈ asin(1.22 · 8.6 / 16) ≈ 41° (full lobe wide)
At 40 kHz the wavelength is large (about 8.6 mm), so a small transducer radiates a broad main lobe, often 15 to 60 degrees full angle, plus side lobes. The consequence: an ultrasonic ranger reports the distance to the nearest strong reflector anywhere in that cone, with no idea of the angle. It cannot tell you a wall is off to the left rather than dead ahead, and it will pick up a nearby side object (a door frame, the robot's own bumper) as a false close reading. Higher-frequency sensors have shorter wavelengths and narrower cones, which is one reason precision short-range units run at 200 kHz or more. For obstacle detection the wide cone is actually useful, since it gives broad coverage from one sensor, but you must not treat the reading as a point measurement.
Ring-down and the blind zone
A single-element transducer transmits by ringing the piezo ceramic hard, then switches to listening. The problem is that the ceramic keeps vibrating for a short time after the drive stops, exactly like a struck bell, and while it rings it is deaf to the faint returning echo. This ring-down creates a blind zone: any target closer than the distance sound travels during the ring-down time is invisible, because its echo arrives while the element is still ringing from its own transmission. Blind zones typically run from about 4 cm on short-range sensors to 25 or 30 cm on long-range ones. It is the single most surprising ultrasonic limitation: the sensor that reads reliably out to 4 m may be completely blind to an object 10 cm from its face. Designs shorten the blind zone with damped transducers, separate send and receive elements, or higher frequencies, but it never goes to zero on an air-coupled sensor.
War story: an AMR with an ultrasonic bumper ring kept grazing pallet corners it should have stopped for. The sensors were rated to 4 m and tested fine on the bench against a wall. In the aisle the corners were entering the 20 cm blind zone before the robot reacted, because the sensors were mounted flush at the leading edge and the robot's stopping distance put the target inside the dead band by the time it mattered. The fix was mounting the transducers recessed a hand's width back from the bumper so the blind zone sat inside the robot's own body, plus adding a short-range diffuse photoelectric sensor for the last 15 cm. The ultrasonic was never wrong; it was aimed so its blind zone lived exactly where the collision happened.
Crosstalk
Put several ultrasonic sensors near each other (a ring around a robot) and they hear each other's pings. Sensor A fires, and sensor B, listening at the same instant, mistakes A's pulse for its own echo and reports a phantom close object. This crosstalk is why ultrasonic arrays must be time-multiplexed: fire the sensors in sequence with enough gap for the previous ping's echoes to die out, or code each sensor's burst so it only accepts its own signature. Time-multiplexing is the usual answer, and it is why an ultrasonic ring's effective update rate is the single-sensor rate divided by the number of sensors, which can drop a 12-sensor ring to a few hertz overall. Crosstalk also happens between robots: two AMRs passing in an aisle can spoof each other's ultrasonics, a real and hard-to-reproduce field fault.
The proximity-switch families
Proximity switches answer a simpler question than a ranger: is a target within the sensing distance, yes or no. They output a binary signal (occasionally an analog distance) and are the backbone of industrial presence detection. Four families dominate, each defined by the physics of what it can sense.
- Inductive: senses metal only, via the eddy currents a target induces in the sensor's oscillating field. Very short range, extremely rugged.
- Capacitive: senses any material by the change it makes to a capacitance, including liquids and powders through a container wall. Medium sensitivity, environment-sensitive.
- Photoelectric: senses anything that blocks or reflects a modulated light beam, at the longest ranges of the group. Comes in through-beam, retroreflective, and diffuse variants.
- IR reflective and break-beam: the cheap, coarse cousins of photoelectric, common on small robots and consumer devices.
Magnetic (reed and Hall) switches sense a magnet specifically and belong to the same family of binary presence detectors, covered briefly under integration. The choice among the four is driven first by the target: what is it made of, how far away, and in what environment.
Inductive proximity sensors
The inductive proximity switch is the most common industrial sensor in the world, and it detects one thing: metal, at close range, without touching it.
How it works
Inside the barrel is a coil driven as part of an LC oscillator, radiating a high-frequency magnetic field from the sensing face. When a conductive (metal) target enters that field, the changing flux induces eddy currents in the target's surface. Those eddy currents dissipate energy, which loads and damps the oscillator, reducing its amplitude. The sensor's trigger circuit watches the oscillation amplitude and switches its output when the damping crosses a threshold. No contact, no moving parts, no wear.
Because the mechanism is eddy currents, the sensor responds only to conductors, and it responds most strongly to ferrous metals. The rated sensing distance is quoted for a standard target: a square of mild steel (Fe 360) of a defined size and 1 mm thickness. Other metals derate it through a correction factor:
Rated distance × correction factor (typical):
mild steel (Fe 360) 1.00 (the reference)
stainless steel ~0.70
brass ~0.40
aluminium ~0.35
copper ~0.30
An aluminium target is sensed at roughly a third of the distance of a steel one of the same size, because aluminium's high conductivity and non-ferrous nature change the eddy-current coupling. This catches people out constantly: a sensor set up on a steel jig fails when the part is swapped to aluminium.
Shielded vs unshielded
Shielded (flush-mountable) sensors have a metal collar focusing the field forward, so they can be embedded flush in a metal fixture without the surrounding metal triggering them, at the cost of shorter range. Unshielded (non-flush) sensors radiate a wider field for longer range but need a clear zone of non-metal around the face. Choosing wrong (mounting an unshielded sensor flush in steel) gives a sensor that triggers permanently on its own housing.
Typical sensing ranges are short: 1 to 2 mm for small M8 barrels, up to 10 to 15 mm for larger M30 units, with long-range variants reaching a few tens of millimetres. The virtues are what make them ubiquitous: fully sealed (IP67, often IP69K for washdown), immune to dust, oil, coolant, and vibration, response times in the tens of microseconds to low milliseconds, and a service life measured in billions of cycles because nothing touches. They confirm part presence in fixtures, count metal objects on conveyors, sense actuator end positions, and detect gear teeth for speed sensing.
Capacitive proximity sensors
The capacitive proximity switch trades the inductive sensor's ruggedness for the ability to sense almost anything.
How it works
The sensing face forms one plate of a capacitor; the target (and the surrounding environment) forms the other. As a target approaches, it changes the capacitance seen by an oscillator circuit, and when the change crosses a threshold the output switches. Because the mechanism is dielectric and charge rather than eddy currents, a capacitive sensor responds to any material that alters the field: metals (strongly), but also plastics, glass, wood, liquids, grain, and powders. The response scales with the target's dielectric constant, so water and metal trigger at longer distance than dry plastic or cardboard.
This makes capacitive sensors the tool for level and fill sensing. Mounted on the outside of a plastic or glass tank, a capacitive sensor detects the liquid level through the wall, because the liquid's high dielectric constant changes the capacitance far more than the empty air behind the wall does. They also detect non-metallic parts, count boxes, and sense material in hoppers and silos.
The catches
The same sensitivity that makes them versatile makes them fussy. A capacitive sensor responds to humidity, condensation, and material buildup on the face, any of which can shift the trigger point or cause false switches. Most industrial capacitive sensors have a sensitivity adjustment (a potentiometer or teach button) so you can tune out the container wall and background and trigger only on the target. Ranges are modest, typically 1 to 25 mm, comparable to inductive but with the material flexibility. The tuning burden and environmental drift are why capacitive sensors are chosen when the target is non-metallic or hidden behind a wall, and inductive is preferred whenever the target is metal and exposed.
Photoelectric and IR sensors
When you need proximity or presence detection at longer range than a few centimetres, the answer is usually optical. Photoelectric sensors use a modulated light source (almost always an LED, visible red or infrared, sometimes a laser) and a photodetector, with the light modulated at a known frequency so the receiver rejects ambient light by only accepting the modulation. Three geometries cover the field.
Through-beam (opposed)
Emitter and receiver are separate units facing each other across the detection zone. A target is detected when it breaks the beam. This is the most reliable and longest-range photoelectric mode (ranges to tens of metres, some to 60 m), because the receiver sees the full direct beam and only needs the target to block it. It works on nearly any opaque target regardless of colour or surface, and it tolerates dust and dirt better than reflective modes because there is signal margin to spare. The cost is running and aligning two separate units with wiring on both sides.
Retroreflective
Emitter and receiver share one housing, and a reflector (a corner-cube prism panel) is mounted opposite. The sensor detects a target that breaks the beam between it and the reflector. This halves the wiring and mounting of through-beam while keeping decent range (a few metres to about 10 m). The classic failure mode is a shiny target that reflects the beam back as well as the reflector does, so the sensor never sees it as "broken"; polarized retroreflective sensors fix this by using a polarizing filter that only accepts the specific polarization rotation the corner-cube reflector produces, rejecting the shiny target's mirror reflection.
Diffuse (reflective)
Emitter and receiver share one housing and there is no reflector; the sensor detects light bounced back off the target itself. This is the simplest to install (one unit, no reflector, no opposing wiring) and the most target-dependent, because the return signal depends entirely on the target's colour, reflectivity, angle, and distance. A white box is detected far; a matte black one barely at all. Ranges run from centimetres to a metre or two. Variants improve on plain diffuse: background suppression (BGS) uses triangulation with a position-sensitive detector so it triggers only within a set distance and ignores a bright wall behind the target, and fixed-field sensors define a fixed detection window. Diffuse with background suppression is the workhorse for detecting parts on a conveyor when you cannot mount anything on the far side.
IR reflective and break-beam
The consumer and hobby end of the same physics: an IR LED and a photodiode, either reflective (detect a nearby surface, as in line-following and cliff detection on a robot vacuum) or break-beam (an emitter and detector pair forming a tripwire, as in a gripper detecting a grasped part). Cheap, coarse, and heavily surface-dependent, but perfectly adequate for edge detection, presence in a gripper, and short-range obstacle sensing on small robots. The cleaning and domestic robots guide is full of these: a robot vacuum's cliff sensors are downward-facing IR reflective sensors that trigger when the floor suddenly stops returning light.
The comparison table
| Sensor | Range | Target | Best at | Weak at |
|---|---|---|---|---|
| Ultrasonic | 2 cm to 6 m | Any acoustically reflective surface | Glass, clear plastic, shiny, liquid level; sees what optics miss | Slow (sound speed), wide cone, temperature drift, blind zone, soft/angled targets |
| Inductive | 1 to 15 mm | Metal only | Rugged metal presence in dirty/oily cells | Metals only, very short range, derates on non-ferrous |
| Capacitive | 1 to 25 mm | Any material (metal, plastic, liquid, powder) | Level/fill through a wall, non-metallic presence | Humidity/buildup drift, needs tuning, short range |
| Photoelectric through-beam | up to 60 m | Any opaque object | Longest, most reliable optical detection | Two units to wire and align |
| Photoelectric retroreflective | up to ~10 m | Any opaque object | One unit + reflector, good range | Shiny targets (needs polarized version) |
| Photoelectric diffuse (BGS) | cm to ~2 m | Any object it can reflect off | Single-unit detection, no far-side mounting | Target colour/reflectivity dependence |
| IR reflective / break-beam | 1 to 80 cm | Nearby reflective surface / any blocker | Ultra-cheap presence, cliff, line-follow | Coarse, surface-dependent, ambient light |
Specs that matter and reading a datasheet
The same handful of parameters decides whether any of these sensors works in your application. Learn to read them and you can size any near-field sensor.
- Rated sensing distance (Sn): the nominal detection range, always quoted for a specified standard target. For inductive it is the steel reference square; for photoelectric diffuse it is a standard white card (often 90% reflectance). Your real target derates it: apply the correction factor for the material (inductive) or expect much shorter range on dark or angled targets (diffuse). The assured operating distance (typically 0 to 0.8 times Sn) is the range you actually design to, giving margin over temperature and target variation.
- Blind zone (dead band): the minimum distance an ultrasonic sensor can measure, set by ring-down. For a wrist or bumper application the blind zone is frequently the binding constraint, not the maximum range: you cannot detect what is too close.
- Beam / cone angle: for ultrasonic, the width of the emission lobe (15 to 60 degrees), which sets how coarsely it localizes and how much side clutter it picks up. For photoelectric, the effective spot size and angular alignment tolerance.
- Hysteresis: the gap between the switch-on distance and the switch-off distance, typically a few percent of Sn. Hysteresis exists on purpose: it stops the output chattering when a target sits right at the threshold and vibration nudges it across. A target parked exactly at the edge with too little hysteresis produces a rapidly toggling output that looks like a wiring fault.
- Response time and switching frequency: how fast the output reacts and how many targets per second it can distinguish. Inductive and photoelectric switch in tens of microseconds to a few milliseconds and handle hundreds to thousands of hertz. Ultrasonic is throttled by the round-trip time of sound, so a sensor watching a 1 m target updates at best around 150 Hz and an array much slower after time-multiplexing.
- Repeatability: does the sensor trigger at the same distance every time? For a positioning or counting task, repeatability matters more than absolute accuracy, since a fixed offset calibrates out but a wandering one does not.
- Output type: the electrical interface (next section). PNP vs NPN, normally-open vs normally-closed, and whether the output is discrete (switch) or analog (a distance signal). Getting this wrong is the most common integration mistake.
Rule of thumb: never read the maximum range without reading the target it was measured against. An inductive "15 mm" is 15 mm on steel and 5 mm on aluminium; a diffuse photoelectric "1 m" is 1 m on a white card and 20 cm on matte black. Design to the assured operating distance for your actual target, not the headline Sn.
Environmental limits and failure modes
Each family fails in a characteristic way, and knowing the failure surface is how you avoid deploying the wrong sensor into the wrong environment.
Ultrasonic fails on soft, angled, and sound-absorbing targets. Foam, cloth, insulation, and a person in a thick coat return little echo. A target angled more than about 30 degrees from perpendicular deflects the echo away from the transducer entirely, so a flat surface the sensor should see becomes invisible. Wind and strong air currents can bend or disperse the pulse over longer ranges. Temperature drift shifts the distance reading unless compensated. And the blind zone plus wide cone make ultrasonic a coarse tool, good for "something is roughly this far away" and poor for precise localization.
Inductive is the most robust of the group but sees metal only, at very short range. Its failures are almost always setup errors: an unshielded sensor mounted flush in metal, a sensor sized for steel used on aluminium, or the sensing face crashed into by the target because the range is so short. Strong external magnetic fields (nearby welding, large motors) can disturb some units.
Capacitive is the environmentally fussiest. Condensation, high humidity, and material buildup on the face all shift the trigger point, and a sensor tuned in a dry morning cell can false-trigger in a humid afternoon. Washdown environments need careful selection and sometimes periodic re-teaching.
Photoelectric fights contamination and ambient light. Dust, mist, oil film, and fog on the lens attenuate the beam; through-beam has the most margin to spare and diffuse the least. Direct sunlight or another sensor's light can swamp the receiver, though modulation and, in laser units, tight spectral filtering reduce this. Reflective modes are fooled by unexpected shiny or dark targets. Alignment drift on through-beam from vibration or thermal expansion breaks the beam and reads a permanent target.
IR reflective shares the photoelectric weaknesses in cheaper form: heavily surface-dependent, easily washed out by sunlight, and short-ranged. A robot vacuum's cliff sensor can be fooled by a very dark carpet that returns as little light as a real drop, which is why some units cross-check multiple sensors.
Rule of thumb: match the sensing physics to the target and the environment before you look at any number. A shiny or transparent obstacle wants ultrasonic; a metal part in coolant wants inductive; a long clean detection line wants through-beam photoelectric; a hidden liquid level wants capacitive. Choosing on range alone and ignoring the physics is how you deploy a sensor that tests fine and fails in the field.
Integration, wiring, and interfaces
Getting the sensor right is half the job; wiring it into the controller correctly is the other half, and it is where a lot of bench-tested designs fall over.
Discrete outputs: PNP vs NPN, NO vs NC
Most industrial proximity switches are three-wire discrete sensors with a transistor output. The two conventions:
- PNP (sourcing): the output switches the positive supply to the load. Common in Europe and the default for most modern PLC inputs. The sensor sources current into the input.
- NPN (sinking): the output switches the load to ground. Common in Asia and older systems. The sensor sinks current from the input.
Mixing them (an NPN sensor into a PLC input expecting PNP) gives a sensor that never reads, or reads inverted, with no obvious wiring fault. Alongside this, each sensor is normally open (output active when target present) or normally closed (output active when target absent); NC is often chosen for safety-relevant detection so a broken wire reads as "target present" and fails safe. The industrial automation guide covers how these wire into PLC input cards and the fieldbus that carries them.
Analog and smart outputs
Ranging ultrasonic sensors and some photoelectric distance sensors output an analog signal (0 to 10 V or 4 to 20 mA) proportional to distance, or a digital value. The 4 to 20 mA current loop is the industrial standard because a broken wire reads 0 mA, distinguishable from a valid 4 mA "zero distance," giving built-in fault detection. Increasingly, sensors carry IO-Link, a point-to-point digital protocol over the same three wires that exposes the analog value, configuration, diagnostics, and remote teach, which turns a dumb switch into a configurable device the controller can query and re-parameterize without touching the hardware.
Hobby and robot-side interfaces
On the robot side of the fence, cheap ultrasonic modules like the HC-SR04 use a trigger/echo pair: pulse the trigger, then time the width of the echo pulse the module returns, which encodes the round-trip time. More capable modules and the ST VL53 optical rangers (an infrared time-of-flight cousin useful where sound is unsuitable) speak I2C or UART. Reading these into a microcontroller is trivial; the engineering is in the timing (blocking on a slow ultrasonic echo stalls a control loop, so you trigger and read asynchronously), the crosstalk management for arrays, and the filtering of the noisy single-shot readings into a stable distance.
Mounting
Mounting decides whether a good sensor works. An ultrasonic transducer's blind zone must sit inside the robot's own body, not out where obstacles appear. An inductive sensor's shielded/unshielded type must match its mounting (flush in metal or not). A through-beam pair must hold alignment against vibration and thermal expansion over its whole life. A diffuse sensor must not stare at a shiny wall in its background. Budget mounting geometry as real engineering, since it is where most field faults actually originate.
Selecting a near-field sensor
Choose in this order, each criterion narrowing the field before the next: target then range then environment then speed then interface.
What is the target made of, and what is its surface? Metal and exposed: inductive, cheapest and toughest. Non-metal, or a level behind a wall: capacitive. Transparent, shiny, or acoustically reflective and you need distance: ultrasonic. Any opaque object at a distance: photoelectric. This one question eliminates most of the table.
How far away, and how close? Millimetres: inductive or capacitive. Centimetres to a couple of metres: ultrasonic, diffuse photoelectric, or IR. Metres to tens of metres: through-beam or retroreflective photoelectric. Check the minimum range too: ultrasonic has a blind zone, and a target inside it is invisible.
What is the environment? Dust, oil, coolant, washdown, vibration: inductive is the survivor (IP67/IP69K), photoelectric needs clean optics, capacitive drifts with humidity. Outdoors or bright ambient light: modulated photoelectric or ultrasonic over IR reflective. Multiple identical sensors nearby: plan for ultrasonic crosstalk with time-multiplexing.
How fast is the target or the robot? Fast parts or a fast control loop need the microsecond-to-millisecond response of inductive or photoelectric. Ultrasonic is slow and gets slower in an array, so it suits slow obstacle detection, not high-speed counting.
How does it wire in? Match PNP/NPN and NO/NC to the controller, choose analog (4 to 20 mA) or IO-Link if you need a distance value and diagnostics, and confirm the voltage and current the input card expects. The industrial automation guide covers the controller side.
Common deployments
- Indoor AMR near-field skirt: an ultrasonic ring catches glass doors, table edges, and low obstacles the 2D LiDAR plane sees through or misses, feeding the safety layer alongside the LiDAR. See the mobile robots guide.
- Robot vacuum and domestic robots: downward IR reflective sensors for cliff/stair detection, forward IR or ultrasonic for wall following and obstacle avoidance, a bump switch as the last resort. See the cleaning and domestic robots guide.
- Gripper part-present: a diffuse photoelectric or IR break-beam confirms an object is between the fingers before and after a grasp, catching missed and dropped picks.
- Industrial cell interlocks: inductive switches confirm metal parts seated in fixtures and actuator end positions; through-beam guards a pick zone; capacitive senses fill level in a hopper. These wire straight into the PLC that sequences the cell.
Rule of thumb: reach for the simplest sensor whose physics matches the target. If "is the steel part in the fixture" is a yes/no in an oily cell, a $15 inductive switch beats any camera for that specific job and lasts years. Save the ranging sensors and the perception stack for questions that are genuinely about distance or about understanding a scene.
Frequently asked questions
When should I use ultrasonic instead of a laser or depth camera? When the obstacle is acoustically reflective but optically difficult: glass, clear plastic, polished metal, or a liquid surface. Sound bounces off all of these fine, while a laser passes through glass and a depth camera struggles with shiny and transparent surfaces. Ultrasonic is also the cheap way to add near-field obstacle coverage in the blind spots a scan plane leaves. It is coarse and slow, so it complements a mapping sensor rather than replacing it.
Why does my ultrasonic sensor miss objects right in front of it? The blind zone. A single-element transducer rings for a moment after transmitting and is deaf during that time, so any target closer than a few centimetres to tens of centimetres (depending on the sensor) is invisible. Mount the sensor so its blind zone falls inside your robot's own body, and add a short-range sensor (diffuse photoelectric or optical time-of-flight) for the last stretch if you need to detect very close objects.
My ultrasonic distance reading drifts through the day. Is the sensor failing? Probably temperature. The speed of sound changes about +0.6 m/s per °C, so an uncompensated ranger reads several percent long or short as the ambient temperature swings. Use a sensor with internal temperature compensation, or add a temperature reading and correct the speed of sound in firmware, or calibrate against a fixed reference target.
Why does my inductive sensor detect steel fine but not aluminium? Inductive sensors are rated against a steel target and detect non-ferrous metals at a fraction of that range: roughly 0.35 for aluminium and 0.30 for copper. The aluminium part is entering the sensor's field at a distance where a steel part would trigger but aluminium does not. Move the sensor closer, choose a longer-range unit, or use a sensor rated for non-ferrous detection.
Inductive or capacitive for detecting a plastic part? Capacitive, because inductive senses metal only. Capacitive responds to any material with a dielectric constant different from air, so it detects plastic, glass, wood, and liquids. Expect to tune its sensitivity to reject the background and the mounting, and watch for humidity and buildup drift on the sensing face.
What is the difference between through-beam, retroreflective, and diffuse photoelectric? Through-beam has a separate emitter and receiver and detects a target breaking the beam between them: longest range and most reliable, but two units to wire. Retroreflective has emitter and receiver in one housing aimed at a reflector, detecting a target that breaks the beam: one unit plus a reflector, medium range. Diffuse has one housing and no reflector, detecting light bounced off the target itself: simplest to install, shortest range, and most dependent on the target's colour and reflectivity.
How do I stop multiple ultrasonic sensors from interfering? Time-multiplex them: fire one at a time with enough delay for the previous pings and echoes to die out before the next fires, so no sensor mistakes a neighbour's pulse for its own echo. This lowers the effective update rate of the array. Some sensors also code their bursts so a receiver only accepts its own signature. Passing robots with ultrasonics can spoof each other, which is harder to prevent and argues for not relying on ultrasonic alone for safety.
PNP or NPN, and does it matter? It matters and it must match your controller. PNP (sourcing) switches the positive supply and is the modern default for most PLC inputs; NPN (sinking) switches to ground. Wiring the wrong type into an input gives a sensor that never reads or reads inverted, with no visible fault. Also choose normally-open or normally-closed deliberately, since normally-closed fails safe (a broken wire reads as target-present) for safety-relevant detection.
Can these sensors be used for safety functions? Standard proximity and ultrasonic sensors are not safety-rated on their own; they are for control and detection. Safety-rated presence sensing uses certified devices (safety light curtains, safety laser scanners) with the diagnostic coverage and fault detection required by the functional-safety standards. You can use a normally-closed proximity switch as part of a safety chain, but the certified device carries the safety function.
What is the cheapest way to give a small robot obstacle and cliff sensing? IR reflective sensors and an ultrasonic module. Downward IR reflective sensors detect the edge of a table or stair (the floor stops returning light), forward IR or an HC-SR04-class ultrasonic gives coarse obstacle distance, and a bump switch behind a compliant bumper is the last-resort collision detector. This is exactly the stack on a consumer robot vacuum, and it costs a few dollars total.