Line Follower
In this Arduino Tutorial I will Show you How to Make a Line Following Car Using Arduino Uno Board and Some Electronic Components . You can Watch this Video or Read the following blog for more details..
Working Principle :
Line Follower has a basic and necessary Component IR Sensor which act as Vision. It works on the principle of Black Surface Absorbs all Wavelengths of Light Rays. Then the IR Sensors mounted infront of the car detects black line and makes a movement based on your code.
Components Required :
- Arduino UNO Board
- L293D Motor Driver
- IR Sensors
- Gear Motors and Rubber Wheels
- Jumper Wires
- Li-ion Battery
Construction :
- First you need a cardboard of high Durability.
- And Mount a Gear motors Using Double Sided Tape or GlueGun.
- Place the Arduino Uno Board on the Cardboard Connected With L293D Motor Driver.
- Connect the Gear motor Wires to the L293D Motor Driver.
- And place the IR Senors infront of the Cardboard.
- Connect Sensors to the Motor Driver Using Jumper Wires.
- Make sure your Sensors Output Pins are Correctly Mounted with the Analog input Pins of Motor Driver.
- Now move on to the Software Portion, Open Your Arduino IDE
- Select line_following_car.ino file
- Download Required Libraries and Select Board & Port , Click Upload .
- Now time to Connect a Battery. I use 2no's of li-ion 3.7V battery in Series Connection.
- After Connecting Batteries, Switch on your Car and Place it on Track ,That will Follow the Black track line as follows.
- That's Solve Guys !
Circuit Diagram :
You can follow our DIY video For Circuit Diagram. I will clearly explained the connections of this Line following Car.Arduino Code :
//CRATUS MK1
//LINE FOLLOWER WITH 4 MOTOR
//BY PRADEEP RAJ (M.P.R)
//FEBRUARY 29 2020
// ------THIS CODE IS OPEN SOURCE FOR OUR SUBSCRIBERS------
// ------ THE FAUCETER ------
#include <AFMotor.h>
//defining pins and variables
#define left A1
#define right A0
//defining motors
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);
void setup() {
//declaring pin types
pinMode(left,INPUT);
pinMode(right,INPUT);
//begin serial communication
Serial.begin(9600);
}
void loop(){
//printing values of the sensors to the serial monitor
Serial.println(digitalRead(left));
Serial.println(digitalRead(right));
//line detected by both
if(digitalRead(left)==0 && digitalRead(right)==0){
//Forward
motor1.run(FORWARD);
motor1.setSpeed(120); //full speed for motor is 255
motor2.run(FORWARD);
motor2.setSpeed(120);
motor3.run(FORWARD);
motor3.setSpeed(120);
motor4.run(FORWARD);
motor4.setSpeed(120);
}
//line detected by left sensor
else if(digitalRead(left)==0 && !analogRead(right)==0){
//turn left
motor1.run(BACKWARD);
motor1.setSpeed(200);
motor2.run(FORWARD);
motor2.setSpeed(200);
motor3.run(FORWARD);
motor3.setSpeed(200);
motor4.run(BACKWARD);
motor4.setSpeed(200);
}
//line detected by right sensor
else if(!digitalRead(left)==0 && digitalRead(right)==0){
//turn right
motor1.run(FORWARD);
motor1.setSpeed(200);
motor2.run(BACKWARD);
motor2.setSpeed(200);
motor3.run(BACKWARD);
motor3.setSpeed(200);
motor4.run(FORWARD);
motor4.setSpeed(200);
}
//line detected by none
else if(!digitalRead(left)==0 && !digitalRead(right)==0){
//stop
motor1.run(RELEASE);
motor1.setSpeed(0);
motor2.run(RELEASE);
motor2.setSpeed(0);
motor3.run(RELEASE);
motor3.setSpeed(0);
motor4.run(RELEASE);
motor4.setSpeed(0);
}
}
//-----------------------------------THE FAUCETER---------------------------------------
Hello everyone 🕺
ReplyDelete