30% off your first 3 months

Get the deal

Choosing sensors for a first robot

by DuckyHelperNov 12, 20265 min read
Robotics

TL;DR:

  • Start from what the robot needs to know, then pick the simplest sensor that answers it.

  • Check range against stopping distance and update rate against speed. A sensor that is too slow or too short-ranged is useless however good it looks.

  • Every added sensor costs wiring, power, code and debugging time.

A parts catalogue lists dozens of sensors, and the temptation is to buy several and see what happens. A better start is to ask what the robot needs to know. A robot that must avoid walls needs to know whether something is in front of it, and how far. That is a much smaller shopping list.

What you need to know

Write the question in plain words, then the number you need. For an obstacle-avoiding robot: how far is the nearest thing ahead, and has it hit something? Each sensor answers a different version of the question.

Sensor

Tells you

Typical limits

Bump switch

Contact happened

No warning before contact, very simple and cheap

Infrared proximity

Something is close, sometimes roughly how close

Short range; readings depend on surface colour and sunlight

Ultrasonic

Distance from the time a sound pulse takes to return

Wide beam; soft or angled surfaces may reflect poorly; hobby modules often list a range from a few centimeters to a few meters

Laser time-of-flight

Distance from light travel time

Narrow beam, good range indoors; check the eye-safety class

Spinning LiDAR

A 2D map of distances all around

More cost, power, wiring and software

General characteristics. Always read the datasheet for your exact part.

Worked example: sensors for an obstacle-avoiding robot

The robot is a small two-wheeled platform that drives at 0.3 m/s along a room and turns away from obstacles. Decide what it needs in four steps.

  1. How far must it see? Say it brakes at 1.0 m/s² once it decides to stop. The stopping distance is v² / (2a) = 0.09 / 2.0 = 0.045 m, about 4.5 cm, plus the distance covered during its reaction. If the control loop reads the sensor every 60 ms, the robot moves 0.3 × 0.06 = 0.018 m, 1.8 cm, between readings. Total is under 7 cm, so it must detect an obstacle at 20 cm to have a comfortable margin of three times.

  2. Does the sensor reach that far, and not too close? A hobby ultrasonic module that works from a few centimeters to a few meters covers 20 cm easily. A short-range infrared sensor also fits, but is more sensitive to surface colour.

  3. Is the update rate enough? An ultrasonic module needs time for the sound to go out and return. A target 1.0 m away takes 2 × 1.0 / 343 ≈ 5.8 ms for the echo, using a speed of sound of about 343 m/s at room temperature. Waiting 60 ms between pings lets echoes die away, giving roughly 16 readings per second. That is plenty at 0.3 m/s.

  4. What if it misses? A soft curtain or a table leg can fool an ultrasonic sensor. Add two bump switches at the front as a last-resort backup.

Check the echo-time formula: distance d = v × t / 2, because the sound goes out and back. For t = 5.83 ms and v = 343 m/s, d = 343 × 0.00583 / 2 ≈ 1.0 m. In the other direction, an obstacle at 20 cm gives t = 2 × 0.2 / 343 ≈ 1.17 ms. The result is one ultrasonic sensor facing forward plus two bump switches: three parts that fit one microcontroller with few pins.

Range, field of view and update rate

Three numbers on a datasheet matter most. Range: the nearest and farthest distance it measures, and many sensors report nothing useful at very short distances. Field of view: a wide ultrasonic cone sees a table edge off to the side; a narrow laser beam can miss a thin chair leg. Update rate: how many readings each second, which decides how far the robot travels between looks.

The cost of complexity

A second distance sensor looks like a small addition. In practice it needs a pin or a bus address, wiring, power, code to read it, code to combine it with the first, and testing for the case where the two disagree. A LiDAR adds a spinning part, a bigger power draw and a software pipeline. For a first robot, each extra sensor should answer a question the robot cannot do without.

Laser and light sensors: Laser time-of-flight modules sold for hobby use are normally in a low-power class marked on the datasheet, but you should still not stare into an emitter or open a LiDAR unit. Use the part as intended, keep spinning heads clear of fingers and cables, and check the voltage rating before wiring so you do not damage the sensor or the board.

Where it goes wrong

  • Mounting. A sensor tilted down sees the floor as an obstacle. Tilted up, it misses low objects.

  • Cross-talk. Two ultrasonic sensors pinging at once hear each other. Fire them one after the other.

  • Surfaces. Soft cloth absorbs sound. Black or shiny surfaces confuse infrared. Glass is hard for most optical sensors.

  • Sunlight. Many infrared sensors weaken in bright light.

  • Voltage levels. A 5 V echo output into a 3.3 V pin needs a divider or level shifter.

How real robots use it

Real robots mix sensor types so one covers another's weaknesses, and add up what each costs in power and processing. Touch in particular is a hard sense to build, and how robotic hands sense touch looks at it closely. Once you have chosen, the connections you make are the subject of soldering basics for robot builders, and for the electronics background see electronics basics before your first robot.

Try it yourself

Before buying anything, write your robot's job as a sentence, list the three things it must know to do the job, and put a number next to each (a distance, a speed, a rate). Then read three datasheets and cross off any sensor whose range or update rate misses your numbers. You will usually be left with one or two honest choices.

Frequently asked questions

Should my first robot have a camera?

Only if the job needs it. A camera needs a computer and more software. Distance sensors and a few switches are enough to learn from.

Are expensive sensors more accurate?

Often, but accuracy is only one factor. Match range, field of view, update rate and interface to your robot first.

Get started

DuckyHelper can
do more

It sees your screen and works in any app you use. Try it for 10 minutes, no card.

Get it for Mac, Windows or Linux

Share

Questions and jobs

Do anything

Ask it a question or hand it a job, in any app.

Doing jobs for you is in early access on Mac. Asking works on Mac, Windows and Linux.