Hi i'am a newbie when I comes to the arduino.For some reason the motors won't turn on when connected to the L298n. I'am wondering if it is a problem with the way I wired the controller and the arduino(Battery pack is in breadboard, motor controller and arduino is powered by breadboard) or my code.
Code:
//Motor A
int enA=9;
int in1=8;
int in2=7;
//Motor B
int enB=3;
int in3=5;
int in4=4;
void loop() {
//Turn on motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA,200);
//Turn on motor B
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
analogWrite(enA,200);
delay(2000);
Hi, Not sure about your particular L298N module. Can you point to a photo? On the ones I use there is a small white button:
---------------------( COPY )---------------------
NOTE! There is a small white button switch next to the blue power terminal board. SIGH! Some need to be UP and some need to be DOWN to power the motor driver. After you plug in the battery cable, look for a red led on the motor driver. Push the switch to the position where an led lights up. NOTE: You can also use the switch to turn the motors off temporarily to upload a new sketch.
-----------------( END COPY )----------------------
Exactly what sort of 9V battery? If it's one of those rectangular PP3 types then that's your answer. They will not provide nearly enough current to run motors.
And connecting relatively high power things like motors via a breadboard is also a bad idea. Many breadboards can only tolerate very low currents.
Please provide full details of all the hardware (at least as much info as you have!).
You've not yet said what motors are involved, we have no idea at all if they are suitable for an L298
in the first place. We can only go by the information you post...
tawfeeq:
Yes it's a rectangular pp3, So i'am guessing that I need a new power source or should i try not using the bread board?
Try 6 x AA cells in a holder or a 9V power supply with at least 2A. The Arduino can be powered via the breadboard but the 9V should also ideally be connected directly to the motor driver board's terminals.