Hey everyone,
I am trying to use the L298N H-Bridge, but I have a few problems with it..
Whenever I connect a battery (either 11.1V LiPo, 9V, or any other power source, and share ground with the Arduino) the PWM voltage produced by the H Bridge is always too high.
Doesn’t matter whether it has load (and doesn’t matter what load), or with no load at all.
I check the output voltage using a multimeter, between the two output terminals.I also tried to connect several loads (for example a motor, and to control its speed) to make sure it is not just false-readings - and the readings are correct.
This is the code I am using, nothing special:
const int PWM = 6, A = 4, B = 5;
void setup() {
pinMode(PWM, OUTPUT);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
}
void loop() {
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
analogWrite(PWM, 1);
}
When I write analogWrite(255), it gives the battery voltage (minus H Bridge voltage drop, understandable) and when I write analogWrite(0) - 0 volts of course.
But anything in between, makes absolutely no sense.
For example, using a fully charged 9V battery and analogWrite(1) I get a reading of 5V, and for analogWrite(50) I get around 6V. It is not proportional to anything. Same behaviour with the 11.1V LiPo battery, and any other power-source I’ve tried.
At first I thought it is a ground-sharing problem, but I do share the ground between the H-Bridge and the Arduino. (and I know it works, because I get different readings without it)
I tried several H-Bridge and I always got the same result.
I also compared my setup with this tutorial, and everything is as it should be.
The H-Bridge module I am using is the exact one like in the tutorial.
However, when I “trigger” PWM pulses manually like the following code (and short the enable pin on the H-Bridge of course), it does work:
const int A = 4, B = 5;
void setup() {
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
}
int pwm = 100;
void loop() {
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
delayMicroseconds(pwm);
digitalWrite(A, LOW);
digitalWrite(B, LOW);
delayMicroseconds(1000 - pwm);
}
This works perfectly fine, but the above code, using analogWrite doesn’t work whatsoever.
I also tried to power the H-Bridge using the 5V (taking out the voltage regulator jumper, and using 5V to power the H-Bridge) - same result.
Example setup schematic:
I can’t figure out what I’m missing..
Any ideas? What else can I try to check?
Thanks in advance!
(p.s. I asked about it a couple of weeks ago but I didn’t explain myself well and the topic shifted to different things, so I’m asking it again, and simplified)