Build your own Arduino based Smart Vacuum Cleaner Robot for Automatic Floor Cleaning

Build your own Arduino based Smart Vacuum Cleaner Robot for Automatic Floor Cleaning

Arduino

ByRajesh 0

Arduino based Smart Vacuum Cleaner Robot

In a present-day scenario, we all are so busy with our work that we don't have the time for cleaning our house properly. The solution to the problem is very simple, you just need to buy a domestic vacuum cleaner robot such as irobot roomba which will clean your house with the press of a button. But such commercial products share one common issue, which is cost. So today, we decided to make a simple Floor cleaner robot, which is not only simple to make but costs very less compared to commercial products available in the market. Frequent readers might remember our Arduino Vacuum Cleaning Robot, which we built a long time ago, but that one was very bulky and needed a big lead-acid battery to move around. The new Arduino Vacuum Cleaner we are going to build here will be compact and more practical. On top of that, this robot will have ultrasonic sensors and an IR proximity sensor. The ultrasonic sensor will allow the robot to avoid obstacles so that it can move freely until the room is properly cleaned, and the proximity sensor will help it to avoid falling from stairs. All these features sound interesting, right? So, let's get started.

In one of our previous articles, we made many bots like the Self Balancing Robot, Automated Surface Disinfecting Robot, and the Obstacle Avoiding Robot. Do check those out if that sounds interesting to you.

Materials Required to Build Arduino Based Floor Cleaning Robot

As we have used very generic components to build the hardware section of the vacuum cleaner robot, you should be able to find all of those in your local hobby store. Here is the complete list of required material along with the image of all the components. 

Components for Floor Cleaning Robot

  • Arduino Pro Mini - 1
  • HC-SR04 Ultrasonic Module - 3
  • L293D Motor Driver - 1
  • 5Volt N20 Motors and Mounting Brackets - 2
  • N20 Motor Wheels - 2
  • Switch - 1
  • LM7805 Voltage Regulator - 1
  • 7.4V Lithium-Ion Battery - 1
  • IR Module - 1
  • Perfboard - 1
  • Castor Wheel - 1
  • MDF
  • Generic Portable Vacuum Cleaner

Portable Vacuum Cleaner

