DIY H-bridge for Motor Control




About: I like to create things that solve problems, using Arduino, Beaglebone Black, and Raspberry Pi to create projects that are useful or interactive.

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);


digitalWrite(H1, LOW);

digitalWrite(H3, LOW);


digitalWrite(H2, HIGH);

digitalWrite(H4, HIGH);


digitalWrite(H2, LOW);

digitalWrite(H4, LOW);


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




    • Gardening Contest

      Gardening Contest
    • Arduino Contest 2019

      Arduino Contest 2019
    • Classroom Science Contest

      Classroom Science Contest

    10 Discussions


    2 years ago

    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.

    1 reply

    Reply 2 years ago

    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.


    Reply 3 years ago

    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.


    3 years ago

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

    2 replies

    Reply 3 years ago

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


    3 years ago

    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