Build Your Own Smart Floor Cleaning Robot!
A fun robotics project for curious kids — ages 10 and up!
Learn circuits, coding & engineering.
🛒 What You Need (Parts List)
🔌 Circuit Wiring Guide
| Arduino Pin | L298N Pin | Purpose |
|---|---|---|
| D3 (PWM) | ENA | Left motor speed |
| D4 | IN1 | Left motor direction A |
| D5 | IN2 | Left motor direction B |
| D6 (PWM) | ENB | Right motor speed |
| D7 | IN3 | Right motor direction A |
| D8 | IN4 | Right motor direction B |
| GND | GND | Common ground |
| 9V Battery | 12V IN | Motor power supply |
| Arduino Pin | Sensor Pin | Sensor |
|---|---|---|
| D9 | TRIG | Front sensor |
| D10 | ECHO | Front sensor |
| D11 | TRIG | Right side sensor |
| D12 | ECHO | Right side sensor |
| 5V | VCC | Both sensors |
| GND | GND | Both sensors |
🗺️ Circuit Diagram
🔨 Step-by-Step Build Instructions
-
🗂️ Prepare Your Chassis (Body)
Cut a 20 cm × 15 cm piece of cardboard or acrylic sheet. This is your robot's body! Make two holes on each side for the motor shafts. Draw a grid on top so you know where to place each part.
💡 Ask a grown-up to help with cutting. Use a ruler for straight edges! -
⚙️ Mount the DC Motors
Attach both DC motors to the sides of the chassis using hot glue or zip ties. The motor shafts should stick out through the holes. Push the wheels onto the motor shafts firmly. Add a small caster wheel at the front for balance!
💡 Make sure both motors face the same direction so the robot goes straight! -
🎛️ Install the Motor Driver (L298N)
Glue the L298N motor driver board in the center of the chassis. Connect the left motor wires to OUT1 and OUT2 terminals. Connect the right motor wires to OUT3 and OUT4 terminals. Use a screwdriver to tighten the terminal screws.
💡 Red wire = positive (+), Black wire = negative (−). Don't mix them up! -
📡 Attach the Ultrasonic Sensors
Mount the first HC-SR04 sensor at the front of the robot pointing forward. Mount the second sensor on the right side pointing sideways. Use hot glue or a small bracket. These sensors detect objects like a bat using sound waves!
💡 The two circles on the sensor are like little ears — one sends sound, one receives it! -
🧠 Connect the Arduino
Place the Arduino UNO on the chassis. Using jumper wires, connect it to the motor driver (pins D3–D8) and both sensors (pins D9–D12) following the wiring table above. Use the breadboard for clean connections. Double-check every wire!
💡 Use different colored wires: red for power, black for ground, blue/green for signals! -
🧹 Add the Cleaning Brush
Tape or glue a small brush, sponge, or microfiber cloth to the front-bottom of the robot. This is what cleans the floor! Make sure it touches the ground gently but doesn't stop the wheels from spinning.
💡 Try a bottle brush cut in half for a really good cleaning effect! -
💻 Upload the Code
Connect your Arduino to a computer using a USB cable. Open the Arduino IDE app. Copy and paste the code below. Click the Upload button (the right arrow ➡️). Wait for "Done uploading!" to appear at the bottom.
💡 Download Arduino IDE free from arduino.cc — it's the app you use to write robot code! -
🔋 Power Up & Test!
Disconnect the USB cable. Connect the 9V battery to the L298N power terminals. Turn it on and place the robot on the floor. Watch it go! It should move forward and turn when it detects an obstacle. Do a happy dance! 🎉
💡 Test on a smooth floor first. Carpet might slow the wheels down!
💻 The Arduino Code
// ============================================ // Smart Floor Cleaning Robot for Kids // Works with: Arduino UNO + L298N + HC-SR04 // ============================================ // --- Motor Driver Pins --- const int ENA = 3; // Left motor speed (PWM) const int IN1 = 4; // Left motor direction A const int IN2 = 5; // Left motor direction B const int ENB = 6; // Right motor speed (PWM) const int IN3 = 7; // Right motor direction A const int IN4 = 8; // Right motor direction B // --- Ultrasonic Sensor Pins --- const int FRONT_TRIG = 9; const int FRONT_ECHO = 10; const int RIGHT_TRIG = 11; const int RIGHT_ECHO = 12; // --- Robot Settings --- const int SPEED = 180; // Motor speed (0 to 255) const int SAFE_DIST = 20; // cm — turn if closer than this // ============================================ // SETUP — runs ONCE when robot turns on // ============================================ void setup() { // Motor driver pins → OUTPUT pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); // Sensor pins pinMode(FRONT_TRIG, OUTPUT); pinMode(FRONT_ECHO, INPUT); pinMode(RIGHT_TRIG, OUTPUT); pinMode(RIGHT_ECHO, INPUT); Serial.begin(9600); Serial.println("Robot is awake! Let's clean! 🤖"); } // ============================================ // getDistance() — sends a sound pulse and // measures how far away the object is // ============================================ long getDistance(int trigPin, int echoPin) { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); // Send sound pulse delayMicroseconds(10); digitalWrite(trigPin, LOW); long duration = pulseIn(echoPin, HIGH); // Measure echo time return duration * 0.034 / 2; // Convert to cm } // ============================================ // Movement functions // ============================================ void moveForward() { analogWrite(ENA, SPEED); analogWrite(ENB, SPEED); digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); } void turnLeft() { analogWrite(ENA, SPEED); analogWrite(ENB, SPEED); digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); // Left backward digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); // Right forward delay(500); // Turn for half a second } void stopMotors() { digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); } // ============================================ // LOOP — runs FOREVER while robot is on // ============================================ void loop() { // Read distances from both sensors long frontDist = getDistance(FRONT_TRIG, FRONT_ECHO); long rightDist = getDistance(RIGHT_TRIG, RIGHT_ECHO); // Print to Serial Monitor (for debugging) Serial.print("Front: "); Serial.print(frontDist); Serial.print(" cm | Right: "); Serial.print(rightDist); Serial.println(" cm"); // Decision time! if (frontDist < SAFE_DIST) { stopMotors(); // Something in front — STOP! delay(200); turnLeft(); // Turn away from obstacle } else { moveForward(); // Path is clear — keep cleaning! } delay(50); // Small pause before checking again }
🔍 How Does It Work?
The robot uses a clever loop to keep your floors clean automatically — 20 times every second!
1. Sense
The ultrasonic sensor sends out a sound wave and measures how long it takes to bounce back.
2. Calculate
The Arduino does math to turn the echo time into a distance in centimetres.
3. Decide
If something is closer than 20 cm, the code says "STOP and turn!" Otherwise, keep going!
4. Act
The motor driver powers the wheels to go forward or turn, based on what the Arduino decided.
5. Clean
While rolling around, the brush at the front sweeps dust and dirt along the floor!
6. Repeat
The loop() function runs over and over so the robot never stops thinking or cleaning!
⚠️ Safety Tips for Young Engineers
Stay safe while building!
- Always ask a parent or teacher before using hot glue guns or scissors
- Never connect the battery while wiring — disconnect it first!
- Don't touch the motor driver when powered on — it can get warm
- Use USB power for testing your code before connecting the 9V battery
- Keep the robot away from water — electronics and water don't mix!
- Don't run the robot near stairs, table edges, or on wet floors
- Always supervise younger siblings around the robot while it's running
🚀 Cool Upgrades to Try Next!
Level up your robot! 🎮
Add an HC-05 Bluetooth module so you can drive it with your phone!
Add an IR sensor to detect extra dusty spots and clean them twice!
Use an ESP32 to map the room and clean in neat rows like a real Roomba!
Add a buzzer that beeps when the robot finds an obstacle — like a backing-up truck!
LEDs that change colour when the robot turns, stops, or finishes cleaning!
Attach a small box at the back to collect all the swept dust automatically!

Comments
Post a Comment