Home   RSS Feed
code coding coders

Content

29 May 2009
L298 Hbridge meets Arduino mega

Filed under Sketch

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 power

pinMode(6, INPUT); // this simulates the two power pins on
pinMode(7, INPUT); // the electric motor, like a virtual motor

pinMode(14, OUTPUT); //logic signal 1
pinMode(15, OUTPUT); //logic signal 2
pinMode(18, OUTPUT); // enable hbridge

digitalWrite(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
}

A better than nothing picture of testing the L298 on an arduino mega

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

L298 HBridge and arduino wiring

VN:F [1.3.2_665]
Rating: 10.0/10 (1 vote cast)
  • Share/Save/Bookmark

2009-05-29  ::  Andrew

Talkback x 8

  1. JDesign
    26 September 2009 @ 1:47 pm

    Hi!
    it seems that you got it working ? Im having a hard time to connect all the wires, do you got a wiring diagram?

    best regards

    VA:F [1.3.2_665]
    Rating: 0.0/5 (0 votes cast)

    [Reply]

    Andrew Reply:

    Yes I got it working, took me a while to get it going too. Unfortunately I didn’t think to make a wiring diagram at the time, and now the project is disassembled waiting to be made into a new project. I’ll try to piece together my memories with the bits of code and pictures to make up a diagram for you. Should get it done today or tomorrow.

    VN:F [1.3.2_665]
    Rating: 0.0/5 (0 votes cast)

    [Reply]

  2. JDesign
    26 September 2009 @ 3:01 pm

    ah, thanks!

    VA:F [1.3.2_665]
    Rating: 0.0/5 (0 votes cast)

    [Reply]

    Andrew Reply:

    I’ve uploaded a wiring diagram, looking back on it there’s room to improve, but it does work. If you have any more questions feel free to ask.

    VN:F [1.3.2_665]
    Rating: 0.0/5 (0 votes cast)

    [Reply]

  3. JDesign
    26 September 2009 @ 6:15 pm

    WOW, great!
    thanks alot! the two white blocks in your photo, what are they for?

    VA:F [1.3.2_665]
    Rating: 0.0/5 (0 votes cast)

    [Reply]

  4. JDesign
    26 September 2009 @ 7:40 pm

    hm, I think I need some help, agian :) ( noob :) )
    I’m using a noname (ebay) bipolar stepper motor with four wires. iv’e checked all the wires with a multimeter, and found two pair that belongs together. where should they go? my first guess was, the first coil, wire1 to out 1, and wire2 to out2 and the second coil ,to out3 and 4. but this was obviously wrong.

    VA:F [1.3.2_665]
    Rating: 0.0/5 (0 votes cast)

    [Reply]

    Andrew Reply:

    The small block is the Hbridge and the larger one is the arduino board, as seen in the picture.

    I’ve never worked with stepper motors before, so there’s not much advice I can give. From what I can gather, you should determine if it is unipolar or bipolar then check the arduino examples for help. The examples seem to have a different model bridge, but you should be able to identify what goes where by looking at the datasheet of the one you have.

    Arduino uniploar example
    Arduino bipolar example

    I’m not sure how much help this is, but I hope it’s at least a little bit useful.

    VN:F [1.3.2_665]
    Rating: 0.0/5 (0 votes cast)

    [Reply]

  5. FOB Controlled H-Bridge Motor with Arduino | The Inner Qube
    12 March 2010 @ 2:56 pm

    [...] http://robot-overlord.blogspot.com/2009/06/controlling-dc-motor-using-arduino-usb.html http://software.o-o.ro/l298-hbridge-meets-arduino-mega/ http://electronics.divinechildhighschool.org/Home/Arduino-Lessons/h-bridge [...]

Share your thoughts







Tags you can use (optional):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>