Introduction: Obstacle Detection Robot Using Three Ultrasonic Sensors and Arduino UNO

Picture of Obstacle Detection Robot Using Three Ultrasonic Sensors and Arduino UNO

Here we are going to implement a bot which is going to detect obstacle and according to that, it going to change its direction.

Step 1: Objective of This Project

Picture of Objective of This Project

In this project we are going to make Avoid obstacle Robot. Here we are going to interface three ultrasonic sensors with arduino uno. We are also using two Dc motors so for that we need one motor driver module because Arduino itself is not capable to give that much amount of current which is able to run dc motors. So for that we are using Motor Driver Module (L298D).

Step 2: Software Used

Picture of Software Used

As we are using Arduino Uno Module so for that you have to use Arduino IDE

Here is the link to download Arduino IDE

https://www.arduino.cc/en/Main/Software

Step 3: Hardware Used

Picture of Hardware Used

These are the Components you required for this project

1. Arduino UNO:

2. Motor Driver Module (L298D)

3. Ultrasonic Sensor(HcSR04)

4. Dc gear Motor

5. Jumper Wires

And one Robot Car Battery Box Chassis Kit you will need for this project so you can get that one as well.

Here I'm going to explain you briefly about these components

1. Arduino Uno:

Arduino/Genuino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button.

2. Ultrasonic Sensor(HC-SR04 ):

Ultrasonic range sensor( HC - SR04) provides 2cm - 400cm distance measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit.

3. Motor Driver(L298N):

The L298N H-bridge module can be used with motors that have a voltage of between 5 and 35V DC. With the module used in this tutorial, there is also an onboard 5V regulator, so if your supply voltage is up to 12V you can also source 5V from the board.

4. Dc gear Motor: In this project we are using two Dc gear motor

Step 4: Controlling DC Motors

Picture of Controlling DC Motors

To control one or two DC motors is quite easy with the L298N H-bridge module. First connect each motor to the A and B connections on the L298N module. If you’re using two motors for a robot (etc) ensure that the polarity of the motors is the same on both inputs. Otherwise you may need to swap them over when you set both motors to forward and one goes backwards!

Next, connect your power supply – the positive to pin 4 on the module and negative/GND to pin 5. If you supply is up to 12V you can leave in the 12V jumper (point 3 in the image above) and 5V will be available from pin 6 on the module. This can be fed to your Arduino’s 5V pin to power it from the motors’ power supply. Don’t forget to connect Arduino GND to pin 5 on the module as well to complete the circuit.

Now you will need six digital output pins on your Arduino, two of which need to be PWM (pulse-width modulation) pins. PWM pins are denoted by the tilde (“~”) next to the pin number, for example:

Finally, connect the Arduino digital output pins to the driver module. In our example we have two DC motors, so digital pins D9, D8, D7 and D6 will be connected to pins IN1, IN2, IN3 and IN4 respectively. Then connect D10 to module pin 7 (remove the jumper first) and D5 to module pin 12 (again, remove the jumper).

The motor direction is controlled by sending a HIGH or LOW signal to the drive for each motor (or channel). For example for motor one, a HIGH to IN1 and a LOW to IN2 will cause it to turn in one direction, and a LOW and HIGH will cause it to turn in the other direction.

However the motors will not turn until a HIGH is set to the enable pin (7 for motor one, 12 for motor two). And they can be turned off with a LOW to the same pin(s). However if you need to control the speed of the motors, the PWM signal from the digital pin connected to the enable pin can take care of it.

Step 5: Project Description:

Picture of Project Description:

First we are going to connect three ultrasonic sensor with our Arduino board. Then according to program our three ultrasonic sensor going to generate a trigger signal which is going to receive by our echo pin of Ultrasonic Sensor. Then we are going to run an algorithm according to which we are going to manipulate our desire distance for obstacle detection then we are going to control our motor rotation direction for movement of our bot. 50CM(Front),15CM (Each Side).

Here above you can see the circuit diagram of this circuit

Step 6: Project Code and Video

You can download source code of this project from the link below

Or else you can also go to our github page : here

And here you can watch it out in action in our video

If you will finish all the steps correctly then you will have one robotic bot with three ultrasonic sensor. So Enjoy your Avoid Obstacle Robot

If you have any question regarding this project feel free to comment us below

For more project you can visit our youtube channel here

And in case you need any help - you can contact us at info@deligence.com. In case you need any embedded systems development or IoT work - you can send an email to us at sales@deligence.com


Comments

23braggeric (author)2017-10-12

I have a problem Because on the diagram it says to connect negative toground and the 6-12v box. also i have 12v dc motor and a 6v box and the motor won't budge how can i bump up the voltedge. plus dc motors have negative and positive wear do they go on the driver motor. please help me figure how to fix this

ppr153 (author)2017-08-20

sir, kindly tell me how many watt of battary did u used in your project?

deligence (author)ppr1532017-08-20

we are using a combination of 4 cell: each cell is 1.5 v

ppr153 (author)deligence2017-08-21

Ty sir

blue vehicle (author)2017-08-18

Hey it's good who's that gue

RajeshS143 (author)2017-07-10

I need help. I am having trouble with the code please help me!!!

Code:

int main()

