MOTORS BASICS (Finally!): HOW TO USE AN H BRIDGE

55,231

640

29

Introduction: MOTORS BASICS (Finally!): HOW TO USE AN H BRIDGE

Hello, followers and makers alike. It's been a while and I haven't posted much. BUT...I now have something to discuss with all of you. Motors. They are very useful, but what would make them more effective is if we knew how to make them change direction without touching the wiring. How would we go about doing that? Hm....

PS: IF YOU DO NOT HAVE ANY EXPERIENCE FROM PREVIOUS LESSONS, PLEASE, PRETTY PLEASE SEE THEM NOW!!!!!!!!!!!!!!! Thank you. <3

Step 1: MEET THE H-BRIDGE

This bizarre chip is called an h-bridge. H-bridges come in all sorts of sizes and capabilities. But for the time being, lets stick with this basic version called the TB66. This chip can drive two mediocre sized motors simultaneously, but all we will be focusing on at the time is how to control 1 motor.

As you can see, there are many pins you might not be familiar with. Do not worry. We will dissect and understand this chip so that way you can access all of its capabilities.

Step 2: The Powers and Grounds

Like most projects we have worked with, the TB66 has powers and grounds. To begin your understanding of the infamous TB66, lets see how we use these terminals.

First, you need a ground and 5v power (top left). These will be used for logic power, or power for the actual chip controlling the circuit.

Then you need a second ground and a power terminal that hooks up to a battery (bottom left). These are what will be used to power your motors, when they are actually turning. For the battery you need to use, I have found that using one 9v battery or six AA batteries are the most preferable when using this H-bridge.

Then there is the manual switch (right, middle) and a ground. What the manual switch allows you to do is force your circuit to turn off, not allowing the motors to move unless the Manual switch gets 5V. Since the circuit that we will be focussing on does not require this, we will supply 5v to the man. switch.

Step 3: Inputs and Outputs

The pins you see labeled above are what will be controlling how your motors (in this case, only one) move.

PWMA is the pin that, depending on how much signal you send to it, indirectly controls how fast your motors move. For instance, if one sends 3.3 v (2/3 of 5v) to PWMA, then the motors will move to the extent that fraction of the battery's voltage (9v), which would be around 6v.

Ain1 and Ain2 are the inputs, from the arduino**, control the direction of the motor. When using them in code, one of these inputs have to be written as LOW, and the other HIGH* when telling the motor to move. However, when telling the motor to stop, both inputs have to be LOW. These inputs don't actually send power to the motors (it wouldn't be enough) but rather represent which terminal on the motor is power and ground.

Ao1 and Ao2 are the pins that you will connect your motors terminals to. These are outputs that send the power from the battery. The way that the power is given to a motor depends on how the Ain1 and 2 are told to be. If Ain1 is LOW, then Ao1 is LOW and the same holds true for Ain2 and Ao2. Again, one output has to be LOW while the other is HIGH in order for the motor to move.

*BAD JOKE ALERT: High on ELECTRICITY!

**Arduino: the chip we will be using to control the TB66

Step 4: Which Pins Correspond to Which?

Here is another way one can view the way that these input pins and output pins interact, inspired by bcraun:

Motor Pin-------------------OUTPUT------------------INPUT--------------------Arduino Pin

Motor Terminal+---------------AO1-----------------------AIN1--------------------------Pin 3

Motor Terminal - ---------------AO2-----------------------AIN2--------------------------Pin 4

OR


Motor Pin-------------------OUTPUT------------------INPUT--------------------Arduino Pin

Motor Terminal- ---------------AO1-----------------------AIN1--------------------------Pin 3

Motor Terminal + --------------AO2-----------------------AIN2--------------------------Pin 4

See bcraun's account @:

https://www.instructables.com/member/bcraun

Step 5: Corresponding Pins on the Arduino

Those familiar with my previous lessons know that the microcontroller we use is an arduino called pro Trinket (5v version).

This is the device that we will be programming and controlling the motors with. On the diagram above, I have labeled the pins on the arduino that correspond with the pins on the TB66.

Take your time in observing and noting. For our Inputs, we will be using pins 3, 4, 5.

It is now time to start constructing our circuit.

Step 6: The Parts Needed

To start constructing your circuit, you will need the following:

-One fully charged 9v battery

-One TB66

-One Pro trinket (5v version!!!)

-Wires to connect your parts together with

Done? Yeesh, you're fast! Lets start working.

Step 7: Connect the Powers

First things first, connect the essential grounds and powers. One thing to keep in mind, and this is very important:

CONNECT ALL THE GROUNDS TO A COMMON GROUND (as seen above), OR YOU WON'T HAVE A COMPLETE CIRCUIT!!

But don't connect powers of different voltages (ex. the 5v pin and Battery pin), or else you are going to be Mr. (or Ms.) Cranky.

Like seen in previous diagrams, connect the manual switch and 5v pins to the 5v pin to the arduino.

As mentioned earlier, connect all grounds to a common ground, including the ground terminal of the battery and the ground pin of the arduino.

Connect the battery's power to the associated pin. In real life, that pin will be labeled asVmot.

Step 8: Connect the Inputs and Outputs

Connect the arduino controls as followed:

Pins 3 and 4 on the arduinowill act as our pins to connect to Ain1 and Ain2, respectively.

Pin 5 on the arduino will act as our PWMA. The speed you want your motors to be able to move at is completely your own decision.

