Dear all,
I am trying to make an arduino based four wheel small car while controlling it using L298N motor drive. Since L298N control two motors, I have connected the two right motors together to one side and the two left motors to the other side. I wanted to test the car movement with commands. I understand that I have switched the connection for one side, but it is ok I figured it out. I started coding and wanted to test the movement so I gave it the command to go forward at a time then another code for reverse, going right, and going left. They all worked great alone, but when I tried to create a code to test them all together while delaying 1 sec for each movement for some reason it just goes forward and again and again. I tried to do serial print to see if it actually run through the other functions of reverse, right, and left turns and it does. I also tried to add a "stop" command between them but it still just goes forward, stops, and again goes forward. The code created is as shown below:
#define LM_1 53//1
#define LM_2 52 //2
#define RM_1 50 //3
#define RM_2 51 //4
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LM_1, OUTPUT);
pinMode(LM_2, OUTPUT);
pinMode(RM_1, OUTPUT);
pinMode(RM_2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Stop();
Forward();
delay(1000);
Stop();
Reverse();
delay(1000);
Stop();
Left();
delay(1000);
Stop();
Right();
delay(1000);
}
void Forward(){
digitalWrite(LM_1, LOW);
digitalWrite(LM_2, HIGH);
digitalWrite(RM_1, HIGH);
digitalWrite(RM_2, LOW);
Serial.print("F");
}
void Reverse(){
digitalWrite(LM_1, HIGH);
digitalWrite(LM_2, LOW);
digitalWrite(RM_1, LOW);
digitalWrite(RM_2, HIGH);
Serial.print("R");
}
void Left(){
digitalWrite(LM_1, LOW);
digitalWrite(LM_2, HIGH);
digitalWrite(RM_1, LOW);
digitalWrite(RM_2, HIGH);
Serial.print("L");
}
void Right(){
digitalWrite(LM_1, HIGH);
digitalWrite(LM_2, LOW);
digitalWrite(RM_1, HIGH);
digitalWrite(RM_2, LOW);
Serial.print("RI");
}
void Stop(){
digitalWrite(LM_1, LOW);
digitalWrite(LM_2, LOW);
digitalWrite(RM_1, LOW);
digitalWrite(RM_2, LOW);
}
It goes through them all but never acts. Could someone please help me finding what went wrong and how to fix it. Thank you for your time and effort.
