Username:    Password: Remember me
Build a 5A H-bridge motor driver
By Ibrahim Kamal
Last update: 6/6/08


This H-bridge is easy to build, without any critical components. It is based on the famous and cheap TIP122 and TIP127 power transistors. It have been used on many of our robots and proved to be very versatile and robust.

Another major advantage is that it only needs 4 wires for 12V power supply and direction control. Nevertheless, it allows bidirectional control, breaking and freewheeling.

1.The hardware
The schematic can seem a little complicated at the first sight, but, practically, it only consists of 2 logic ICs and a bunch of transistors.

figure 1.a

Q1, Q2, Q3 and Q4 are 2N2222 BJT. They can be replaced with any generic switching transistor.

Resistors R2, R4, R5 and R10 have to be 1 WATT rated, to support high currents, especially if a 24V power supply is used.

The wire connection W1 to W4 are the wires between this H-bridge module and the controller board that provides the 12/24V power supply and the logic signals for direction control.

The wire connection W3 can be connected to a power source from 10V to 24V, without circuit modifications.

The wire connection W1 and W2 are for connecting the H-bridge to a microcontroller or another logic device allowing the control of the motor. A truth table is given below showing the effect of every combination of the logic states of W1 and W2:


Inputs
Result on the connected motor
W1
W2
0
0
Motor is freewheeling (disconnected, High impendence)
0
1
Turn the motor clockwise
1
0
Turn the motor anti-clockwise
1
1
breaking the motor
*(X mean Don't care), 1 = Logic high Voltage (5V), 0 = Logic low voltage (0V).

Diodes D2 to D4 are simple rectifier diodes, with forward current ratings of at least 4A.

LED D1 is only used to signal the presence of power in the circuit.

The whole is assembled in a 5cm X 5cm PCB like in the picture below (figure 1.b). The length of the cable is not critical, it can be up to 1 meter, assuming you're PWM frequency is below 50 KHz. Heatsinks can be added to protect the TIP transistors from overheating. Be careful, the metallic back of the TIP is internally connected the collector, so be careful not to cause short circuits.

Actually, as you can see in figure 1.b, each pair of TIP122 and TIP127 share the same heatsink, without any risk of short circuits, since their collectors are already connected together in the circuit (If the schematic in figure 1.a, Q5 and Q6 have their collector connected together, as well as Q7 and Q8).

figure 1.b


2. Associated motor control algorithm
Here are some example C source codes showing how to control a motor using this H-bridge. The source codes are written for 8051 micro controller under the KEIL IDE, but can be easily modified for any other kind of microcontrollers or compiler.

This first example shows a function that control the direction/state of the motor, without speed variation.
#define w1 P1_0
#define w2 P1_1
#define motor_free 0
#define motor_break 1
#define motor_clockwise 2
#define motor_anti_clockwise 3

drive_motor(state){
   if (state == motor_free){
      w1 = 0;
      w2 = 0;
   }else if(state == motor_break){
      w1 = 1;
      w2 = 1;
   }else if(state == motor_clockwise){
      w1 = 1;
      w2 = 0;
   }else if(state == motor_anti_clockwise){
      w1 = 0;
      w2 = 1;
   }
}


The above function can then be called anytime in your program to change the state of the motor as in the example below:

drive_motor(motor_clockwise); //turn clockwise


The same function can be used in a more complicated code that controls the speed (or breaking torque) of a motor via PWM signals (for more information about PWM signals and speed control, check this article). The following example shows how to use this h-bridge with speed variations via PWM:

//global variables
unsigned char pwm_counter;
//used to count from 0 to max_pwm
unsigned char max_pwm = 100;
//this controls the period of one complete cycle
unsigned char pwm = 50;
//this controls the duty cycle.

void main(){
    while(1){
        pwm_counter++
        if (pwm_counter > max_pwm){ pwm_counter = 0; }
        if (pwm_counter < pwm){
//ON cycle
              drive_motor(motor_clockwise);
//turn clockwise
        }else{
//OFF cycle
              drive_motor(motor_free);
//motor freewheeling
        }
    }
}


The above example drives a motor with a 50% duty cycle PWM signal. It can be integrated in any program without causing any delays or disturbance the other functions.

You can download the PCB and the schematic for that h-bridge though the link below:

Download the zip file for the project.
Containing the full schematic and the PCB designs.
[note: i use ExpressPCB(FREEWARE) to design the schematics and the PCB]



I hope this article was useful. Any comments and further questions are welcome in the forum below.

Discussion (Last 15 posts preview...)
Preview of the last 15 messages discussing this page. Messages are sorted from the newest to the oldest.
Posted by:
saqib053
on: 29 Jul 2010
Re: 5A H-Bridge motor controllers
['Quote ]
@ Poncho Magilakutti
but our project includes controlling through h-bridge circuit. so i think it should control servo motor.
and please if you could refer some dc servo motor models which could b found easily.
motor should be 12v or 24 v. can u give some suggestions please
Posted by:
poncho magilakutti
on: 29 Jul 2010
Re: 5A H-Bridge motor controllers
['Quote ]

Quoting saqib053: hi brother,my name is saqib. we are building a final year project named twin rotor system. for that we are using servo motors. we have to control them so the circuit u mentioned can control the servo motors?
and also if u could let me know some cheap servo motors smaller in size and easily available. hope u gona corporate.


Well, normal hobby servos like these http://www.hobbypartz.com/servos.html have control boards inside them that use a PWM input signal from a microcontroller to dictate how much power should be fed to the servo. A pot is used to provide feedback so you can control the servo with a fair amount of precision. If you are using one of these servos, you do not need a controller like this, you only need a PWM input signal from a microcontroller, and power supply, and ground.
Posted by:
saqib053
on: 29 Jul 2010
5A H-Bridge motor controllers
['Quote ]
hi brother,my name is saqib. we are building a final year project named twin rotor system. for that we are using servo motors. we have to control them so the circuit u mentioned can control the servo motors?
and also if u could let me know some cheap servo motors smaller in size and easily available. hope u gona corporate.
Posted by:
otaromece
on: 11 Jul 2010
5A H-Bridge motor controllers
['Quote ]
good day. i am planning to use the 5A h-bridge motor controller on my project. but i don't know how to interface the h-bridge via parallel port and what programing code should be use. thanks
Posted by:
otaromece
on: 11 Jul 2010
Re: 5A H-Bridge motor controllers
['Quote ]
good day master.. i am planning to use the 5a h-bridge motor control on my project.. my question is that is it possible for me to interface the h-bridge via parallel port instead of using micro-controller? if possible can you teach me how???? :D :D :D
Posted by:
otaromece
on: 11 Jul 2010
5A H-Bridge motor controllers
['Quote ]
hello to all., i am new here in ikalogic. i have a school project to do and im planning to use the 5a hbridge motor driver because it is practical and easy to construct. so my question is., is it possible if i interface the h bridge via parallel port instead of using a micro-controller. if its possible can somebody teach me how??? hoping for kind consideration. thanks a lot masters
Posted by:
User avatar
ikalogic

on: 28 Jun 2010
Re: 5A H-Bridge motor controllers
['Quote ]

Quoting heraldo: One more question: the TIPs 122 and 127 already have a protecting diode from collector to emitter (see the datasheet); why did you put another external diode in parallel ?

(I intend not to use these extra diodes, unless you give me a good reason)


Just extra protection. the first thing that will let you down in such a system are the freewheel diodes.
Posted by:
heraldo
on: 28 Jun 2010
Re: 5A H-Bridge motor controllers
['Quote ]
One more question: the TIPs 122 and 127 already have a protecting diode from collector to emitter (see the datasheet); why did you put another external diode in parallel ?

(I intend not to use these extra diodes, unless you give me a good reason)
Posted by:
heraldo
on: 28 Jun 2010
Re: 5A H-Bridge motor controllers
['Quote ]
First of all I want to thank you for sharing this very smart and useful 5A H-Bridge project.

Right now I am trying to build it in a protoboard, using the simplified digital logic suggested by Chapo (I've checked and confirmed that Chapo's smaller digital circuit is actually equivalent to the original one).

However, in my case the PWM control signals will be generated by a PIC microcontroler whose power is supplied by a laptop computer USB interface.

In order to protect the laptop from eventual switching transients, I intend to isolate the +5VDC power supply that feeds the digital ICs from the +12VDC power supply that feeds the motor and the TIPs.

My idea is to replace transistor Q1, Q2, Q3 and Q4 by 4N25 optoisolators.

It seems to me that all the rest of the circuit can remain just the same, including all resistor values, since the 4N25 optoisolator works fine with the 10 mA input current set up by the 470 ohm resistor and its npn output can easily drive the 1.5 mA set up by the 820 ohm resistor to saturate the TIPS (the 4N25 can drive up to 150 mA collector current).

Do you see any problem in this idea ? Any suggestion ?
Posted by:
User avatar
ikalogic

on: 21 Jun 2010
Re: 5A H-Bridge motor controllers
['Quote ]

Quoting Poncho Magilakutti:
Quoting misfitpv: neutral


What?


yes, same response for me.. WHAT???!! :D
Posted by:
poncho magilakutti
on: 21 Jun 2010
Re: 5A H-Bridge motor controllers
['Quote ]

Quoting misfitpv: neutral


What?
Posted by:
misfitpv
on: 20 Jun 2010
5A H-Bridge motor controllers
['Quote ]
neutral
Posted by:
User avatar
ikalogic

on: 03 Jun 2010
Re: 5A H-Bridge motor controllers
['Quote ]
Thanks a lot for this contribution!! great work :)
Posted by:
chapo
on: 03 Jun 2010
Re: 5A H-Bridge motor controllers
['Quote ]
Well, I've redone the logic stage of your circuit .. Same inputs, same outputs, but cheaper (since there is no need to buy a quad NOR gate IC), maybe this one will be more efficient (not that much I know) cause one chip is saved, and equilibrated (speaking of propagation delays)..

what do you think?
Posted by:
muhammad arsalan
on: 16 Apr 2010
5A H-Bridge motor controllers
['Quote ]
are these pcbs in dip trace or eagle?
You have to be a member to post replies.
Username: Remember me
Register now! it only takes an instant.
Forgot your password?


Unless mentioned, all content is written and designed by Ibrahim Kamal, copying is prohibited and unethical
ikalogic.com: Electronics and Robotics related projects.
All content on this site is provided as is and without any guarantee of any kind. We cannot be held responsible for any errors, omissions, or damages arising out of use of information available on this web site.
Creative Commons License
IMPORTANT COPYRIGHT NOTE: Electronics and Robotics Articles by Ibrahim KAMAL are licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.