# DIY H-bridge for Motor Control

12,678

59

10

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.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Get It!

All you need is...

1. 4 NPN transistors (salvage from old electronics)
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

}

Participated in the
On a Budget Contest

Participated in the
Explore Science Contest

## Recommendations

• ### Internet of Things Class

21,579 Enrolled

## 10 Discussions

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.

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.

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.

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

2 replies

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

Nice project though... ^^

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