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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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.

Comments

drinkypoo (author)2015-12-21

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

gearsngenes (author)drinkypoo2015-12-21

Yes... you are correct. You could.

But Adafruit's protrinket that is used here is not expensive either. It is $10.

https://www.adafruit.com/products/2000

vinz3nt (author)gearsngenes2015-12-29

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.

gearsngenes (author)vinz3nt2015-12-30

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

Dimitris Platis (author)2015-12-20

"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.

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!!

:)

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

Dave P (author)2015-12-22

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

mzbas (author)2015-12-21

does this particular H-Bridge have current protection?

gearsngenes (author)mzbas2015-12-21

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

noecus (author)2015-12-20

very useful, thanks for sharing

number 1 usher (author)2015-12-19

can I use an adafruit TB6612

Yes. TB66 12fng is the full name.

dgateley (author)2015-12-10

And the motor connects how?

bcraun (author)dgateley2015-12-10

Mot+ <--> AO1

Mot- <--> AO2

--or--

Mot+ <--> AO2

Mot- <--> AO1

gearsngenes (author)bcraun2015-12-13

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

gearsngenes (author)bcraun2015-12-11

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

NathanG13 (author)2015-12-08

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

gearsngenes (author)NathanG132015-12-11

Thank YOU.

xavidua (author)2015-12-10

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

t.rohner (author)xavidua2015-12-11

Hi

For a scooter, you don't need a H-bridge. (You don't need a reverse...)

Your scooter motor might be in the range of 250-500W this gives a current of 11-22 A @ 24V. This can be done with a single Mosfet with a low RDSon.

xavidua (author)t.rohner2015-12-11

I do not understand electronics. My home is built scooter speed controller board but has no reverse and necessary. what can I do?

t.rohner (author)xavidua2015-12-11

If you don't understand electronics, it's probably the best, if you buy a speed controller.

Something like this:

http://www.dx.com/p/maitech-ccm6dw-dc-motor-speed-controller-325731#.Vmrgq140-uQ

xavidua (author)t.rohner2015-12-11

I need reverse....

t.rohner (author)xavidua2015-12-11

This can easily be done with such a switch.

http://www.dx.com/p/6-pin-on-on-toggle-switches-orange-ac-250v-2-pcs-163273#.Vmr7tF40-uQ

xavidua (author)t.rohner2015-12-11

These switches I've used. very hot and melt.

bcraun (author)xavidua2015-12-10

Not with the TB66. The DRV8801 can drive a single motor 8-36V @ 1A continuous.

keithisit (author)2015-12-11

Really cool! Not a difficult circuit to build but very useful and practical.

kooth (author)2015-12-08

Very nicely done! Thanks for sharing!