And for the last step, connect your motor's terminals (ground and power) to Ao1 and Ao2, which will change relative to the inputs. The way you connect your motors terminals to the outputs does not matter, as long as those outputs correspond to the correct inputs.

And there you have it. You have successfully finished your own H-Bridge circuit! Welcome to the beginning of basic robotics!

Step 9: Writing the Code

For my fellow viewers and followers, we all know that in order to get the circuit to actually do anything, we have to code the circuit to do something.

Those who do not know how to do basic coding, click on the following link to see how to code an LED to blink:

https://www.instructables.com/id/Lesson-4-Basic-Ard...

For those who are curious for the code now...it's down below. Please read the built in comments to help your understanding.

Beginining

void setup() {

pinMode(3, OUTPUT); //This is our AIN 1

pinMode(4, OUTPUT); //This is our AIN2

pinMode(5, OUTPUT); //This is our PWMA

}

void loop() {

digitalWrite(3, HIGH); // If you change this to LOW, then change the line below to HIGH

digitalWrite(4, LOW); //

analogWrite(5, 100); // *

}

END.

*When you say analogWrite in arduino, you are giving an integer of 0 to 255 after the coma. Divide this number by 255, and you get the fraction of the battery you are using to power your motors. In this case, 100/255 is roughly .39, or 39% of the battery's voltage will be sent to the motors. So if you are using a 9 V battery, 3.52 V will be used.

Feel free to experiment with the code and manipulate the speed of the motor.

Step 10: For Other Tutorials

For those curious in continuing, I have made tutorials on building professional robots requiring the TB66 circuitry. Code for these codes can be found on my github account under Gears n' Genes. Please do not feel afraid to check them out and make your own code and creations.

Check it out here:

https://github.com/gearsngenes/IRDriven2WheelRobot

Don't forget to favorite this instructables and follow me for more lessons to inspire yourself to make creative projects.

Be the First to Share

    Recommendations

    • Toys & Games Contest

      Toys & Games Contest
    • Big vs Small Challenge

      Big vs Small Challenge
    • Fix It Challenge

      Fix It Challenge

    29 Comments

    0
    drinkypoo
    drinkypoo

    5 years ago

    You can get a nano 3.0 cheaper, same chip :)

    0
    vinz3nt
    vinz3nt

    Reply 5 years ago

    nano 3.0 can be bought on ebay or aliexpress for . € 2 or even less. That's 5 times cheaper,quite a difference. H bridges can be bought from around € 1 for a dual one.

    0
    gearsngenes
    gearsngenes

    Reply 5 years ago

    That's true; it is the same Atmega 328 chip... The prices are falling down as we speak:-) great time for makers...

    0
    Dimitris Platis
    Dimitris Platis

    5 years ago

    "What the manual switch allows you to do is force your circuit to turn off, not allowing the motors to move unless the Manual switch gets 5V."

    Hmmm, does that imply that the motors are "locked", meaning that they will be dynamically breaking? If not, maybe "not moving the motors" or something like that would be more accurate instead.

    0
    gearsngenes
    gearsngenes

    Reply 5 years ago

    Fair point, what I meant to say is that the "manual switch" cuts off power to the motors, causing them to stop from no power going through them, not "locking" them in place. Thanks for the critique. Keep up the analysis!!

    :)

    0
    Dimitris Platis
    Dimitris Platis

    Reply 5 years ago

    Keep up the good work with more nice tutorials! :D

    0
    Dave P
    Dave P

    5 years ago

    Building a robot mower from a Jazzy mobility chair, going to use

    Sabertooth Dual 60A 6V-30V Regenerative Motor Driver

    since this is my first project I did a lot of research and found this is the H- Bridge it will need to handle the job

    sabertooth-dual-motor-driver.html?product-code=RB-Dim-44

    Jazzy.jpg
    0
    mzbas
    mzbas

    5 years ago

    does this particular H-Bridge have current protection?

    0
    gearsngenes
    gearsngenes

    Reply 5 years ago

    Dont believe so. Max current 3A, continuous 1A per channel (motor). Most hobby motors and servo motors would be fine. See below for details on specs.

    https://www.pololu.com/product/713

    0
    noecus
    noecus

    5 years ago

    very useful, thanks for sharing

    0
    number 1 usher
    number 1 usher

    5 years ago

    can I use an adafruit TB6612

    0
    gearsngenes
    gearsngenes

    Reply 5 years ago

    Yes. TB66 12fng is the full name.

    0
    dgateley
    dgateley

    5 years ago

    And the motor connects how?

    0
    bcraun
    bcraun

    Reply 5 years ago

    Mot+ <--> AO1

    Mot- <--> AO2

    --or--

    Mot+ <--> AO2

    Mot- <--> AO1

    0
    gearsngenes
    gearsngenes

    Reply 5 years ago

    Dude, got your chart in the edition. See if you like it. I added in INPUT and OUTPUT connections too.

    0
    gearsngenes
    gearsngenes

    Reply 5 years ago

    LOVE the arrangement of data! I should probably add that into the instructables. THANKS BCRAUN!

    0
    NathanG13
    NathanG13

    5 years ago

    Excellent information. Thanks for writing this up. Helped me get started.

    0
    gearsngenes
    gearsngenes

    Reply 5 years ago

    Thank YOU.

    0
    xavidua
    xavidua

    5 years ago

    it's possible work at 24V? I need to my Electric scooter