Mini robot vacuum with bump sensors
Build it step by step
0 of 7 doneBuild a round base
Free to turn.
Fit motors and a caster
Wheels in line.
Make the bumper
Two switches behind it.
Test the motors
Each way.
Add the fan and MOSFET
Switch it from D10.
Upload and test on a table mat
Away from edges.
Run it in a clear room
Watch the first run.
How do you build a mini robot vacuum with bump sensors?
A round robot with a small suction fan and two bump switches wanders a room, turning randomly when it hits something. You need Arduino Nano, TB6612FNG Motor Driver, N20 micro metal gear motor × 2, Limit switch (micro switch with lever) × 2, 5 V DC fan 40 mm, MOSFET IRLZ44N, Resistor 10 kΩ, Li-Po 2S 7.4 V 2200 mAh 25C (RC) and Mini-360 buck converter. It takes 7 steps and about 300 minutes.
- Level
- Intermediate
- Time
- About 300 min
- Parts
- 9
Parts list
- Development BoardsBuyArduino Nano × 1
- Motor DriversBuy
- Motors & ActuatorsBuy
- SwitchesBuy
- Motors & ActuatorsBuy5 V DC fan 40 mm × 1
- SemiconductorsBuyMOSFET IRLZ44N × 1
- PassivesBuyResistor 10 kΩ × 1
- BatteriesBuy
- PowerBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Left bump switch | Nano D2 and GND | Hits on the left (internal pull-up) |
| Right bump switch | Nano D12 and GND | Hits on the right (internal pull-up) |
| TB6612 AIN1, AIN2, PWMA | Nano D4, D5, D3 | Left motor |
| TB6612 BIN1, BIN2, PWMB | Nano D7, D8, D6 | Right motor |
| TB6612 STBY | Nano D9 | High to enable |
| TB6612 VM and GND | LiPo plus and minus | Motor power |
| Fan plus | Mini-360 OUT (set to 5.0 V) | Fan power |
| Fan minus | IRLZ44N drain | Switched by the MOSFET |
| IRLZ44N gate and source | Nano D10 and GND, with 10 k from gate to GND | Fan switch |
| Mini-360 OUT and GND | Nano 5V pin and GND | Logic power |
Code
This is a small model of the bump-and-run robot vacuums, which do not map the room; they simply drive until they touch something, back up, turn a random amount and go again, and over time that covers most of the floor. A round body is important because it can rotate without catching a corner. The two micro switches sit behind a light front bumper that can move a few millimetres, and which one closes tells the robot which way to turn. The fan only moves air and can pick up dust and crumbs; it is not a real vacuum. The sketch stops after thirty minutes because there is no battery monitor: with a LiPo you must not run the pack flat, so also check its voltage and stop at about 3.3 V per cell, charge it on a balance charger, and never charge it unattended. Use it only on a floor with no stairs or drops, since it has no cliff sensor, and stay in the room while it runs. Keep cables and small things off the floor. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Bump-and-run vacuum model: drives forward, reverses and turns a random angle on a bump, stops after 30 minutes.
// Board: Arduino Nano. Left bump on D2, right bump on D12, both LOW when pressed.
const uint8_t AIN1 = 4, AIN2 = 5, PWMA = 3, BIN1 = 7, BIN2 = 8, PWMB = 6, STBY = 9, FAN = 10, BUMP_L = 2, BUMP_R = 12;
const int SPEED = 170;
const unsigned long RUN_MS = 30UL * 60UL * 1000UL;
void motor(int l, int r) {
digitalWrite(AIN1, l >= 0); digitalWrite(AIN2, l < 0); analogWrite(PWMA, constrain(abs(l), 0, 255));
digitalWrite(BIN1, r >= 0); digitalWrite(BIN2, r < 0); analogWrite(PWMB, constrain(abs(r), 0, 255));
}
void setup() {
pinMode(AIN1, OUTPUT); pinMode(AIN2, OUTPUT); pinMode(PWMA, OUTPUT);
pinMode(BIN1, OUTPUT); pinMode(BIN2, OUTPUT); pinMode(PWMB, OUTPUT);
pinMode(STBY, OUTPUT); digitalWrite(STBY, HIGH);
pinMode(FAN, OUTPUT); pinMode(BUMP_L, INPUT_PULLUP); pinMode(BUMP_R, INPUT_PULLUP);
randomSeed(analogRead(A0));
digitalWrite(FAN, HIGH);
delay(3000); // time to put it on the floor
}
void loop() {
if (millis() > RUN_MS) { motor(0, 0); digitalWrite(FAN, LOW); while (true) {} }
bool hitL = digitalRead(BUMP_L) == LOW, hitR = digitalRead(BUMP_R) == LOW;
if (hitL || hitR) {
motor(-SPEED, -SPEED); delay(400);
int turnMs = random(300, 900);
if (hitL && !hitR) motor(SPEED, -SPEED); // hit on the left, turn right
else if (hitR && !hitL) motor(-SPEED, SPEED);
else motor(random(2) ? SPEED : -SPEED, random(2) ? SPEED : -SPEED);
delay(turnMs);
} else {
motor(SPEED, SPEED);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Drive into a wall | Reverses and turns |
| Left bump | Turns right |
| After 30 minutes | Stops and the fan stops |
| Fan | Spins while running |
If it does not work
Does not turn away
Swap the left and right switch wires.
Resets when the fan starts
Power the fan from the mini-360, not the Nano.
Keeps hitting the same corner
Increase the random turn range.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the mini robot vacuum with bump sensors?
Arduino Nano, TB6612FNG Motor Driver, N20 micro metal gear motor × 2, Limit switch (micro switch with lever) × 2, 5 V DC fan 40 mm, MOSFET IRLZ44N, Resistor 10 kΩ, Li-Po 2S 7.4 V 2200 mAh 25C (RC) and Mini-360 buck converter.
How long does the mini robot vacuum with bump sensors take to build?
About 300 minutes for a intermediate maker, in 7 steps.
How do I know the mini robot vacuum with bump sensors works?
Drive into a wall: Reverses and turns. Left bump: Turns right. After 30 minutes: Stops and the fan stops.
Does not turn away: what should I check?
Swap the left and right switch wires.
Resets when the fan starts: what should I check?
Power the fan from the mini-360, not the Nano.
Keeps hitting the same corner: what should I check?
Increase the random turn range.
