Autonomous Vehicles: What the Car Actually Senses
A self-driving car is not a big Arduino, but the logic is the same. Several sensors of different kinds watch the world, their readings are combined into one picture of the road, and a controller turns that picture into steering and speed.
What a self-driving car actually senses
Production systems use a mix, and each one covers a gap the others leave. Cameras give the richest scene but struggle in glare, fog and heavy rain, and they cannot measure distance directly, only infer it from apparent size. Lidar gives accurate distance and shape in almost any light, but a spinning unit is expensive and its returns carry no colour, so a lidar on its own cannot tell a red light from a green one.
Radar fills in the speed gap, because it measures the rate at which distance changes and therefore gives closing velocity directly, which is exactly what a camera and a lidar both have to infer from two frames. Ultrasonic sensors are short range and cheap, and are used for the last few centimetres, such as parking and kerb detection. Satellite positioning and an inertial unit give the vehicle its own position and heading, which is the frame of reference every other measurement is expressed in.
Why one sensor is never enough, and how fusion works
Fusion is not just averaging. It is a filter that predicts where objects should be, weights each sensor by how much it should be trusted right now, and corrects the prediction with the measurements. In a simple classroom version that can be a weighted average: the ultrasonic reading counts for less when the radar says something is closing fast, and the camera counts for more when the scene is well lit.
Timing is where most student projects go wrong. A camera at 30 frames per second, a lidar at 10 Hz and an ultrasonic sensor at 20 Hz are not describing the same instant, and a control loop that fuses them without timestamps will chase its own tail. Log every reading with a millisecond timestamp, then study the raw data before you write the filter.
Step by step
-
Start with the ego vehicle
Add wheel encoders or an IMU and work out how far the robot has travelled and which way it faces. Every other measurement is relative to this frame, so get it right first.
-
Add one ranging sensor
An HC-SR04 reading forward gives you a stopping distance. Log it with a timestamp and study the noise at different distances and angles before you trust any threshold.
-
Add a second, different sensor
An IR reflectance sensor or a light sensor near the ground adds a different kind of evidence. Two sensors of different types are the minimum for anything worth calling fusion.
-
Write the fusion rule
Combine the readings with explicit weights and change those weights with conditions, such as trusting the ultrasonic less when the reading is near its minimum range.
-
Close the driving loop
Turn a distance reading into a steering command with a proportional controller and watch the error fall. Then layer obstacle avoidance on top as a higher priority rule, the same structure as a traffic light state machine.
-
Log a whole drive
Record every reading and command with timestamps and then plot them. The plots show which sensor failed and when, which is exactly what a fleet diagnosis looks like.
What you'll need
| Item | Qty | Why |
|---|---|---|
| Arduino Mega 2560 | 1 | Four hardware serial ports, so the range sensors, the IMU and the logging link can run at once without blocking each other. |
| HC-SR04 ultrasonic sensor | 2 | Front and rear obstacle ranging for $4 to $8 each, which is the range a student build can afford. |
| MPU6050 IMU module | 1 | Gives heading and angular rate for dead reckoning between the range readings. |
| Light sensor with resistive divider | 1 | A crude but real brightness channel, standing in for the signal a camera would contribute. |
| L298N dual H-bridge module | 1 | Drives the drive motors with independent speed control for a differential steer chassis. |
| 9 V battery and barrel jack | 1 | A separate motor supply, so motor noise does not show up as false sensor readings. |
Practise it before you build it
Every step above has a matching circuit in the ThinkEdge Learn simulator. The simulator runs a real
Arduino sketch against a modified-nodal-analysis solver, so digitalWrite actually drives the
LED on screen and the readings change when you change the wiring — no hardware, no burnt components.
Mount an HC-SR04 ultrasonic sensor on top of a servo. Sweep the servo from 0° to 180° and back, and at each step measure the distance. Print the results to the Serial Monitor as "angle,distance" pairs. Open the Serial Plotter in the Arduino IDE to see a live radar-like graph of the room. With Processing on your computer, you can build a full visual radar.
A parking sensor beeps faster as you get closer to an obstacle, and stays silent past a safe distance. We use 100 cm as the cutoff: anything closer triggers a beep (faster the nearer you are), anything farther is silent. The trick is to change the `delay()` between beeps based on distance: very close = short delay, close = medium delay, safe = no beep. The green LED above the buzzer lights up at safe distances so the driver has a visual cue that the car can keep moving — sound alone is easy to miss in a noisy parking garage. This is the same "map input range to output range" pattern you used for the potentiometer projects, but applied to time.
An HC-SR04 ultrasonic sensor measures distance by sending out a high-frequency sound pulse (40 kHz, above human hearing) and timing how long it takes to echo back. Sound travels ~343 m/s in air, so distance = (time × speed) / 2 (divide by 2 because the sound travels there AND back). The sensor does the timing for you — you just trigger it and read the echo pulse width.
The Mega has 4 hardware serial ports (Serial, Serial1, Serial2, Serial3). That means you can talk to 4 different devices at the SAME time — like a GPS, a Bluetooth module, an XBee radio, and the USB. Use 3 of those ports to read 3 different sensors in parallel and stream their data to the Serial Monitor as a CSV row every second. This is the foundation of every real Arduino data logger.
A real traffic light runs a state machine: GREEN (cars go) → YELLOW (slow down) → RED (cars stop) → PEDESTRIAN WALK (cross the road) → RED → GREEN. The Mega has enough pins to build a full intersection: 3 LEDs for cars in one direction, 3 LEDs for cars in the other, 2 LEDs for the pedestrian signal, and a button to request to cross. Use millis() for non-blocking timing so the button check is responsive.
Common questions
What sensors do autonomous vehicles use?
Usually a camera for scene content, lidar for accurate shape and distance, radar for closing speed in bad weather, ultrasonics for the last few centimetres, and satellite positioning plus an inertial unit for the vehicle's own position. The reason for so many is that each one fails in a different condition, so combining them covers more of the envelope than any of them alone.
How much does it cost to build a self-driving car for a school project?
A scaled down car costs $90 to $220: $25 to $60 for a chassis with two drive motors and casters, $6 to $12 for the driver, $8 to $16 for the ultrasonic sensors, $3 to $6 for the IMU, and $15 to $30 for the board and battery. Full size autonomy hardware is out of reach by a very wide margin, and no classroom build is road legal.
Can an Arduino run a self-driving car?
It can run the control logic for a small scale vehicle: ranging, thresholding, obstacle avoidance and differential steering all fit comfortably. It cannot run a neural network for perception, a lidar point cloud filter or a localisation system, because those need far more memory and compute. Use the Arduino for the real time layer and hand the slow, heavy perception work to a Raspberry Pi or a computer over serial.
Related guides
Try the full simulator with your class
103 guided circuit projects, 21 lessons and an in-browser Arduino simulator. The first 15 projects are free, no account needed. NCERT Science mapping on 47 projects, with Arabic and English copy in the regional builds.