In this blog, I will explain you how to build a obstacle avoiding robot using Arduino UNO.
Materials Required;
1.
Arduino uno/nano/mega/mini.
2.Motor driver L298n.
3.Two dc motors.
4.Two wheels with high grip
5. One chasey.
6.One caster wheel.
7.Ultrasonic Sensor.
Circuit Diagram
|
circuit design in Fritzing |
What is an ultrasonic sensor?
An ultrasonic sensor is an instrument that measures the distance to an object using ultrasonic sound waves.
An ultrasonic sensor uses a transducer to send and receive ultrasonic pulses that relay back information about an object’s proximity.
High-frequency sound waves reflect from boundaries to produce distinct echo patterns.
Arduino code
int trigPin = 9; |
| int echoPin = 10; |
| int revright = 4; //REVerse motion of Right motor |
| int fwdleft = 7; |
| int revleft= 6; |
| int fwdright= 5; //ForWarD motion of Right motor |
| int c = 0; |
| |
| void setup() { |
| //Serial.begin(9600); |
| pinMode(5, OUTPUT); |
| pinMode(6, OUTPUT); |
| pinMode(4, OUTPUT); |
| pinMode(7, OUTPUT); |
| pinMode(trigPin, OUTPUT); |
| pinMode(echoPin, INPUT); |
| // put your setup code here, to run once: |
| |
| } |
| |
| void loop() { |
| long duration, distance; |
| digitalWrite(trigPin,HIGH); |
| delayMicroseconds(1000); |
| digitalWrite(trigPin, LOW); |
| duration=pulseIn(echoPin, HIGH); |
| distance =(duration/2)/29.1; |
| //Serial.print(distance); |
| //Serial.println("CM"); |
| delay(10); |
| |
| |
| if((distance>20)) |
| { |
| digitalWrite(5,HIGH); // If you dont get proper movements of your robot, |
| digitalWrite(4,LOW); // then alter the pin numbers |
| digitalWrite(6,HIGH); // |
| digitalWrite(7,LOW); // |
| } |
| |
| else if(distance<20) |
| { |
| digitalWrite(5,LOW); |
| digitalWrite(4,HIGH); |
| digitalWrite(6,HIGH); //HIGH |
| digitalWrite(7,LOW); |
| |
| } |
| |
| }
Github link-https://github.com/AmanJaiswal210/Avoid-obstacle-Robot
Media gallery
|
|
| |
0 comments:
Post a Comment