How To Make A Floor Cleaning Robot Using Ultrasonic Sensor?

An automatic floor cleaning robot is not a new concept. But these robots have a major issue. They are very expensive. What if we can make a low-cost floor cleaning robot that is as efficient as the robot available in the market. This Robot will use an ultrasonic sensor and will avoid any obstacle in its way. By doing so, it will clean the whole room.

(This Picture is taken from Circuit Digest)

How To Use Ultrasonic Sensor To Make An Automatic Floor Cleaning Robot?

As we now know the abstract of our project. Let us gather some more information to start working.

Step 1: Collecting The Components

The best approach to start any project is to make a list of complete components at the start and going through a brief study of each component. This helps us in avoiding the inconveniences in the middle of the project. A complete list of all the components used in this project is given below.

  • No products found.
  • No products found. No products found.
  • No products found.
  • No products found.
  • Battery
  • Show Brush
  • No products found.

Step 2: Studying The Components

Now as we have a complete list of all the components, let us move a step ahead and study the working of each component briefly.

Arduino nano is a microcontroller board that is used to control or carry out different tasks in a circuit. We burn a  C Code on Arduino Nano to tell the microcontroller board how and what operations to perform. Arduino Nano has exactly the same functionality as Arduino Uno but in quite a small size. The microcontroller on the Arduino Nano board is ATmega328p.

Arduino Nano

The L298N is a high current and high voltage integrated circuit. It is a dual full-bridge designed to accept standard TTL logic. It has two enable inputs that allow the device to operate independently. Two motors can be connected and operated at the same time. The speed of the motors is varied through the PWM pins.

L298N Motor Driver

HC-SR04 board is an ultrasonic sensor which is used to determine the distance between two objects. It consists of a transmitter and a receiver. The transmitter converts the electrical signal into an ultrasonic signal and the receiver converts the ultrasonic signal back to the electrical signal. When the transmitter sends an ultrasonic wave, it reflects after colliding with a certain object. The distance is calculated by using the time, that ultrasonic signal takes to go from the transmitter and come back to the receiver.

Ultrasonic Sensor

Step 3: Assembling The Components

As we now know how all the components work, let us assemble all the components and start making a robot.

Take a car wheel chassis and mount a show brush in front of the chasses. Mount the Scotch Brite beneath the robot. Make sure it is right behind the shoe brush. Now attach a small breadboard on the top of the chasses and behind it, attach the Motor driver. Make proper connections of the motors to the motor driver and carefully connect the pins f motor driver to the Arduino. Mount a battery behind the chassis. The battery will power up the Motor driver which will power the motors. The Arduino will also take power from the Motor driver. Vcc pin and the ground of the ultrasonic sensor will be connected to the 5V and ground of the Arduino.

Circuit Diagram

Step 4: Getting Started With Arduino

If you are not already familiar with the Arduino IDE, don’t worry because a step by step procedure to set-up and use Arduino IDE with a microcontroller board is explained below.

  1. Download the latest version of Arduino IDE from Arduino.
  2. Connect your Arduino Nano board to your laptop and open the control panel. in the control panel, click on Hardware and Sound. Now click on Devices and Printers. Here, find the port to which your microcontroller board is connected. In my case it is COM14 but it is different on different computers.
    Finding Port
  3. Click on the Tool menu and set the board to Arduino Nano.
    Setting Board
  4. In the same Tool menu, set the port to the port number that you observed before in the Devices and Printers.
    Setting Port
  5. In the same Tool menu, Set the Processor to ATmega328P (Old Bootloader).
    Processor
  6. Download the code attached below and paste it into your Arduino IDE. Click on the upload button to burn the code on your microcontroller board.
    Upload

Click here to download the code.

Step 5: Understanding The Code

The code is pretty well commented and self-explanatory. But still, it is explained briefly below.

1. At the start, all the pins of Arduino that we are going to use, are initialized.

int enable1pin=8; // Pins for first Motor 
int motor1pin1=2; 
int motor1pin2=3;
int enable2pin=9; // Pins for second Motor
int motor2pin1=4;
int motor2pin2=5;

const int trigPin = 11; // Pins for Ultrasonic Sensor
const int echoPin = 10;
const int buzzPin = 6;

long duration; // Variables for Ultrasonic Sensor
float distance;

2. void setup() is a function in which we set all the pins to be used as INPUT or OUTPUT. Baud Rate is also set in this function. Baud rate is the speed by which the microcontroller board communicates with the sensors attached.

void setup() 
{
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT); 
pinMode(buzzPin, OUTPUT);
pinMode(enable1pin, OUTPUT);
pinMode(enable2pin, OUTPUT);
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
}

3. void loop() is a function that runs continuously in a loop. In this loop, we have told the microcontroller when to move forward if no obstacle is found in 50cm. The robot will take a sharp right turn when an obstacle is found.

void loop() 
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distance = 0.034*(duration/2);

if(distance>50) // Move Forward if no obstacle found 
{
digitalWrite(enable1pin, HIGH);
digitalWrite(enable2pin, HIGH);
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
} 

else if(distance<50) // Sharp Right Turn if an obstacle found
{
digitalWrite(enable1pin, HIGH);
digitalWrite(enable2pin, HIGH); 
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, LOW);
} 
delay(300); // delay
}

Now, as we have discussed everything you need to make an automatic floor cleaning robot, enjoy making your own low cost and efficient floor cleaning robot.

ABOUT THE AUTHOR

Hamza Iqbal


Hey! I am Hamza. I am an Electrical Engineer who has a very innovative approach towards daily life stuff. I tend to make life easier by making circuits and designs to automate things around me. I mainly work with printed circuit boards on proteus to bring life to my inventions.