Skip to content

Commit

Permalink
Merge pull request #1036 from deedGhost/main
Browse files Browse the repository at this point in the history
Line Follower Robot using Arduino #996
  • Loading branch information
Kushal997-das authored May 20, 2024
2 parents 0b59315 + b092496 commit f298ee0
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#define LEFT_SENSOR 3 // pin connected to the left sensor
#define RIGHT_SENSOR 4 // pin connected to the right sensor

#define Motor14 1 // pin connected to motor 1 (control pin 1)
#define Motor15 0 // pin connected to motor 1 (control pin 2)
#define Motor17 5 // pin connected to motor 2 (control pin 1)
#define Motor18 6 // pin connected to motor 2 (control pin 2)

void setup() {
// Set Timer 0 for PWM (Pulse Width Modulation) used for motor speed control
TCCR0B = TCCR0B & B11111000 | B00000010;

// Start serial communication for debugging (optional)
Serial.begin(9600);

// Set sensor pins as inputs
pinMode(LEFT_SENSOR, INPUT);
pinMode(RIGHT_SENSOR, INPUT);

// Set motor control pins as outputs
pinMode(Motor14, OUTPUT);
pinMode(Motor15, OUTPUT);
pinMode(Motor17, OUTPUT);
pinMode(Motor18, OUTPUT);
}

void loop() {
int leftSensorValue = analogRead(LEFT_SENSOR); // Read analog value from left sensor
int rightSensorValue = analogRead(RIGHT_SENSOR); // Read analog value from right sensor

// Print sensor readings for debugging (optional)
Serial.print("LEFT_SENSOR = ");
Serial.println(leftSensorValue);

Serial.print("RIGHT_SENSOR = ");
Serial.println(rightSensorValue);

// Call the rotation function to control motor movement based on sensor readings
rotation(leftSensorValue, rightSensorValue);
}

void rotation(int leftValue, int rightValue) {
// Forward (both sensors see white - high sensor readings)
if (leftValue >= 800 && rightValue >= 800) {
digitalWrite(Motor14, HIGH);
digitalWrite(Motor15, LOW);
digitalWrite(Motor17, HIGH);
digitalWrite(Motor18, LOW); // Set motors to move forward
}

// Right turn (left sensor sees black - low sensor reading, right sensor sees white)
else if (leftValue <= 800 && rightValue >= 800) {
digitalWrite(Motor14, LOW);
digitalWrite(Motor15, HIGH);
digitalWrite(Motor17, HIGH);
digitalWrite(Motor18, LOW); // Set motors to turn right
}

// Left turn (left sensor sees white, right sensor sees black)
else if (leftValue >= 800 && rightValue <= 800) {
digitalWrite(Motor14, HIGH);
digitalWrite(Motor15, LOW);
digitalWrite(Motor17, LOW);
digitalWrite(Motor18, HIGH); // Set motors to turn left
}

// Stop (both sensors see black - low sensor readings)
else {
digitalWrite(Motor14, LOW);
digitalWrite(Motor15, LOW);
digitalWrite(Motor17, LOW);
digitalWrite(Motor18, LOW); // Stop motors
delay(400); // Wait for 400 milliseconds

// Short forward movement to help escape from a centered position
digitalWrite(Motor14, HIGH);
digitalWrite(Motor15, LOW);
digitalWrite(Motor17, HIGH);
digitalWrite(Motor18, LOW); // Short forward movement
delay(400); // Wait for 400 milliseconds
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Line Follower Robot using Arduino

-> This project involves creating a line-following robot using an Arduino microcontroller.

-> The robot follows a predefined path or line on the ground using infrared sensors to detect the line and make necessary adjustments in its movement.

# Circuit Diagram
[Image](Images/circuit.png.png)

# Demonstration [Video](https://geuac-my.sharepoint.com/:v:/g/personal/21022109_geu_ac_in/EXHbhFVZHbhPhkgSunn_W1EB5jz8xyH8o5IU7j8TXhfC2Q)

# Implementation [Video](https://geuac-my.sharepoint.com/:v:/g/personal/21022109_geu_ac_in/EfzswFv9-M1Nu_r0viun3TIBGBUgg-pNA1_6fYiQuPa0tA)

1 change: 1 addition & 0 deletions IOT(Internet of Things)/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
| 13. | [Arduino PIR Motion Sensor](https://github.com/Kushal997-das/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Arduino_PIR_Motion_Sensor) | 14. | [Arduino RGB Mixing](https://github.com/Kushal997-das/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Arduino_RGB_Mixing)| 15. | [Arduino Serial Monitor](https://github.com/Kushal997-das/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Arduino_Serial_Monitor)
| 16. | [Arduino Servo Motor](https://github.com/Kushal997-das/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Arduino_Servo_Motor) | 17. | [Arduino Stress Sensor](https://github.com/Kushal997-das/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Arduino_Stress_Sensor) | 18. | [Arduino Temperature Sensor](https://github.com/Kushal997-das/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Arduino_Temperature_Sensor)
| 19. | [Arduino Traffic Light Simulator](https://github.com/Kushal997-das/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Arduino_TrafficLight_Simulator) | 20. | [Arduino UltraSonic Sensor](https://github.com/Kushal997-das/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Arduino_UltraSonic_Sensor) | 21. | [Multi Arduino Knight Rider Lights](https://github.com/Kushal997-das/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Multi%20Arduino%20Knight%20Rider%20Lights)
| 22. | [Arduino_Line_Follower_Robot](https://github.com/deedGhost/Project-Guidance/tree/main/IOT(Internet%20of%20Things)/Basic/Arduino_Line_Follower_Robot)

## Level 2: Intermediate 🚀

Expand Down

0 comments on commit f298ee0

Please sign in to comment.