Hello everyone I have been having difficulties with this project (should have been simple).
It is just a line follower program who needs to cover about 6 meters in the least amount of time possible.
It is kinda slow and after the first half of the track (it is a rectangle with gentle curves at its edges) where it needs to turn, it starts to form a path of a sine wave between the black lines.
I did indeed try google but it didn’t really help me in this instance.
I'm not in any way an experienced person with Arduino, in fact I am fairly new. Sorry for any mistakes. I thank anyone in advance who responds to this post.
Anyway here is the code:
// Pins of Motors
int vRIGHT = 5; // Velocity Motor RIGHT
int vLEFT = 6; // Velocity Motor LEFT
int dRIGHT = 7; // direction Motor RIGHT
int dLEFT = 8; // direction Motor LEFT
// Pins of the sensors
int line = 11;
int line2 = 12;
int light = A0;
int sensorLEFT;
int sensorRIGHT;
void velRIGHT(int vel)
{
if(vel >= 0) // MOTOR
{
digitalWrite(dRIGHT,HIGH);
analogWrite(vRIGHT,vel);
}
else
{
digitalWrite(dRIGHT,LOW);
analogWrite(vRIGHT,abs(vel));
}
}
void velLEFT(int vel)
{
if(vel >= 0)
{
digitalWrite(dLEFT,HIGH);
analogWrite(vLEFT,vel);
}
else
{
digitalWrite(dLEFT,LOW);
analogWrite(vLEFT,abs(vel));
}
}
void setup(void)
{
pinMode(dRIGHT, OUTPUT);
pinMode(dLEFT, OUTPUT);
pinMode(line, INPUT);
Serial.begin(9600);
Serial.println("Sensor Testing");
}
void loop(void)
{
while(analogRead(light) < 800)
{
Serial.print("Sensor light = ");
Serial.print(analogRead(light));
Serial.print(" Sensor line = ");
Serial.print(digitalRead(line));
Serial.print(" Sensor line2 = ");
Serial.println(digitalRead(line2));
}
velLEFT(255);
velRIGHT(255);
delay(600);
while(1)
{
sensorLEFT = digitalRead(line);
sensorRIGHT = digitalRead(line2);
if(sensorLEFT && sensorRIGHT) //LEFT = BLACK e RIGHT = BLACK
{
velLEFT(255); //
velRIGHT(115);//
}
if(!sensorLEFT && !sensorRIGHT) //LEFT = WHITE e RIGHT = WHITE
{
velLEFT(110);//
velRIGHT(255);//255
}
if(sensorLEFT && !sensorRIGHT) //LEFT = BLACK e RIGHT = WHITE
{
velLEFT(255);
velRIGHT(255);
}
if(!sensorLEFT && sensorRIGHT) //LEFT = WHITE e RIGHT = BLACK
{
velLEFT(0);
velRIGHT(255);
}
}
}
Sono_un_inglese_di_Londra.ino (1.77 KB)