How to Build Arduino Smart Vacuum for Automatic Floor Cleaning

Original idea and source via Circuit Digest.

Our lives are becoming hectic every day. This means that we have less time to clean our home. While there are commercial solutions to this problem, not everybody can afford costly automatic vacuum cleaners. If you are looking to save some money, we can help you build an automatic surface cleaning robot that only takes a couple of components and a few coding skills. Arduino smart vacuum robot uses ultrasonic and IR proximity sensors to avoid obstacles and clean without colliding with any objects. It offers all the features you could find in a commercial surface cleaning robot and more.

Components required for the project

Source via Circuit Digest.

The project uses simple components to build the robot so you should have no problem finding them in your regular hardware store. Find the component list below:

Arduino Pro Mini (quantity: 1)

⦁ 7.4V Lithium-Ion Battery (quantity: 1)

⦁ L293D Motor Driver (quantity: 1)

⦁ LM7805 Voltage Regulator (quantity: 1)

⦁ N20 Motor Wheels (quantity: 2)

⦁ HC-SR04 Ultrasonic Module (quantity: 3)

⦁ 5Volt N20 Motors and Mounting Brackets (quantity: 2)

⦁ Switch (quantity: 1)

⦁ LM7805 Voltage Regulator (quantity: 1)

⦁ IR Module (quantity: 1)

⦁ MDF (material for housing)

⦁ Perfboard (quantity: 1)

⦁ Castor Wheel (quantity: 1)

⦁ A Portable Vacuum Cleaner

We recommend that you get a portable vacuum cleaner with a simple mechanism. Any vacuum cleaner that has minimum parts including a small dust-collecting chamber, a motor, a fan, and a battery socket. Most simple portable vacuums have a fan and a DC motor. The motor connects to the batteries, usually 3V (AA batteries) through a switch. Once you have the portable vacuum cleaner, you need to prepare it for your project. For example, change the batteries to 7.4 V.

Source via Circuit Digest.

Once you have assembled all the components mentioned in the list, use the circuit diagram below to put them together. More on this later in the tutorial.

Source via Circuit Digest.

Step-by step process for building the robot

Before we get into the technicalities of building the vacuum robot, let’s go through the sensors used in the machine first.

We are using two different sensors: HC-SR04 ultrasonic distance sensor and IR proximity sensor. Both sensors perform distinct functions.

The ultrasonic distance sensor, also known as the obstacle avoidance sensor, works by sending and receiving a sound wave that bounces with the obstacle and comes back to tell the sensor there’s something in its way. You can calculate the time for the sound wave through Arduino.

Source via Circuit Digest.

The floor sensor or the IR sensor detects staircases and avoids falling. To make this sensor work, you need to interface it with Arduino. When there is an object in the way, the infrared light from the LED reflects off the obstacle and alerts the receiver.

Source via Circuit Digest.

You can read more about iR sensors here. Now let’s get back to building the Arduino smart vacuum robot.

In this project, you will use 3 different ultrasonic sensors that will detect objects or obstacles. You need to connect their grounds to the common ground. In addition, you need to connect all 3 VCC of the sensor to the common VCC pin.

Next, connect the echo and triggers pins to the Arduino PWM pins. After that, connect the IR module’s VCC to 5V, and its ground to the Arduino’s ground pin.

Connect The output pin of the sensor module to the Arduino digital pin D2.

To enable the motor driver, connect the 2 enable pins and the driver voltage pin to 5V as the project uses 5 Volt motors.

The ultrasonic modules, motor driver, and Arduino can only sustain 5 volts. The higher voltage can fry the components and render them incapable of function. In this project. A 7.4 Volt battery is used, so to make it work you can use an LM7805 voltage regulator to convert 7.4 to 5 Volt.

Next, connect the vacuum to the main circuit.

How to build the circuit for an Arduino smart vacuum robot?

To ensure precision, use a small dotted perfboard and place components on it as shown in the circuit diagram. Then solder all the components carefully. Use two female headers to position Arduino pro mini. After the soldering process, connect all the components to their corresponding pins as shown in the circuit diagram.

How to build housing for the Arduino smart vacuum robot?

You have plenty of options for building the body and the chase of the robot. You can use MDF, foam sheets, or cardboard. MDF has water-resistant properties which makes it the best option. However, other materials will work just fine.

Follow these steps to build the robot:

