I’ve recently purchased a L298 Hbridge to help me help arduino help a remote controlled car think by itself and move.
Does it work? Why not test it I said to myself. Play around with low voltages, see if I can get it to switch polarities.
After some trying and testing, or just trial and error, as the datasheet didn’t help much or I just missed where it mentioned, I’ve figured out I need to disable the bridge every time I switch polarities.
Since code and pictures speak louder than words allow me to show just what I did:
void setup() {
Serial.begin(9600); // go go serial powerpinMode(6, INPUT); // this simulates the two power pins on
pinMode(7, INPUT); // the electric motor, like a virtual motorpinMode(14, OUTPUT); //logic signal 1
pinMode(15, OUTPUT); //logic signal 2
pinMode(18, OUTPUT); // enable hbridgedigitalWrite(18,LOW); //turn off
digitalWrite(14,HIGH); //send signal1
digitalWrite(15,HIGH); //send signal2
digitalWrite(18,HIGH); //turn on
Serial.println(digitalRead(6)); //get output
Serial.println(digitalRead(7));
Serial.println();digitalWrite(18,LOW); //turn off
digitalWrite(14,HIGH); //send signal1
digitalWrite(15,LOW); //send signal2
digitalWrite(18,HIGH); //turn on
Serial.println(digitalRead(6)); //get output
Serial.println(digitalRead(7));
Serial.println();digitalWrite(18,LOW); //turn off
digitalWrite(14,LOW); //send signal1
digitalWrite(15,HIGH); //send signal2
digitalWrite(18,HIGH); //turn on
Serial.println(digitalRead(6)); //get output
Serial.println(digitalRead(7));
Serial.println();digitalWrite(18,LOW); //turn off
digitalWrite(14,LOW); //send signal1
digitalWrite(15,LOW); //send signal2
digitalWrite(18,HIGH); //turn on
Serial.println(digitalRead(6)); //get output
Serial.println(digitalRead(7));
Serial.println();
}void loop() {
// Please use common sense when trying ‘internet code’.
// I refuse to be held accountable for any
// damages this code may or may not cause.
// Shameless and removable author webpage inclusion:
// http://software.o-o.ro
}

L298 and arduino mega
And the lovely output:
1
1
0
1
1
0
0
0
The wiring in this example is rather poorly made, I can think of better ways to do it now, but it works. Here’s a graphical representation of the connections, done with the aid of fritzing.

L298 HBridge and arduino wiring
Was this useful at all?
L298 Hbridge meets Arduino mega,
Pingback: FOB Controlled H-Bridge Motor with Arduino | The Inner Qube
Pingback: Controlling your trains with an Arduino « modelrail.otenko
Pingback: Ardunio L298 motor control | Software