-
-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1036 from deedGhost/main
Line Follower Robot using Arduino #996
- Loading branch information
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+15.5 MB
...uino_line_follower_robot - Tinkercad - Personal - Microsoft Edge 2024-05-15 23-03-21.mp4
Binary file not shown.
Binary file added
BIN
+56.2 KB
IOT(Internet of Things)/Basic/Arduino_Line_Follower_Robot/Images/circuit.png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+574 KB
IOT(Internet of Things)/Basic/Arduino_Line_Follower_Robot/Images/robo.png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions
82
IOT(Internet of Things)/Basic/Arduino_Line_Follower_Robot/code.ino/code.ino.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
IOT(Internet of Things)/Basic/Arduino_Line_Follower_Robot/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters