How to make a line following with obstacle avoid robot with arduino uno?
Answers
a line following robot follows a black line about 3/4 inches in width on a black surface. these robots are usually used in compititions. according to rules, the robots are raced one at a time and the robot with the shortest time wins. the curves in the lines must be 4 inchces or more in diameter
Answer:
#define IN_11 2 // L298N #1 in 1 motor Front Right
#define IN_12 3 // L298N #1 in 2 motor Front Right
#define IN_13 4 // L298N #1 in 3 motor Back Right
#define IN_14 7 // L298N #1 in 4 motor Back Right
int command; //Int to store app command state.
int speedCar = 100; // 50 - 255.
int speed_Coeff = 4;
void setup() {
pinMode(IN_11, OUTPUT);
pinMode(IN_12, OUTPUT);
pinMode(IN_13, OUTPUT);
pinMode(IN_14, OUTPUT);
Serial.begin(9600);
}
void goAhead() {
digitalWrite(IN_11, HIGH);
digitalWrite(IN_12, LOW);
digitalWrite(IN_13, LOW);
digitalWrite(IN_14, HIGH);
}
void goBack() {
digitalWrite(IN_11, HIGH);
digitalWrite(IN_12, LOW);
digitalWrite(IN_13, LOW);
digitalWrite(IN_14, HIGH);
}
void goRight() {
digitalWrite(IN_11, LOW);
digitalWrite(IN_12, HIGH);
digitalWrite(IN_13, HIGH);
digitalWrite(IN_14, LOW);
}
void goLeft() {
digitalWrite(IN_11, HIGH);
digitalWrite(IN_12, LOW);
digitalWrite(IN_13, LOW);
digitalWrite(IN_14, HIGH);
}
void stopRobot() {
digitalWrite(IN_11, LOW);
digitalWrite(IN_12, LOW);
digitalWrite(IN_13, LOW);
digitalWrite(IN_14, LOW);
}
void loop() {
if (Serial.available() > 0) {
command = Serial.read();
stopRobot(); //Initialize with motors stopped.
switch (command) {
case 'F': goAhead(); break;
case 'B': goBack(); break;
case 'L': goLeft(); break;
case 'R': goRight(); break;
case '0': speedCar = 100; break;
case '1': speedCar = 115; break;
case '2': speedCar = 130; break;
case '3': speedCar = 145; break;
case '4': speedCar = 160; break;
case '5': speedCar = 175; break;
case '6': speedCar = 190; break;
case '7': speedCar = 205; break;
case '8': speedCar = 220; break;
case '9': speedCar = 235; break;
case 'q': speedCar = 255; break;
}
}
}
Explanation: