In this article we will learn how to make Line Following Robot Using Arduino.
You can visit our website, I hope you appreciate my work, let’s discuss about today’s project.
What is Line Following Robot?The Line Following Robot is an autonomous robot designed to follow a specific path or line on the ground. It typically employs sensors to detect the contrast between the line and its surroundings, allowing it to stay on track and navigate through a predefined route.
1. Arduino Uno
2. Button
3. LED
4. Resistors
5. Sounder
6. IR sensors
7. DC motors
8. H-Bridge
9. Jumper Wires
Circuit Connections:· Connect D12 pin of Arduino with one side of Push Button
· Connect 2ndside of Push button with one side of Resistor
· Connect 2ndside of Resistor with GND
· Connect one side of Sounder with GND
· Connect 2ndside of Sounder with D3 pin of Arduino Uno
· Connect one side of Resistor with +5V
· Connect 2ndside of Resistor with one side of Push button through Reset pin
· Connect 2ndside f Push button with GND
· Connect –ve Terminal of LED with GND
· Connect +ve terminal f LED with D13 pin of Arduino Uno
CircuitConnectionDiagram:
The working principle of a Line Following Robot is based on the interaction between its sensors, control system, and motors.
Ø Sensors:
The robot is equipped with sensors (often infrared or IR sensors) that continuously scan the ground below to detect the line's presence. These sensors can differentiate between the line and the background surface by recognizing the contrast in color or reflectivity.
Ø Control System:
The robot's control system, usually a microcontroller or a similar onboard computer, receives signals from the sensors. It processes this input to determine the robot's position relative to the line.
Ø Decision Making:
Based on the sensor readings, the control system executes programmed instructions or algorithms. It decides the appropriate action for the robot to stay on track. For instance, if the sensors detect the line beneath the robot, it continues moving forward. If the sensors detect the robot veering off the line, the control system adjusts the robot's movements to realign it with the line.
Ø Motor Control:
The control system sends commands to the robot's motors via a motor driver circuit. These commands dictate the speed and direction of the motors, enabling the robot to maneuver in a way that keeps it following the line accurately.
Ø Feedback Loop:
The process operates in a continuous loop where the sensors continually provide input; the control system processes this data, makes decisions, and adjusts the robot's movements accordingly. This feedback loop allows the robot to maintain its course along the line.
Advantages:1. Simplicity:
It's relatively straight forward to build and program, making it an excellent starting point for beginners in robotics and programming.
2. Educational Tool:
It's an effective educational tool for learning about sensors, control systems, programming logic, and robotics principles in a hands-on manner.
3. Cost-Effectiveness:
Building a line follower robot can be affordable, especially with readily available components and open-source platforms like Arduino or Raspberry Pi.
4. Versatility:
It can be adapted for various applications beyond following lines, such as in automated logistics, path tracking in industries, or even as a base for more complex robot designs.
5. Competitions and Challenges:
Line following robots is used in competitions, encouraging creativity and innovation in designing efficient algorithms and strategies for precise line tracking.
Program code:#define IR_SENSOR_RIGHT 12
#define IR_SENSOR_LEFT 11
#define MOTOR_SPEED 100
//Right motor
int enableRightMotor=6;
int rightMotorPin1=2;
int rightMotorPin2=3;
//Left motor
int enableLeftMotor=4;
int leftMotorPin1=5;
int leftMotorPin2=10;
void setup()
{
//The problem with TT gear motors is that, at very low pwm value it does not even rotate.
//If we increase the PWM value then it rotates faster and our robot is not controlled in that speed and goes out of line.
//For that we need to increase the frequency of analogWrite.
//Below line is important to change the frequency of PWM signal on pin D5 and D6
//Because of this, motor runs in controlled manner (lower speed) at high PWM value.
//This sets frequecny as 7812.5 hz.
TCCR0B = TCCR0B & B11111000 | B00000010 ;
// put your setup code here, to run once:
pinMode(enableRightMotor, OUTPUT);
pinMode(rightMotorPin1, OUTPUT);
pinMode(rightMotorPin2, OUTPUT);
pinMode(enableLeftMotor, OUTPUT);
pinMode(leftMotorPin1, OUTPUT);
pinMode(leftMotorPin2, OUTPUT);
pinMode(IR_SENSOR_RIGHT, INPUT);
pinMode(IR_SENSOR_LEFT, INPUT);
rotateMotor(0, 0);
}
void loop()
{
int rightIRSensorValue = digitalRead(IR_SENSOR_RIGHT);
int leftIRSensorValue = digitalRead(IR_SENSOR_LEFT);
//If none of the sensors detects black line, then go straight
if (rightIRSensorValue == LOW && leftIRSensorValue == LOW)
{
rotateMotor(MOTOR_SPEED, MOTOR_SPEED);
}
//If right sensor detects black line, then turn right
else if (rightIRSensorValue == HIGH && leftIRSensorValue == LOW )
{
rotateMotor(-MOTOR_SPEED, MOTOR_SPEED);
}
//If left sensor detects black line, then turn left
else if (rightIRSensorValue == LOW && leftIRSensorValue == HIGH )
{
rotateMotor(MOTOR_SPEED, -MOTOR_SPEED);
}
//If both the sensors detect black line, then stop
else
{
rotateMotor(0, 0);
}
}
void rotateMotor(int rightMotorSpeed, int leftMotorSpeed)
{
if (rightMotorSpeed < 0)
{
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, HIGH);
}
else if (rightMotorSpeed > 0)
{
digitalWrite(rightMotorPin1, HIGH);
digitalWrite(rightMotorPin2, LOW);
}
else
{
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, LOW);
}
if (leftMotorSpeed < 0)
{
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, HIGH);
}
else if (leftMotorSpeed > 0)
{
digitalWrite(leftMotorPin1, HIGH);
digitalWrite(leftMotorPin2, LOW);
}
else
{
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, LOW);
}
analogWrite(enableRightMotor, abs(rightMotorSpeed));
analogWrite(enableLeftMotor, abs(leftMotorSpeed));
}
Comments