Guys, In this project we are going to build a robot which can follow a black line on a white surface or white line on a black surface. I think this project is very helpful to you. If you want deliver something to another place just create a line and this robot will do the work by following the line.
Components Required
1. | Arduino UNO | * 1 |
2. | L298N Motor Driver Module | * 1 |
3. | Gear Motor | * 2 |
4. | Wheels | * 2 |
5. | Caster Wheel | * 1 |
6. | IR Proximity Sensor | * 2 |
7. | Acrylic Sheet | * 1 |
8. | 18650 Li-ion Battery | * 2 |
9. | 18650 Li-ion Battery Holder | * 1 |
10. | Jumper Wires | * 1 |
11. | DC Power Switch | * 1 |
Circuit Diagram
Program
int turn_speed = 230; // Max 255
int turn_delay = 10;
//L293 Connection
const int motorA1 = 8;
const int motorA2 = 10;
const int motorAspeed = 9;
const int motorB1 = 12;
const int motorB2 = 13;
const int motorBspeed = 11;
//Sensor Connection
const int left_sensor_pin =A0;
const int right_sensor_pin =A1;
int right_sensor_state;
void setup()
{
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
Serial.begin(9600);
delay(3000);
}
void loop()
{
left_sensor_state = analogRead(left_sensor_pin);
right_sensor_state = analogRead(right_sensor_pin);if(right_sensor_state > 500 && left_sensor_state < 500)
{
Serial.println("turning right");
digitalWrite (motorA1,LOW);digitalWrite(motorA2,HIGH);
digitalWrite (motorB1,LOW);
digitalWrite(motorB2,HIGH);
analogWrite (motorBspeed, turn_speed);
}
if(right_sensor_state < 500 && left_sensor_state > 500)
{
Serial.println("turning left");
digitalWrite (motorA1,HIGH);digitalWrite(motorA2,LOW);
digitalWrite (motorB1,HIGH);
digitalWrite(motorB2,LOW);
analogWrite (motorAspeed, turn_speed);
analogWrite (motorBspeed, vSpeed);
delay(turn_delay);
if(right_sensor_state > 500 && left_sensor_state > 500)
{
Serial.println("going forward");
digitalWrite (motorA2,LOW);digitalWrite(motorA1,HIGH);
digitalWrite (motorB2,HIGH);
digitalWrite(motorB1,LOW);
analogWrite (motorAspeed, vSpeed);
analogWrite (motorBspeed, vSpeed);
}
if(right_sensor_state < 500 && left_sensor_state < 500)
{
analogWrite (motorAspeed, 0);
analogWrite (motorBspeed, 0);
}
}