Hey everyone, been tyring to make a robo-car for a while and at the moment I'm struggling. Actually I have 2 problems:
-
When I plug in the arduino(start providing current) , 2 left side wheels are rotating forward and stoping constantly, that takes approximately 6 seconds. Only after that it starts to do whatever in the code is written. It happens only when it gets the current for the first time , for example if don't plug the cable out and re-upload the code everything goes normal.
-
I can't change the speed of the rotating. I watched couple tutorials and learned that I can change the speed of rotation by using pins ENA and ENB(on the photos marked light blue). I don't even know how to call those things that cover the ENA and ENB(If you know, please tell me). So, in order to change the speed of the wheels i have to remove the cover and connect the wires into those places. The problem is- if I do that the car doesn't move at all( no matter the speed(0-255) I set ).
I'm using An arduino Mega 2560 and a L298N Bridge
Wires are connected:
(Arduino <-> L298N)
5V <-> +12V
GND <-> GND
13(PWM) <-> IN1
12(PWM) <-> IN2
11(PWM) <-> IN3
10(PWM) <-> IN4
3(PWM) <-> ENA
4(PWM) <-> ENB
P.S. Sorry for the mess, the wires are too long, but they don't get stuck in the wheels, of course I'll have to make them shorter.
Photos:
And the code:
void setup() {
pinMode(3,OUTPUT); //ENA
pinMode(4,OUTPUT); //ENB
pinMode(13,OUTPUT); //left motors forward
pinMode(12,OUTPUT); //left motors reverse
pinMode(11,OUTPUT); //right motors forward
pinMode(10,OUTPUT); //right motors reverse
Serial.begin(9600);
}
void loop() {
analogWrite(3 , 100); //Setting speed to 100
analogWrite(4 , 255); //Setting speed to 100
digitalWrite(13,HIGH);
digitalWrite(12,LOW); //Going Forward
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
delay(1000);
digitalWrite(13,LOW);
digitalWrite(12,HIGH); //Going Backward
digitalWrite(11,LOW);
digitalWrite(10,HIGH);
delay(1000);
}
