Projects / Mini robot vacuum with bump sensors

Mini robot vacuum with bump sensors

Intermediate5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Build a round base

    Free to turn.

  2. NANO

    Fit motors and a caster

    Wheels in line.

  3. NANO

    Make the bumper

    Two switches behind it.

  4. NANO

    Test the motors

    Each way.

  5. NANOIRLZ44

    Add the fan and MOSFET

    Switch it from D10.

  6. NANO

    Upload and test on a table mat

    Away from edges.

  7. NANO

    Run it in a clear room

    Watch the first run.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Left bump switchNano D2 and GNDHits on the left (internal pull-up)
Right bump switchNano D12 and GNDHits on the right (internal pull-up)
TB6612 AIN1, AIN2, PWMANano D4, D5, D3Left motor
TB6612 BIN1, BIN2, PWMBNano D7, D8, D6Right motor
TB6612 STBYNano D9High to enable
TB6612 VM and GNDLiPo plus and minusMotor power
Fan plusMini-360 OUT (set to 5.0 V)Fan power
Fan minusIRLZ44N drainSwitched by the MOSFET
IRLZ44N gate and sourceNano D10 and GND, with 10 k from gate to GNDFan switch
Mini-360 OUT and GNDNano 5V pin and GNDLogic 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.

CheckExpected
Drive into a wallReverses and turns
Left bumpTurns right
After 30 minutesStops and the fan stops
FanSpins 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 →

Ask Lark AI

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.