I have a L298n Hbridge wired into an ATMega 2560. Trying to control a dc motor. I wired the hbridge as follows:
GND/CSA/CSB --> Arduino GND
Enable B --> PWM pin 5
In3/In4 --> PWM pins 6 and 7
Out3/Out4 --> Motor
VLS --> 5V on Arduino (with 100 nF capacitor in btwn)
VS --> 12V battery thru fuse box (also with 100 nF capacitor)
I've checked voltages going to the Hbridge; From the battery the Hbridge is receiving the full 12.5V, but when I move the multimeter to the "out" pins of the Hbridge, it reads 0V.
As far as I understand it you control the Hbridge with a code like this:
It's hard to say what the problem is without a clear picture of your wiring and your code.
For starters:
Did you check for loose connections?
Are you connecting what you think you are connecting? (enable B vs enable A, mixing up digital pins, ect.)
Do you have proper and correct variable initialization?
Do you have a proper setup() defining the correct pins the correct pinMode?
Is your code getting stuck in a loop somewhere?
Is your power source sufficient?
Hi, I am part of this project. Here is the code we are using:
int in1 = 6;
int in2 = 5;
int ena = 7;
void setup(){
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(ena, OUTPUT);
}
void loop(){
digitalWrite(ena, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in1, HIGH);
delay(3000);
digitalWrite(in2, LOW);
digitalWrite(in1, LOW);
delay(3000);
}
We checked another of our hbridges (we have four) and that one didn't work either. We didn't want to put any permanent connection on so we're using alligator clips...we' ve double checked that we didn't mix up pins, so we're pretty certain that isn't it.
Our power source is a 12V battery...it's certainly sufficient to drive the motors (we've done it before) and we're just using the 5V pin for the logic power.
We rewired the hbridges into breadboards and used heat shrink to reduce the likelihood of crossed wires and such and still no luck. Below is a picture of our wiring:
-Braided purple and white wires are inputs and enable. Hooked to PWM pins 5, 6, 7 (we're only testing on 1 motor currently)
-Black wires from output are going to motor
-Orange jumpers go to GND strip that is being connected to battery GND via the black wire on the end
-Capacitors for VLS and VS to Arduino 5V and battery 12V respectively
Any ideas on what's wrong? Still using previous code
Thanks for the capacitor schematic, we definitely wired that wrong. We figured it out just now though... We were not wiring the Hbridge's ground to the arduino, so the 5V pulse that was being sent was not with respect to ground...