Obstacle Avoiding Robot



In my previous instructables I made a virtual obstacle avoiding circuit using tinkercad, in this instructables I will tell you how to make this obstacle avoiding robot.
Supplies








Supplies-
-Jumper wires (male to male)
-Jumper wires (male to female)
-Motor Driver
- Hobby motor and wheels
-Arduino with cable
-Castor wheel
-AA battery holder
-Nuts and Bolts
Assembling the Body of the Robot


Attach the chasis as shown in the picture above. You can make your own using cardboard, wood, mdf board or you can buy the sparklebox obstacle avoider robot kit to get the readymade cutouts and assemble them.
link to buy sparklebox obstacle avoider robot kit- https://mysparklebox.com/educational-toys/robotics/obstacle-avoiding-robot-ideal-for-age-9-years-and-above
Attach the Legs to Chasis

Attach the legs of our robot i.e. motors to the chasis by nuts and bolts and attach the wheels to the motor.
Attach the Castor Wheel to the Chasis

To give support to the wheels add a castor wheel using 4 screws and 2 hex spacers
Giving Brain to the Robot

Think of a human without a brain, impossible huh it is the same case for robots as well all robots need a brain to tell all the components what to do by coding the brain in this project we will use arduino as the brain. Use 2 set of nuts and bolts connecting them diagonally to attach the brain to the robot
Attaching Motor Driver to Chasis

Now we will attach a motor driver behind the arduino using 2 nuts and bolts by connecting them diagonally as we did in the case of arduino.
Giving the Robot Its Power Source

We will use a 4 batteries AA battery holder to be used as the power source of our robot which would be connected to the robot by a double sided tape.
Making Connections


Connecting wires is the most important step to make a robot because if your wiring are incorrect it could also lead to damage of your components I have attached the virtual circuit and also a dedicated video to wiring please refer to them, we will also attach the eyes of the robot i.e. ultrasonic distance sensor and fix it in the holes for the eyes.
Programming

Code for obstacle avoiding robot to be copied in arduino IDE-
#define trigPin 6
#define echoPin 7
#define MLa 8 //left motor 1st pin
#define MLb 9 //left motor 2nd pin
#define MRa 10 //right motor 1st pin
#define MRb 11 //right motor 2nd pin
long duration, distance;
void setup() {
Serial.begin(9600);
pinMode(MLa, OUTPUT);
pinMode(MLb, OUTPUT);
pinMode(MRa, OUTPUT);
pinMode(MRb, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
Serial.begin(9600);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
duration = pulseIn(echoPin, HIGH);
distance = duration / 58.2; // Get Distance
Serial.println(distance);
delay(10);
if (distance > 15) // Condition when obstacle is not near than 10cm
{
digitalWrite(MRa, HIGH); // Move Forward
digitalWrite(MRb, LOW);
digitalWrite(MLa, HIGH);
digitalWrite(MLb, LOW);
}
else if ((distance < 10)&&(distance > 0)) // Condition when obstacle is near than 10cm
{
digitalWrite(MRb, LOW); //Stop
digitalWrite(MRa, LOW);
digitalWrite(MLb, LOW);
digitalWrite(MLa, LOW);
delay(100);
digitalWrite(MRa, LOW); // Move Backward
digitalWrite(MRb, HIGH);
digitalWrite(MLa, LOW);
digitalWrite(MLb, HIGH);
delay(500);
digitalWrite(MRb, LOW); //Stop
digitalWrite(MRa, LOW);
digitalWrite(MLb, LOW);
digitalWrite(MLa, LOW);
delay(100);
digitalWrite(MLa, LOW); // Move RIGHT
digitalWrite(MLb, HIGH);
digitalWrite(MRa, HIGH);
digitalWrite(MRb, LOW);
delay(500);
}
}
JUST HAVE FUN

OBSTACLE AVOIDING ROBOT rules!