This project involves a line follower robot that can navigate a track by following a line on the ground. The robot uses infrared sensors to detect the line and adjusts its movement accordingly. The main features include the ability to move forward, turn left, turn right, and stop based on sensor inputs.
- Motors: DC motors for driving the robot.
- Motor Driver: Controls the direction and speed of the motors.
- Sensors: Infrared sensors for line detection.
- Microcontroller: Arduino for controlling the robot's behavior.
- LED Indicator: Provides visual feedback.
Here is a basic circuit diagram for connecting the components:
-
Motors:
- Motor right 1 (MR1) and Motor right 2 (MR2) connected to the motor driver.
- Motor left 1 (ML1) and Motor left 2 (ML2) connected to the motor driver.
-
Sensors:
- Right sensor (SR) connected to pin 6.
- Left sensor (SL) connected to pin 7.
-
LED:
- Connected to pin 13.
-
Motor Driver Enable Pins:
- ENR connected to pin 3.
- ENL connected to pin 5.
-
Power Supply:
- Connect the power supply to the motor driver and Arduino as per their requirements.
For a detailed circuit diagram, you can create one using circuit design software like Fritzing or refer to a basic motor driver connection guide if you have a specific motor driver model in mind.
The Arduino code for the line follower robot is provided below. This code handles the motor control based on sensor inputs.
// Motor and sensor pin definitions
const int MR1 = 8; // Motor right 1
const int MR2 = 9; // Motor right 2
const int ML1 = 10; // Motor left 1
const int ML2 = 11; // Motor left 2
const int SR = 6; // Sensor right
const int SL = 7; // Sensor left
const int LED = 13; // LED indicator
const int ENR = 3; // Enable pin for right motor
const int ENL = 5; // Enable pin for left motor
// Speed and timing parameters
const int VSPEED = 100; // Speed for forward and backward motion
const int TSPEED = 255; // Speed for turning
const int TDELAY = 20; // Delay for turning
void setup() {
// Initialize pin modes
pinMode(MR1, OUTPUT);
pinMode(MR2, OUTPUT);
pinMode(ML1, OUTPUT);
pinMode(ML2, OUTPUT);
pinMode(LED, OUTPUT);
pinMode(SR, INPUT);
pinMode(SL, INPUT);
delay(5000); // Delay for setup
}
void loop() {
// Read sensor values
int svr = digitalRead(SR);
int svl = digitalRead(SL);
// Determine robot behavior based on sensor values
if (svl == LOW && svr == LOW) {
forward(); // Move forward
} else if (svl == HIGH && svr == LOW) {
left(); // Turn left
} else if (svl == LOW && svr == HIGH) {
right(); // Turn right
} else if (svl == HIGH && svr == HIGH) {
stop(); // Stop
}
}
void forward() {
// Move forward by setting motor directions
digitalWrite(MR1, HIGH);
digitalWrite(MR2, LOW);
digitalWrite(ML1, HIGH);
digitalWrite(ML2, LOW);
analogWrite(ENR, VSPEED);
analogWrite(ENL, VSPEED);
}
void backward() {
// Move backward by setting motor directions
digitalWrite(MR1, LOW);
digitalWrite(MR2, HIGH);
digitalWrite(ML1, LOW);
digitalWrite(ML2, HIGH);
analogWrite(ENR, VSPEED);
analogWrite(ENL, VSPEED);
}
void right() {
// Turn right by adjusting motor speeds
digitalWrite(MR1, LOW);
digitalWrite(MR2, HIGH);
digitalWrite(ML1, HIGH);
digitalWrite(ML2, LOW);
analogWrite(ENR, TSPEED);
analogWrite(ENL, TSPEED);
delay(TDELAY);
}
void left() {
// Turn left by adjusting motor speeds
digitalWrite(MR1, HIGH);
digitalWrite(MR2, LOW);
digitalWrite(ML1, LOW);
digitalWrite(ML2, HIGH);
analogWrite(ENR, TSPEED);
analogWrite(ENL, TSPEED);
delay(TDELAY);
}
void stop() {
// Stop the robot by setting motor speeds to zero
analogWrite(ENR, 0);
analogWrite(ENL, 0);
}
- Connect the motors to the motor driver and the motor driver to the Arduino.
- Connect the infrared sensors to the designated pins on the Arduino.
- Ensure the LED is connected to pin 13 for visual feedback.
- Open the Arduino IDE.
- Copy and paste the code into a new sketch.
- Upload the code to your Arduino board.
- Place the robot on a track with a line.
- Power on the robot and observe its behavior as it follows the line.
- Adjust
VSPEED
andTSPEED
values for different speed requirements. - Modify
TDELAY
to adjust turning sensitivity.
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome! Please fork this repository and submit a pull request with your improvements.