In the component requirement section, we have talked about a portable vacuum cleaner, the images below show exactly that. It is a portable vacuum cleaner from amazon. This comes with a very simple mechanism. It has three parts in the bottom (a small chamber for storing the dust, the middle portion includes the motor, fan, and the battery socket on the top (there is a cover or cap for the battery). It has a DC motor and a fan. This motor is directly connected to 3V (2*1.5volt AA batteries) via a simple switch. As we are powering our robot with a 7.4V battery, we will cut the connection from the internal battery and power it from the 5V power supply. So, we have removed all the unnecessary parts and only the motor with two-wire stays. You can see that in the image below.

Portable Vacuum Cleaner

 HC-SR04 Ultrasonic Sensor Module

HC-SR04 Ultrasonic Sensor Module

To detect the obstacles, we are using the popular HC-SR04 ultrasonic distance sensor or we can call it the obstacle avoidance sensors. The working is very simple, first, the transmitter module sends an ultrasonic wave which travels through air, hits an obstacle, and bounces back and the receiver receives that wave. By calculating the time with Arduino, we can determine the distance. In a previous article on Arduino Based Ultrasonic Distance Sensor project, we have discussed the working principle of this sensor very thoroughly. You can check that out if you want to know more about the HC-SR04 ultrasonic distance sensor module.                         

Floor Sensor (IR Sensor) for Staircase Detection

Floor Sensor for Staircase Detection

In the features section, we have talked about a feature where the robot can detect staircases and can prevent itself from falling. To do that, we are using an IR Sensor. We will make an interface between the IR sensor and Arduino. The working of the IR Proximity Sensor is very simple, it has an IR LED and a photodiode, the IR LED emits IR light and if any obstacle comes in front of this emitted light, it will be reflected, and the reflected light will be detected by the photodiode. But the generated voltage from the reflection will be very low. To increase that, we can use an op-amp comparator, we can amplify and get output. An IR module has three pins - Vcc, ground, and output. Usually, the output goes low when an obstacle comes in front of the sensor. So, we can use this to detect the floor. If for a split second, we detect a high from the sensor, we can stop the robot, turn it back or do anything we want to prevent it from falling from the staircase. In a previous article, we have made a Breadboard version of the IR Proximity Sensor Module and explained the working principle in details, you can check that out if you want to know more about this sensor.

Circuit Diagram of Arduino Based Floor Cleaner Robot

Arduino Based Floor Cleaner Robot Circuit Diagram

We have three ultrasonic sensors that detect obstacles. So, we need to connect all grounds of ultrasonic sensors and connected them to common ground. Also, we connect all the three Vcc of the sensor and connect that to the common VCC pin. Next, we connect the trigger and echo pins to the PWM pins of the Arduino. We also connect the VCC of the IR module to 5V and ground to the ground pin of Arduino, the output pin of the IR sensor module goes to the digital pin D2 of the Arduino. For the motor driver, we connect the two enable pins to 5v and also the driver voltage pin to 5V because we are using 5volt motors. In a previous article, we have made an Arduino Motor Driver Shield, you can check that out to learn more about L293D Motor Driver IC and its operations. The Arduino, Ultrasonic modules, motor driver, and motors work on 5 Volt, the higher voltage will kill it and we are using the 7.4-volt battery, to convert that into 5 Volt, the LM7805 voltage regulator is used. Connect the vacuum cleaner directly to the main circuit.

Building the Circuit for Arduino Based Floor Cleaning Robot 

Floor Cleaning Robot Circuit Board

To solder every component together, first, I took a very small piece of doted perfboard and place every component according to the circuit diagram, and solder everything. This part is very simple but do it with care. Also, we have used two female headers to place the Arduino pro mini. After completing the perfboard soldering, we connect wires to ultrasonic modules and connect them to the corresponding pins, as shown in the schematic.

Building a Housing for Arduino Based Floor Cleaning Robot

In order to get some ideas about my robot, I searched for vacuum cleaner robots online and got some images of round-shaped robots. So, I decided to build a round-shaped robot. To build the chase and body of the robot, I have plenty of options like foam sheet, MDF, cardboard, etc. But I choose MDF because it is hard and has some water-resistant properties. If you are doing this, you can decide which material you will choose for your bot.

To build the robot, I took the MDF sheet, then drew two circles with an 8 CM radius, and inside that circle, I have also drawn another circle having a radius of 4 CM for fitting the vacuum cleaner. Then I cut out the circles. Also, I have cut and removed appropriate pieces for the wheel path (refer to the images for better understanding). Finally, I made three small holes for the castor wheel. The next step is fitting the motors on the base using its brackets, also place and fix the castor wheel to its position. After that, place the ultrasonic sensors to left, right, and middle of the robot. Also, connect the IR module to the downside of the robot. Don't forget to add the switch on outside. That's all about building the robot, if you are getting confused at this point, you can refer to the following images.

Arduino Based Floor Cleaning Robot

For the top part, I have also drawn a circle of 11 CM in radius on the foam sheet and cut it. For the spacing between the top and the bottom part, I had cut three 4 CM long pieces of a plastic tube. After that, I glued the plastic spacers on the bottom part and then I glued the top part. You can cover the side parts of the bot with plastic or similar materials if you want.

Assembling Floor Cleaning Robot

Arduino Based Floor Cleaning Robot - Code

The complete code for this project is given at the end of the document. This Arduino code is similar to the Arduino Based Ultrasonic Distance Sensor code, the only change is in the floor detection. In the following lines, I am explaining how the code works. In this case, we are not using any extra libraries. Below we have described the code in a step-by-step manner. We are not using any extra libraries to decode the distance data from the HC-SR04 sensor, because it's very simple. In the following lines, we described how. First, we need to define the Trigger Pin and Echo Pin for all three ultrasonic distance sensors which are connected to the Arduino board. In this project, we have three Echo pins and three Trigger pins. Note that 1 is the left sensor, 2 is the front sensor, and 3 is the right sensor.

const int trigPin1 = 3;
const int echoPin1 = 5; 
const int trigPin2 = 6;
const int echoPin2 =9; 
const int trigPin3 = 10;
const int echoPin3 = 11;
int irpin =2;

Then we defined variables for the distance which all are (int) type variables and for the duration, we chose to use (long). Again, we have three of each. Also, I have defined an integer for storing the status of the movement, we will talk about it later in this section.

 long duration1;
 long duration2;
 long duration3;
int distanceleft;
int distancefront;
int distanceright;
int a=0;

Next, in the setup section, we need to make all the perspective pins as input or output using the pinModes() function. To send ultrasonic waves from the module, we need to enable trigger pin to high i.e all trigger pins should define as OUTPUT. And to receive the echo, we need to read the state of echo pins so all echo pins should define as INPUT. Also, we enable the serial monitor for troubleshooting. To read the status of the IR-modules, I have defined the irpin as input.

pinMode(trigPin1, OUTPUT);
pinMode(trigPin2, OUTPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin1, INPUT); 
pinMode(echoPin2, INPUT);
pinMode(echoPin3, INPUT);
 pinMode(irpin, INPUT);

And these digital pins are defined as OUTPUT for the input of the motor driver.

pinMode(4, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(12, OUTPUT);

In the main loop, we have three sections for three sensors. All the sections work the same but each for different sensors. In this section, we read the obstacle distance from each sensor and store it in each defined integer. To read the distance, first, we have to make sure that the trigger pins are clear, for that, we need to set the trigger pin to LOW for 2 µs. Now, for generating the ultrasonic wave, we need to turn the trigger pin HIGH for 10 µs. This will send the ultrasonic sound and with the help of the pulseIn() function, we can read the travel time, and store that value into the variable “duration”. This function has 2 parameters, the first one is the name of the echo pin and for the second one, you can write either HIGH or LOW. HIGH means that the pulseIn() function will wait for the pin to go HIGH caused by the bounced sound wave and it will start counting, then it will wait for the pin to go LOW when the sound wave will end which will stop the counting. This function gives the length of the pulse in microseconds. For calculating the distance, we will multiply the duration by 0.034 (speed of sound in air is 340m/s) and divide it by 2 (this is due to the back and forth traveling of the sound wave). Finally, we store the distance of each sensor in corresponding integers.

digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distanceleft = duration1 * 0.034 / 2;

After getting the distance from each sensor, we can control the motors with the help of an if statement thus we control the movement of the robot. This is very simple, first, we gave an obstacle distance value, in this case, it is 15cm (change this value as your wish). Then we gave conditions according to that value. For example, when an obstacle comes in front of the left sensor (that means the distance of the left sensor should below or equals to 15 cm) and the other two distances are high (that means no obstacle is in front of that's sensors), then with the help of digital write function, we can drive the motors to right. Later, I checked the status of the IR sensor. If the robot is on the floor, the value of the IR pin will be LOW, and if not, then the value will be HIGH. Then I stored that value in the int s variable. We are going to control the robot according to this status.

This section of the Code is used to Move the Robot Forward and Backward:

if(s==HIGH)
  { 
    digitalWrite(4, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(12, HIGH);
      delay(1000);
    a=1;
        }

But there is a problem with this method when the motor moves backward, the floor comes back and the bot will move forward, and it will repeat making the bot stuck. To overcome that, we store a value (1) in int after understanding floor is not present. We also check this condition for other movements.

After detecting the absence of the floor, the robot will not move forward. Instead, it will move left, this way, we can avoid the problem.

if ((a==0)&&(s==LOW)&&(distanceleft <= 15 && distancefront > 15 && distanceright <= 15) || (a==0)&&(s==LOW)&&(distanceleft > 15 && distancefront > 15 && distanceright > 15))

In the above condition. First, the robot will check the floor status and integer value. The bot will only move forward if all conditions are satisfied.

Now, we can write the commands for the motor driver. This will drive the right-motor backward and the left-motor forward, thereby turning the robot to the Right.

This section of the Code is used to Move the Robot Right:

 digitalWrite(4, HIGH);
 digitalWrite(7, LOW);
 digitalWrite(8, HIGH);
 digitalWrite(12, LOW);

If the bot detects the floor is absent, the value changes to 1, and the bot will move to the left. After turning left, the value of 'a' changes to 0 from 1.

 if ((a==1) &&(s==LOW) ||(s==LOW) && (distanceleft <= 15 && distancefront <= 15 && distanceright > 15) || (s== LOW) && (distanceleft <= 15 && distancefront <= 15 && distanceright > 15) || (s==LOW) && (distanceleft <= 15 && distancefront > 15 && distanceright > 15) || (distanceleft <= 15 && distancefront > 15 && distanceright > 15))
  {
    digitalWrite(4, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(12, HIGH);
    delay(100);
    a=0;
  }

This section of the Code is used to Move the Robot Left:

 if ((s==LOW)&&(distanceleft > 15 && distancefront <= 15 && distanceright <= 15) ||(s==LOW)&& (distanceleft > 15 && distancefront > 15 && distanceright <= 15) ||(s==LOW)&& (distanceleft > 15 && distancefront <= 15 && distanceright > 15) )
    {
    digitalWrite(4, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(12, LOW);
  }

Floor Cleaning Robot

That's it for building Arduino based Smart Vacuum Cleaner Robot. The complete working of the project can be found in the video linked at the bottom of this page. If you have any questions, comment down below.

Code
// defining the pins
const int trigPin1 = 3;
const int echoPin1 = 5;
const int trigPin2 = 6;
const int echoPin2 = 9;
const int trigPin3 = 10;
const int echoPin3 = 11;
int irpin =2;
// defining variables
long duration1;
long duration2;
long duration3;
int distanceleft;
int distancefront;
int distanceright;
int a=0;
void setup() {
  pinMode(trigPin1, OUTPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(trigPin3, OUTPUT);// Sets the trigPin as an Output
  pinMode(echoPin1, INPUT); // Sets the echoPin as an Input
  pinMode(echoPin2, INPUT);
  pinMode(echoPin3, INPUT);
  pinMode(irpin, INPUT);
  pinMode(4, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, OUTPUT);
}
void loop() {
  digitalWrite(trigPin1, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distanceleft = duration1 * 0.034 / 2;
  Serial.print("Distance1: ");
  Serial.println(distanceleft);
  digitalWrite(trigPin2, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin2, LOW);
  duration2 = pulseIn(echoPin2, HIGH);
  distancefront = duration2 * 0.034 / 2;
  Serial.print("Distance2: ");
  Serial.println(distancefront);
  digitalWrite(trigPin3, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin3, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin3, LOW);
  duration3 = pulseIn(echoPin3, HIGH);
  distanceright = duration3 * 0.034 / 2;
  Serial.print("Distance3: ");
  Serial.println(distanceright);
  int s = digitalRead(irpin);
  if(s==HIGH)
  { 
    digitalWrite(4, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(12, HIGH);
      delay(1000);
    a=1;
    }
  if ((a==0)&&(s==LOW)&&(distanceleft <= 15 && distancefront > 15 && distanceright <= 15) || (a==0)&&(s==LOW)&&(distanceleft > 15 && distancefront > 15 && distanceright > 15))
  {
    digitalWrite(4, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(8, HIGH);
    digitalWrite(12,LOW);
  }
  if ((a==1)&&(s==LOW)||(s==LOW)&&(distanceleft <= 15 && distancefront <= 15 && distanceright > 15)||(s==LOW)&&(distanceleft <= 15 && distancefront <= 15 && distanceright > 15)||(s==LOW)&& (distanceleft <= 15 && distancefront > 15 && distanceright > 15)||(distanceleft <= 15 && distancefront > 15 && distanceright > 15))
  {
    digitalWrite(4, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(12, HIGH);
    delay(100);
    a=0;
  }
  if ((s==LOW)&&(distanceleft > 15 && distancefront <= 15 && distanceright <= 15) ||(s==LOW)&& (distanceleft > 15 && distancefront > 15 && distanceright <= 15) ||(s==LOW)&& (distanceleft > 15 && distancefront <= 15 && distanceright > 15) )
  {
    digitalWrite(4, LOW);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(12, LOW);
  } 
}
Video

Get Our Weekly Newsletter!

Subscribe below to receive most popular news, articles and DIY projects from Circuit Digest

Comments

Log in or register to post Comment