Build a 5A H-bridge Motor driver! New version

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 four wires for 12V power supply and direction control. Nevertheless, it allows bidirectional control, breaking and freewheeling.

The hardware

The schematic figure 1.A can seem a little complicated at the first sight, but, practically, it only consists of two 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 figure 1.B, is given below showing the effect of every combination of the logic states of W1 and W2:

figure 1.B

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.C). 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.C, 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.C

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.

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

Comments ( 12 )

  • Sherif says:

    Hii Ibrahim how are you? I am Sherif Roshdy from o6u, please i want to ask if this driver support pwm signals?? i am using an arduino DAQ and this driver via matlab… i tried the pwm but the motor is not stable..

    thanks

  • Lee Allen says:

    The problem some are having with this circuit may be due to ‘shoot through’. Shoot thru happens when both transistors on one side of the motor switch on at the same time and for a few nanoseconds the supply rails are shorted. This can happen because of race conditions on the switching logic path but for this circuit I think it much more likely because of slow switch off. No transistor ever swiitches on or off instantaneously so for a period both are partially switched on- darlingtons are relatively slow switching. Whatever the reason for a ‘shoot thru’ condition – just a very short time can cause latchups and sometimes even destroy the driver transistors. The solution is to modify the microprocessor instructions so a transistor pair is switched of a few microseconds before the other pair is switched on.

  • bobg says:

    Sorry
    In the last message the last sentence should read

    With W1 and W2 = 0,0 then the voltages at U3-1, U3-4, U1-1 and U1-11 should all be the same, about +0v

    If the voltages are correct then the problem lies in the H-Bridge area

  • bobg says:

    You will need a voltmeter or an
    ‘scope
    Temporarily disconnect the +12V supply but leave it connected to U2 only. This will provide +5V for the logic chips
    Apply 0,1 or 1,0 signals to W1 and W2
    The voltages at pins U3-Pin 1 and U1-Pin 11 should be the same (+/- 0.2v)
    The voltages at pins U1-Pin 8 and U3-Pin 4 should be the same BUT opposite to U3-1 and U1-11
    (Opposite means if one measures approx 0.4V the other should be about +5V)
    If this is not the case then the problem lies in the logic circuit, then check .wiring and the correct orientation of U1 and U3 in the wiring/sockets

    With W1 and W2 = 0,0 then the voltages at U3-1, U3-4, U1-1 and U1-11 should all be the same, about +5v

  • kenny says:

    We also have that short circuit without a motor. So i guess that the darlingtons don’t swtich correctly.

    • Ibrahim KAMAL says:

      Yes most probably the darlingtons aren’t switching as you say.

      What is the voltage level are you using for the bridge?
      maybe the resistors are not adapted to the voltage levels being used…?

  • Flemming says:

    hey,
    I was wondering if the gates could run on a 3v3 input? Im using the mbed microcontroller.
    Im not sure, but from what I can see, the 74LS02 can, but I dont know about the 74HC00

  • kenny says:

    Hello,

    I’ve made two of this H-bridges, but non of the two works fine, both have a short circuit. It’s not full short because the motor turns anti-clockwise, but it takes a lot of current out the power supply. When I try to turn clockwise, it won’t turn and it takes the same amount of current out the power supply.
    Is here somebody who have the same problem, or who know what there is wrong?

    Friendly regards.

    • Ibrahim KAMAL says:

      We all have had a similar problem at one point…
      Have you double checked the diodes direction?
      Have you changed the transistors?
      important question: Does it consume current if you don’t connect a motor ( and leave it open)..?

      • kenny says:

        We also have that short circuit without a motor. So i guess that the darlingtons don’t swtich correctly.
        And the diodes are correct.

Leave A Comment

Your email address will not be published. Required fields are marked *