{

// put your setup code here, to run once:

void Setup()

{

Serial.begin(9600);

pinMode(Echo1, INPUT);

pinMode(Trig1, OUTPUT);

pinMode(Echo2, INPUT);

pinMode(Trig2, OUTPUT);

pinMode(Echo3, INPUT);

pinMode(Trig3, OUTPUT);

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

pinMode(in3, OUTPUT);

pinMode(in4, OUTPUT);

pinMode(ENA, OUTPUT);

pinMode(ENB, OUTPUT);

_mStop();

}

int Echo1 = A4; //LEFT_SENSOR ECHO

int Trig1 = A5; //LEFT_SENSOR TRIG

int Echo2 = A2; //MID_SENSOR ECHO

int Trig2 = A3; //MID_SENSOR TRIG

int Echo3 = A0; //RIGHT_SENSOR ECHO

int Trig3 = A1; //RIGHT_SENSOR TRIG

int in1 = 8;

int in2 = 9;

int in3 = 6;

int in4 = 7;

int ENA = 5;

int ENB = 11;

int ABS = 200;

int Left_Distance = 0, Right_Distance = 0, Middle_Distance = 0 ;

void _mForward()

{

digitalWrite(in1, LOW);

digitalWrite(in2, HIGH);

digitalWrite(in3, LOW);

digitalWrite(in4, HIGH);

analogWrite(ENA, ABS);

analogWrite(ENB, ABS);

Serial.println("ROBOT_MOVING_FORWARD");

}

void _mBack()

{

digitalWrite(in1, HIGH);

digitalWrite(in2, LOW);

digitalWrite(in3, HIGH);

digitalWrite(in4, LOW);

analogWrite(ENA, ABS);

analogWrite(ENB, ABS);

Serial.println("ROBOT_MOVING_BACKWARD");

}

void _mleft()

{

digitalWrite(in1, LOW);

digitalWrite(in2, HIGH);

digitalWrite(in3, LOW);

digitalWrite(in4, LOW);

analogWrite(ENA, ABS);

analogWrite(ENB, ABS);

Serial.println("ROBOT_MOVING_LEFT");

}

void _mright()

{

digitalWrite(in1, LOW);

digitalWrite(in2, LOW);

digitalWrite(in3, LOW);

digitalWrite(in4, HIGH);

analogWrite(ENA, ABS);

analogWrite(ENB, ABS);

Serial.println("ROBOT_MOVING_RIGHT");

}

void _mStop()

{

digitalWrite(in1, LOW);

digitalWrite(in2, LOW);

digitalWrite(in3, LOW);

digitalWrite(in4, LOW);

digitalWrite(ENA, LOW);

digitalWrite(ENB, LOW);

Serial.println("ROBOT_STOP");

}

/*Ultrasonic distance measurement Sub function*/

int Left_Distance_test()

{

digitalWrite(Trig1, LOW);

delayMicroseconds(2);

digitalWrite(Trig1, HIGH);

delayMicroseconds(20);

digitalWrite(Trig1, LOW);

float Fdistance = pulseIn(Echo1, HIGH);

delay(10);

Fdistance = Fdistance / 29 / 2;

return (int)Fdistance;

}

int Middle_Distance_test()

{

digitalWrite(Trig2, LOW);

delayMicroseconds(2);

digitalWrite(Trig2, HIGH);

delayMicroseconds(20);

digitalWrite(Trig2, LOW);

float Fdistance = pulseIn(Echo2, HIGH);

delay(10);

Fdistance = Fdistance / 29 / 2;

return (int)Fdistance;

}

int Right_Distance_test()

{

digitalWrite(Trig3, LOW);

delayMicroseconds(2);

digitalWrite(Trig3, HIGH);

delayMicroseconds(20);

digitalWrite(Trig3, LOW);

float Fdistance = pulseIn(Echo3, HIGH);

delay(10);

Fdistance = Fdistance / 29 / 2;

return (int)Fdistance;

}

void loop()

{

Left_Distance = Left_Distance_test();

delay(10);

Middle_Distance = Middle_Distance_test();

delay(10);

Right_Distance = Right_Distance_test();

delay(10);

Serial.println("Left_Distance\tMiddle_Distance\tRight_Distance\tStatus\n");

Serial.print(Left_Distance);

Serial.print("cm\t\t");

Serial.print(Middle_Distance);

Serial.print("cm\t\t");

Serial.print(Right_Distance);

Serial.print("cm\t\t");

if (Middle_Distance <= 50)

{

if (Right_Distance > Left_Distance)

{

if ((Right_Distance <= 30) && (Left_Distance <= 30))

{ _mStop();

delay(100);

_mBack();

delay(600);

}

else

{

_mright();

delay(300);

}

}

}

else if (Right_Distance < Left_Distance)

{

if ((Right_Distance <= 30) && (Left_Distance <= 30))

{ _mStop();

delay(100);

_mBack();

delay(700);

}

else

{

_mleft();

delay(300);

}

}

}

else if (Right_Distance <= 20)

{

_mleft();

delay(300);

}

else if (Left_Distance <= 20)

{

_mright();

delay(300);

}

else

{

_mForward();

}

}

About This Instructable

2,808views

41favorites

License:

Bio: We are a team of IoT &amp; Embedded Systems developers. We are working in Raspberry Pi and Arduino.
More by deligence:Over the Air(OTA) Update of Nodemcu(esp8266) Using MQTT)Raspberry Pi Web GPIO With Live Streaming Creating a Virtual World  Using Arduino and Python
Add instructable to: