I am an arduino noob and I have made a line follower robot using arduino uno, Motor 3-6V TT DC with 4 motors and 5 IR sensors in the front and L298N shield. The motors seem to be working fine although, the right wheel stops pretty frequently and the sensors only light up when encountering the black line instead of also turning or following the black line. Sometimes the sensors picked up the line but turned the wrong direction
This is the code I made that seemed to work the best, still not following the line and the motors stopping here and there.
void ____readsensors();
void ____controlmotor();
void ____error();
double ___SA0;
double ___SA1;
double ___SA2;
double ___SA3;
double ___SA4;
double ___error;
double ___Senzors;
int _output_MotorRight2 = 5;
int _input_SA1 = A1;
int _input_SA0 = A0;
int _input_SA3 = A3;
int _input_SA2 = A2;
int _input_SA4 = A4;
int _output_MotorRight1 = 4;
int _output_SpeedMotorRight = 10;
int _led_L = 13;
int _output_MotorLeft2 = 7;
int _output_MotorLeft1 = 6;
int _output_SpeedMotorLeft = 9;
void ____citestesenzori() {
___SA0 = analogRead(_input_SA0);
___SA1 = analogRead(_input_SA1);
___SA2 = analogRead(_input_SA4);
___SA3 = analogRead(_input_SA3);
___SA4 = analogRead(_input_SA4);
}
void ____controlmotor() {
digitalWrite(_output_MotorRight1, (int)1);
digitalWrite(_output_MotorRight2, (int)0);
digitalWrite(_output_MotorLeft1, (int)0);
digitalWrite(_output_MotorLeft2, (int)1);
if ( ___error == 0 ) {
analogWrite(_output_SpeedMotorRight, (int)80);
analogWrite(_output_SpeedMotorLeft, (int)80);
} else {
if ( ___error == 1 ) {
analogWrite(_output_SpeedMotorRight, (int)0);
analogWrite(_output_SpeedMotorLeft, (int)80);
} else {
if ( ___error == -1 ) {
analogWrite(_output_SpeedMotorDrept, (int)80);
analogWrite(_output_SpeedMotorStang, (int)0);
}
}
}
}
void ____errors() {
if ( ___SA2 < 400 ) {
___error = 0;
} else {
if ( ( ___SA0 < 400 ) || ( ___SA1 < 400 ) ) {
___error = 1;
} else {
if ( ( ___SA3 < 400 ) || ( ___SA4 < 400 ) ) {
___error = -1;
}
}
}
}
void setup()
{
Serial.begin(9600);
pinMode(_output_MotorRight2, OUTPUT);
pinMode(_input_SA1, INPUT);
pinMode(_input_SA0, INPUT);
pinMode(_input_SA3, INPUT);
pinMode(_input_SA2, INPUT);
pinMode(_input_SA4, INPUT);
pinMode(_output_MotorRight1, OUTPUT);
pinMode(_output_SpeedMotorRight, OUTPUT);
pinMode(_led_L, OUTPUT);
pinMode(_output_MotorLeft2, OUTPUT);
pinMode(_output_MotorLeft1, OUTPUT);
pinMode(_output_SpeedMotorLeft, OUTPUT);
___SA0 = 0;
___SA1 = 0;
___SA2 = 0;
___SA3 = 0;
___SA4 = 0;
___Ajustare = 0;
___Senzori = 5;
}
void loop()
{
____readsensors();
____errors();
____controlmotor();
Serial.println(___SA0);
Serial.println(___SA1);
Serial.println(___SA2);
Serial.println(___SA3);
Serial.println(___SA4);
Serial.println("");
delay(10);
}
I would love any help with this, thank you so much!



