Introduction: DIY H-bridge for Motor Control

Ever wanted to make a robot, but don't have an H-bridge handy? Then make your own! It's easy, cheap to make, and simple in concept and design. It doesn't have Pulse Width Modulation to control speed, but that isn't totally necessary.

Step 1: Get It!

All you need is...

  1. 4 NPN transistors (salvage from old electronics)
  2. breadboard
  3. small DC motor (everyone should have one from an old RC car)
  4. Arduino Uno (optional, used to control the motor)
  5. 4 resistors (any value really)

Step 2: Build It!

Wire up the connections as shown in the picture. The resistors are for the inputs from a microcontroller to control the direction of the motor. Be sure to orient the transistor the right direction. here I added a sitch to turn on the opposite transistors to turn one direction or another.

Step 3: Use It!

Hook up the inputs to the resistors, the digital pins in an Arduino. You can use the code below to test it. Opposite transistors turn the motor. Be sure to connect a battery to the power and ground rails on the breadboard, and connect the ground from the Arduino to the ground rail on the breadboard.

//H-bridge code!

const int H1=9;

const int H2=10;

const int H3=11;

const int H4=12;

//Pins for the transistors, starting at the top left, going around clockwise

void setup()

{

pinMode(H1, OUTPUT);

pinMode(H2, OUTPUT);

pinMode(H3, OUTPUT);

pinMode(H4, OUTPUT);

//Set pins as outputs for transistors

}

void loop()

{

digitalWrite(H1, HIGH);

digitalWrite(H3, HIGH);

delay(1000);

digitalWrite(H1, LOW);

digitalWrite(H3, LOW);

delay(500);

digitalWrite(H2, HIGH);

digitalWrite(H4, HIGH);

delay(1000);

digitalWrite(H2, LOW);

digitalWrite(H4, LOW);

delay(500);

//Turns one way for a second, then switches directions

}

Comments

author
AndyB97 (author)2016-08-06

You should test your code. Actually, you shouldn't, but you should examine it. You say to start top left as H1 and go around clockwise, so H4 is immediately below H1. Using your fritzing diagram, H1 supplies VCC to the yellow lead and H4 ties the yellow lead to GND, so when you set them both HIGH it's a dead short. So is H2 and H3; H2 supplies VCC to the green lead and H3 ties the green lead to GND. The way you laid the circuit out, the pairs that should be on and off at the same time are diagonal.

I changed it to pair H1/H3 and H2/H4 and it runs and then reverses, but so much damage was done from the first test that not much voltage gets through and the engine doesn't spin fast enough to move the car. It does if I go through a simple fet switch that doesn't reverse; the battery has enough juice and the motor works fine. The good news is that the code only destroys the circuit.

author
nolanthecyborg (author)AndyB972016-08-10

Thanks for letting me know about the mistake. I must have corrected it in my code and not transferred it here. It now shows H1 and H3, and H2 and H4. Only the circuit should be damaged, which you said, and transistors are fairly cheap. Also, a full blown motor driver or H-bridge would be more robust.

author
Stefanosandri (author)2015-11-23

what about back emf protection

author

You could put four diodes after the transistors to protect the circuit from back emf, but buying a cheap motor controller would be best for permanent projects. This design would be better for testing a design before buying parts.

author
Raphango (author)2015-10-09

In your fritzing sketch you seem to miss the other end of the resistors.. =]~

author
nolanthecyborg (author)Raphango2015-10-12

The unconnected ends are supposed to go to pins on a microcontroller.

author
Raphango (author)nolanthecyborg2015-10-12

Oh, i got it! =D

author
Raphango (author)2015-10-09

Nice project though... ^^

author
StevenDeDomenico (author)2015-09-21

Is it possible to make it PWM using the outlined setup? Steve

author

After thinking a bit, it might be possible for PWM if you put another transistor below the rest (see image, Q1) and PWM on that transistor after setting the other four transistors. Hope this helps

H-bridge.png

About This Instructable

9,475views

59favorites

License:

Bio: I like to create things that solve problems, using Arduino, Beaglebone Black, and Raspberry Pi to create projects that are useful or interactive.
More by nolanthecyborg:Getting Started with BeagleBone BlackBluetooth Controlled Robot: RustyLeafSwordLettuceDIY H-bridge for Motor Control
Add instructable to: