Motor_Schematic.png (104915Bytes)
I am using an arduino uno and a L298N motor driver board. I have pins IN1, IN2, IN3, IN4 connected to arduino digital pins 2, 3, 4, 5 respectivly. ENA and ENB are connected to pins 9 and 10. The code I am using works because all it is made to do is make the motors go forward. I know it's working because there are four indicator LED's that correspond with the input pins. At the start, all of them light up because I declare them as outputs. After, only pins 1 and 3 light up because I active those in the code to make it go forward. However, only one motor moves. I have tried adjusting all the shorting blocks on the board to no avail. I know the motors work because I applied voltage directly and they worked fine. Is there a problem with my code? I have a 9V connected to the motor board. I know there is about a 2V drop with this chip. That means the motors get 7V, or 3.5V each. The motors are rated at 3-6V each. I ran my code and that one motor worked. I have checked all my wiring and can't seem to figure it out. What I did find out was that the board might be bad. I switched the motors around. Meaning I put the left motor wires in the opposite screwblocks and same for the right. This made the other motor work; making me think my board is partially bad. Do you think it is? Do you think it needs more voltage? If you think the board is bad could you recommend a different one? Regardless, I was still quite happy to see just one motor going as that was the first code I ever wrote on my own. I never learned how to code I just looked at others and read the arduino libraries. It was a nice confidence boost.
I also attached the picture of the schematic in case it is too hard to see.
CODE:
// This program uses an Arduino Uno and a L298N motor driver board. It will make both motors go forward.
int fPinA = 2; // Forward for motor A (left)
int rPinA = 3; // Reverse for motor A (Left)
int toggleA = 9; // Turns motor A on/off
int fPinB = 4; // Forward for motor B (Right)
int rPinB = 5; // Reverse for motor B (Right)
int toggleB = 10; // Turns motor B on/off
void setup()
{
pinMode( fPinA, OUTPUT );
pinMode( rPinA, OUTPUT );
pinMode( toggleA, OUTPUT );
pinMode( fPinB, OUTPUT );
pinMode( rPinB, OUTPUT );
pinMode( toggleB, OUTPUT );
}
void loop()
{
digitalWrite( toggleA, HIGH ); // Turns motor A on
digitalWrite( fPinA, HIGH ); // Makes motor A go forward
digitalWrite( rPinA, LOW ); // Reverse not used
digitalWrite( toggleB, HIGH ); // Turns motor B on
digitalWrite( fPinB, HIGH ); // Makes motor B go forward
digitalWrite( rPinB, LOW ); // Reverse not used
}