Hi,
I am making a vehicle in class that is suppose to travel across a two-walled course, and cross a black finish line. I am having trouble figuring out what I am suppose to code for the line follower to work. Basically, once the vehicle crosses the black finish line, the vehicle is suppose to stop. My vehicle runs, but it doesn't stop when it senses a black line, and so I'm wondering how to code this or what to use?
Thank you for your time.
int rightmotor = 5; //pin5
int leftmotor = 6; //pin6
int rightbumper = 7; //pin7
int leftbumper = 8; //pin8
int linefollower = 0;
int increasespeed = 30;
int speed1 = 150; //left motor
int speed2 = 150; //right motor
int switchstate1; //left
int switchstate2; //right
void setup() {
Serial.begin(9600);
pinMode(leftmotor, OUTPUT);
pinMode(rightmotor, OUTPUT);
pinMode(leftbumper, INPUT);
pinMode(rightbumper, INPUT);
}
void loop(){
linefollower = analogRead(A0); //this is the part i need help with
Serial.println(linefollower); //this is the part i need help with
analogWrite(leftmotor, speed1);
analogWrite(rightmotor, speed2);
switchstate1 = digitalRead(leftbumper);
switchstate2 = digitalRead(rightbumper);
if(switchstate1 == HIGH && switchstate2 == HIGH){
speed1;
speed2;}
if(switchstate1 == HIGH && switchstate2 == LOW){
speed1 = speed1 + increasespeed;
speed2 = speed2 - increasespeed;
}
if(switchstate1 == LOW && switchstate2 == HIGH){
speed1 = speed1 - increasespeed;
speed2 = speed2 + increasespeed;
}
}