⦁ We use MDF for this particular project. So start with the MDF sheet. Draw two circles of an 8-centimeter radius. Inside one of the circles, draw another 4-centimeter circle. This will contain the vacuum cleaner. Cut out these circles as shown in the images below.

⦁ Make 3 small holes to add to the caster wheel.

⦁ Now fit the motor to the base using brackets. Then place the castor wheel in its position.

⦁ Next, connect the ultrasonic sensors to the right, left, and middle of the bot.

⦁ Connect the IR module to the bot’s lower body.

Source via Circuit Digest.
  • Once you are done with the lower part, cut an 11-centimeter circle using a foam sheet for the top or roof of the bot. To add spacing between the top and the bottom, use plastic tubes (4 centimeters in size). Glue the plastic tubes to the bottom and top to shape the body of the robot.
Source via Circuit Digest.
  • Add the switch on the outside and you are done.

Writing the code for the automatic floor cleaning robot

Step 1: Define the Trigger and Echo pins for the 3 ultrasonic sensors linked to the Arduino board. In the following code, 1 indicates the left sensor, 2 indicates the front sensor, and 3 indicates the right sensor. We will write code for all 3.

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;

Step 2: Define variables. For the distance, you will use (int) type while for the duration you can choose (long). Remember that we have three Trigger and Echo pins in this project.

long duration1;
long duration2;
long duration3;
int distanceleft;
int distance front;
int distanceright;
int a=0;

Step 3: Assign input and output to all the pins through the pinModes() function.

To transmit the ultrasonic waves, you need to enable the trigger pin to HIGH i.e. the trigger pins should be set as OUTPUT. On the other hand, to receive the wave back, you need to define all Echo pins as INPUT. In addition, you can enable troubleshooting through a serial monitor.

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

Step 4: Add the following digital pins defined as OUTPUT to indicate motor driver input.

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

Setting up obstacle distance reading

To set up obstacle distance reading, you have to do two things:

First, set to transmit the ultrasonic wave; set the trigger pin HIGH (10 µs). This will generate the ultrasonic sound. You can measure the travel time through pulsein() function and store the result in the “duration” variable.

Note that we have 3 different sections of the 3 sensors in the main loop. All 3 sections work the same but offer different functionality for the different sensors. You need to define the function for each sensor. So, here you’ll see how you can set up obstacle distance reading from each of the sensors and save them in defined integers. To read the obstacle distance, you need to make sure that the trigger pins (all of them) are clear. To make that happen, set the trigger pins to LOW (2µs). Next, to generate the sound wave, set the trigger pin to HIGH (10µs).

You can read or measure the travel time of the sound wave using the pulseIn() function and save that value in the “duration” variable.

This function represents 2 different parameters: The first parameter represents the name of the Echo pin while the second parameter defines HIGH or LOW. The HIGH variable indicates that the function will wait as the pin goes HIGH due to a sound wave bouncing off an obstacle triggering the counting. Then the function will wait for the pin to go LOW which would indicate that the sound wave has ended and the counting has stopped.

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

To calculate the distance, multiply the total duration by 0.034 and divide the result by 2. Then store the distance value of each sensor in the right integers.

Next, you can use the if statement to control the motors. This will control the movement of the bot. To add controls for the bot movement, give an obstacle a distance value. For example, you can add 15 centimeters as the distance value. Next, give conditions for that value so the bot knows when to move. The bot will move when certain conditions are met. For example, If the left sensor comes across an obstacle with 15 centimeters or less distance and the distance for the other two sensors (from the obstacle ) is higher then the robot will move to the right. If the bot is on the floor, the IR sensor will have a LOW value. If it’s not on the floor, the value will be HIGH. You can measure and store this value inside the int s variable.

The following code will 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;
}

Now you may face a slight problem: when the robot moves back on the floor, it will move forward and may stay stuck in that position. To fix that add (1) to the int function. If the function works, the robot will not go forward and instead move in another direction.

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

With the above code, the robot will sense the floor through integer value. It will only go forward if all the conditions are met for going forward.

The following commands will move the robot to the right:

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

If the floor is missing, the value will turn 1 and the bot will go to its left. After it has made the turn, the value “a” will change 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;
}

The following code will move the bot to the 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);
}

Below you can find the complete code for the Arduino smart vacuum robot.

// 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);
}
}

We hope this tutorial will help you build your very own smart vacuum cleaner so you can avoid the hefty costs associated with commercial vacuums. Learn how to make an Arduino UV sanitizing robot here.

You can get an Arduino Pro Mini here.

We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.

Source via Circuit Digest.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: