I am working on a project where I need to control the speed of a DC Motor. I am currently using a 12V DC Motor, a L298N Motor Driver and a Sparkfun RedBoard. Below I have included the code I am using (I am just trying to see if I can have control over direction and speed) as well as images of my wiring. I am using a power supply with the shown voltage, which I assumed should work fine as it is below 12. My main problem is that when I have everything wired up as shown and I upload the code, nothing happens. My motor does not spin or hum and there seems to be no change at all. I have tested all the wires and they are all running a current fine. I have also looked online and at other posts and it seems the most common error is not connecting the L298N and Arduino Ground, but I have done that. I am very new to Arduino and electronics, so I am hoping my error is obvious to someone. Thanks in advance for any help!
int enA = 9;
int in1 = 8;
int in2 = 7;
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void loop() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(enA, 200);
delay(5000);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
analogWrite(enA, 200);
delay(2500);
}
The motor does work if connected to the power supply. I am not sure how I could test the L298. Here is a drawing of the wiring, it is pretty rudimentary and based off of a tutorial, which is why I am having trouble solving my problem. Thank you for your response.
BigALig:
My apologies in regards to the image, I'm new to this sort of stuff. Yes, both connections on the L298 fail.
I think if it was my project I would get another L298.
Even better would be to get a more modern driver that uses MOSFETs and has a lower voltage drop. The Pololu website has lots of examples and there are many similar products available from other suppliers.
Test that L298 board on it's own, without Arduino.
Put both EN jumpers on.
Connect IN1 to module ground.
And IN2 to module 5volt.
If the motor runs,
Connect IN1 to module 5volt.
And IN2 to module ground.
The motor should run in the opposite direction.
Did have another look at the pictures from post#1,
It seems OP has removed the 5volt jumper.
If so, then the logic part of the motor chip won't be powered.
Put that jumper back again, assuming your motor supply is <=12volt.
Or... give the motor driver 5volt power by connecting 5volt from the Arduino to the 5volt terminal of the driver.
Leo..
The motor is working now thanks for all of the help. The L298 came without the jumper so I never realized that it wasn't on anymore. When I connected the Arduino's 5V to the L298 it ran.