Robot Sensors Explained: Ultrasonic, IR, Encoders and IMUs
Sensors are how a robot stops being a remote-controlled toy and starts making decisions. This guide maps the sensors you will actually meet in hobby and school robotics: what each one measures, what it costs in India, its wiring gotchas, and which of our builds uses it.
The cheat sheet
| Sensor | Measures | Interface | Indicative price |
|---|---|---|---|
| HC-SR04 ultrasonic | Distance 2 cm–4 m | 2 digital pins | ₹60–120 |
| TCRT5000 IR module | Surface reflectance (line/edge) | 1 digital or analog pin | ₹40–80 |
| 5-ch IR array | Line position | 5 analog pins | ₹150–300 |
| LM393 slot encoder + disc | Wheel rotation | 1 digital pin (interrupt) | ₹40–90 |
| MPU-6050 IMU | Rotation rate + tilt | I²C | ₹150–300 |
| IR receiver (VS1838) | Remote-control commands | 1 digital pin | ₹30–60 |
| HC-05 / HC-06 Bluetooth | Phone link (not strictly a sensor) | Serial | ₹250–400 |
Prices shown are indicative online street prices in India as of mid-2026. They vary by seller and stock — treat them as a budgeting guide, not a quote.
Ultrasonic (HC-SR04)
Sonar for robots: emits a 40 kHz chirp and times the echo. Great for “is something in front of me and how far” at toy-car speeds. Weaknesses: a wide ~15° cone (cannot tell where in the cone the object is), poor returns from soft or angled surfaces, and occasional ghost readings — take the median of three pings. Used in our obstacle avoider.
IR reflectance (line sensors)
An IR LED and phototransistor pair pointed at the floor. Black tape absorbs IR, white reflects it; a comparator gives you a clean digital edge (or read the analog pin for a gradient). Range is millimetres, so mounting height matters more than anything else. Ambient sunlight is full of IR — calibrate where you run. Two of these power the line follower; arrays of 5–8 power PID racers. The same module pointed forward makes a short-range obstacle “whisker”, and pointed down at a table edge makes a cliff detector.
Wheel encoders
A slotted disc on the wheel or motor shaft spins through an optical slot sensor, producing one pulse per slot. Count pulses (use attachInterrupt) and you know how far each wheel actually turned — which motors alone never tell you, because no two DC motors run at exactly the same speed. Encoders turn “spin for 420 ms and hope it’s 90°” into “turn until the wheels have rolled 90° worth”. They are the gateway to odometry and straight-line driving, and the standard TT-motor discs cost almost nothing.
IMU: gyro + accelerometer
The MPU-6050 packs a 3-axis gyroscope (rotation rate) and 3-axis accelerometer (tilt/acceleration) behind an I²C interface (pins A4/A5 on an Uno). Integrate the gyro and you get heading for precise turns; read the accelerometer and you get tilt for ramps — or build a self-balancing robot, the definitive intermediate project. Gotcha: it is a 3.3 V-core module; the common breakout boards include a regulator so 5 V VCC is fine, but never feed 5 V straight into a bare chip.
Honourable mentions
- Bumper microswitches — the humble last line of defence; trivially reliable where sonar fails.
- IR receiver (VS1838) — drive your robot with a TV remote for ₹40.
- Bluetooth HC-05 — a serial pipe to a phone app; technically a link, practically how most students add “app control”.
- VL53L0X laser ToF — a ₹250–450 laser rangefinder: narrow beam and millimetre precision where sonar’s cone is too blunt.
- Colour (TCS34725) and light (LDR) — event tasks love colour-coded zones.
Choosing sensors per project
| You want the robot to… | Use | Guide |
|---|---|---|
| Follow a taped track | 2× IR modules, later a 5-ch array | Line follower |
| Roam without collisions | HC-SR04 on a servo + bumper switches | Obstacle avoider |
| Drive dead straight / turn exact angles | Wheel encoders, or IMU | Sensors above |
| Balance on two wheels | MPU-6050 + encoders | Advanced project |
| Stay on the table | IR module pointed down at the edge | Edge/cliff variant |
Universal wiring gotchas
- Common ground, always. Every module’s GND ties to the Arduino’s GND.
- Know your voltages. Uno logic is 5 V; many modern sensors are 3.3 V. Check before wiring, use breakouts with regulators/level shifters.
- Don’t starve the 5 V rail. Sensors are light loads, but servos and Bluetooth modules add up; budget your regulator.
- Noise is real. Motors spray electrical noise — keep sensor wires short and away from motor leads, and add a 100 nF capacitor across misbehaving modules’ supply pins.