Sensor Picker by Use Case
Range rules sensors out before accuracy does — and an ultrasonic sensor drifts 24 times its own spec across an ordinary temperature swing.
If you're using an ultrasonic sensor
Ultrasonic error against temperature
What the beam actually covers
Range gates the choice before accuracy does
People compare accuracy first. But of six common temperature sensors, only two can measure a 200 °C oven at all — the other four are destroyed by it. A ±0.5 °C part that melts is worse than a ±2.2 °C one that survives, so the first question is what the sensor can reach and survive, not how tight its tolerance is.
An ultrasonic sensor's temperature error swamps its accuracy spec. The speed of sound is 331.3 + 0.606·T m/s, so a reading calibrated at 20 °C is out by 3.53% at 0 °C or 40 °C. At 2 m that's 71 mm — roughly 24× the ±3 mm the HC-SR04 datasheet claims. Anything outdoors needs a thermometer to correct it, and almost nothing has one.
And it reports the nearest object in a cone, not what's ahead. A 15° beam is 2r·tan(7.5°) across — 26 cm at a metre, 105 cm at four. That's why ultrasonic sensors "see" doorframes and table edges nowhere near the axis. It's physics, not a fault, and it's the reason a narrow-beam optical sensor behaves so differently in the same room.
The Sharp IR rangers are non-monotonic below their minimum range, which is the trap that matters most. The output rises to a peak near 7 cm then falls, so roughly 3 cm and 34 cm give the same voltage. A too-close object reads as a far one — exactly the failure that makes an obstacle detector drive into something — and no software separates them. If anything can get closer than the minimum range, the sensor cannot tell you.
- A PIR detects change, not presence. Someone who stops moving stops being detected within seconds, and the retrigger hold hides that gap rather than filling it. If the question is "is anyone in the room", mmWave radar answers it — it resolves the motion of breathing — and a PIR doesn't.
- Sample rate is bounded by the round trip. A 4 m ultrasonic sensor can't exceed 43 Hz, about half that once echoes decay — so a robot at 2 m/s covers 9 cm between readings. Filtering can't recover ground that was never sampled.
- Match the failure mode to the environment, not the spec to the requirement. Optical fails in sunlight, ultrasonic on soft and angled surfaces, radar through walls it shouldn't see through. Each is physics no part choice within the family avoids.
- Glass is invisible to time-of-flight sensors and reflective to ultrasonic ones. Which of those is a problem depends entirely on whether you wanted to detect the glass or what's behind it.
How to use
- Filter by range first — it eliminates more options than accuracy does.
- Correct ultrasonic readings for temperature if the sensor is outdoors.
- Check whether anything can get closer than the minimum range.
- Match the failure mode to the environment, not the spec to the requirement.
Frequently asked questions
How accurate is an HC-SR04 ultrasonic sensor really?
Far less accurate than its claimed three millimetres, once temperature is accounted for. The speed of sound is 331.3 plus 0.606 times the temperature in Celsius, so a sensor calibrated at twenty degrees reads 3.53 per cent out at zero or forty. At two metres that is seventy-one millimetres, roughly twenty-four times the datasheet figure, and nothing in the sensor corrects for it.
Why does my ultrasonic sensor detect things that are not in front of it?
Because it reports the nearest object anywhere in a cone rather than what is straight ahead. A fifteen-degree beam is twice the range times the tangent of seven and a half degrees across — twenty-six centimetres at a metre and over a metre at four. Doorframes, table edges and floor returns all fall inside that circle, and it is a property of the physics rather than a fault.
How fast can an ultrasonic sensor sample?
The round trip sets a hard ceiling: sound covers two metres and back in about twelve milliseconds, so a two-metre sensor caps near eighty-six hertz and a four-metre one near forty-three. Halve that in practice to let echoes decay. A robot moving at two metres a second with a four-metre sensor therefore covers about nine centimetres between readings, and no filtering recovers ground that was never sampled.
Why do Sharp infrared distance sensors give wrong readings up close?
Because the response curve is not monotonic below the minimum range. The output voltage rises to a peak around seven centimetres and then falls again, so roughly three centimetres and thirty-four centimetres produce the same voltage. A too-close object reads as a far one, and no amount of software can separate the two — the sensor genuinely cannot tell you it is out of range.
Which distance sensor should I use for obstacle avoidance?
Not a Sharp infrared ranger on its own, because of the non-monotonic near field: an obstacle closer than the minimum range reads as far away, which is the exact failure that makes a robot drive into things. A time-of-flight sensor reports an explicit out-of-range condition instead. If cost rules that out, add a bumper switch to cover the region the ranger cannot see.
Does a PIR sensor detect presence or motion?
Motion, or more precisely change. The pyroelectric element responds to a change in incident infrared, so someone who stops moving stops being detected within seconds. The retrigger hold hides that gap rather than filling it — a person still for longer than the hold reads as absent however long you set it. Occupancy from a PIR really means recent movement.
What can detect that someone is in a room but not moving?
Millimetre-wave radar, which resolves motion small enough to pick up breathing and so reports genuine presence rather than movement. That is the specific problem a PIR cannot solve at any price. The trade-off is that radar sees through thin walls and doors, so it detects the next room too, and a rotating fan or swaying curtain reads as continuous presence.
Should I pick a sensor by accuracy or by range?
By range, and it is not close. Of six common temperature sensors only two can measure a two-hundred-degree oven at all — the other four are physically destroyed by it. A half-degree part that melts is worse than a two-degree part that survives. Accuracy is the question everyone asks first and it is the second question, not the first.
What temperature sensor works above 150 degrees?
A thermocouple or an RTD, and very little else in the hobby range. A K-type thermocouple covers minus two hundred to thirteen hundred and fifty degrees at about two degrees of accuracy and survives being put in a flame. A PT100 RTD is far more accurate at 0.15 degrees but stops around eight hundred and fifty. Semiconductor sensors like the DS18B20 and BME280 top out near a hundred.
Why does my BME280 read warmer than the room?
Self-heating, usually from its own bus activity and from whatever else is on the board. The temperature element exists mainly to compensate the humidity and pressure readings, so it sits close to other components rather than out in the air. Mounted on a board near a regulator it reports the board temperature, and reading it less often measurably reduces the bias.
Can a time-of-flight sensor see glass?
No, and this catches people out in both directions. Glass is effectively invisible to a time-of-flight sensor, which reads whatever is behind it, while an ultrasonic sensor reflects off glass and reads the pane. Which behaviour is a problem depends entirely on whether you wanted to detect the glass or what is beyond it — neither is more correct than the other.
Why does my optical distance sensor stop working outdoors?
Sunlight swamps the receiver. Infrared from the sun is far stronger than the sensor own emitter, so the return pulse disappears into the background and the effective range collapses — sometimes to nothing. Ultrasonic sensors are unaffected by light and fail on different things instead: soft surfaces that absorb the pulse, and angled surfaces that deflect it away.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.