Cleaning Robots: Bumpers, Cliff Sensors and the Brush
A robot vacuum has no map and no idea where the walls are. It bumps into things, backs off, turns by a random amount and repeats, and the trick is that a carefully chosen set of cheap sensors makes that random walk cover the floor properly.
How a robot vacuum navigates without a map
There is no map. A robot vacuum drives forward, and when a bumper switch or a wall sensor reports contact it reverses, turns by a random angle of roughly 30 to 150 degrees, and drives on. Given enough time, a random walk with a bias towards the walls covers a room well enough, and that bias is what makes it look deliberate. Newer machines add a camera or a laser scanner and build a real floor plan, but the random walk version is the logic a student can write in twenty lines.
The second trick is the schedule. A vacuum that cleaned for 20 minutes and then stopped would leave the far corner of a large room untouched, so real machines clean in bursts, pause briefly and change direction again, which spreads the coverage over time. It is a strange idea, but it measurably improves the result.
Cliff sensors matter more than the brush motor
The brush motor is the part everybody wants to build, and it is the least important. A small brush motor draws a few hundred milliamps and does most of the cleaning, while the navigation decides whether the robot ever reaches the dirt at all. The infrared cliff sensors under the front bumper matter more, because they stop the machine driving off a step onto a stair or into a sock.
Cliff sensing works by measuring how much infrared light comes back. A sensor fires a beam downward and looks for the return. On a floor the reflection is strong and consistent; over an edge there is nothing to reflect from, so the return collapses. The failure mode worth knowing is a black or glossy floor tile, which absorbs the beam and looks like a cliff, so machines with real cliff sensors look at the pattern across several sensors to tell the difference.
Step by step
-
Build a driving base
Two geared motors with an H-bridge and a caster wheel. Get it driving straight and turning on the spot before adding any sensors.
-
Add a front bumper
A small microswitch on a sprung bracket triggers on contact. This is how the robot knows it hit something, and it is more reliable than trying to detect walls with ultrasonics.
-
Add a wall sensor
Mount an ultrasonic sensor facing forward and read the distance. Compare it with the bumper output so you can see which one fires first as the robot nears a wall.
-
Write the bounce and turn
On contact, reverse for a fixed distance and then turn by a randomised angle. Log every turn angle so you can see whether the coverage is actually spreading.
-
Add cliff detection
Use an IR reflectance module under the front edge to detect a drop and stop the motors. Test it over a dark tile as well as over a step, because the two look the same to a naive sensor.
-
Add the brush and the dock
Drive a small brush motor with a MOSFET and add charging contacts so the robot returns to a dock when the battery drops. Then log a full run and look for the floor it never visited.
What you'll need
| Item | Qty | Why |
|---|---|---|
| Arduino Uno R3 | 1 | Runs the motor control and the sensor logic for a machine that has to keep working between charges. |
| 2WD chassis kit with geared motors and casters | 1 | The standard base, with rubber wheels that grip a smooth floor. |
| L298N dual H-bridge module | 1 | Two channels for the drive motors, with a spare channel for the brush. |
| HC-SR04 ultrasonic sensor | 1 | Long range wall detection, so the robot can slow down before it actually bumps. |
| IR reflectance sensor modules | 2 | Cliff detection under the front edge, plus a line sensor if you want a docking guide. |
| TP4056 LiPo charging module | 1 | Charges the pack safely. A plain wire and USB setup is the most common way these projects start a fire. |
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.
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.
A real car reversing buzzer does NOT use a smooth `map()`. It beeps in zones: 1 slow beep when far, 1 medium beep closer, 2 beeps when close, 2 fast high-pitched beeps when very close. We can build the same with the Nano + HC-SR04 + a buzzer. The trick is a chain of `if (cm > X)` checks that picks one of four zones — each zone has its own number of beeps, frequency, and gap.
The HC-SR04 ultrasonic sensor measures distance by sending out a 40 kHz ping and timing how long the echo takes to come back. We trigger the ping with a digitalWrite, time the echo with pulseIn(), and convert the time to centimeters using the speed of sound. This is the same sensor used in car parking sensors and robot vacuums.
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.
Common questions
How much does a robot vacuum cost?
Consumer robot vacuums run from about $150 for a basic random navigation model to $500 or more for one with a lidar scanner and a self emptying dock. A DIY version with an Arduino and parts is $50 to $120: $20 to $40 for the chassis and motors, $6 to $12 for the driver, $4 to $8 for the ultrasonic sensor, $3 to $6 for the cliff sensors, and $10 to $20 for the battery and charging module.
Why does my robot keep backing away from the wall?
Almost always the bumper switch or the ultrasonic threshold is too sensitive. If you are using ultrasonics for wall detection, note that the beam hits a corner and returns a much shorter distance than it should, which reads as a very close wall. Angle the sensor away from the wall or lower the trigger threshold.
Do robot vacuums really clean in a random pattern?
Yes, on the entry level models. A random walk with a wall bias and a duty cycle does cover a room over a full cycle, which is why they sometimes wander for a while and then appear to pick up. The more expensive models replace this with a lidar scan and a planned path, which is faster and far more repeatable.
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.