Introduction: H Bridge Motor Driver for Arduino Using Transistors

Picture of H Bridge Motor Driver for Arduino Using Transistors

Hello everyone, In this instructable we will be building our own H Bridge motor driver module for Arduino using transistors.

Technical specifications:

  • Control motor speed using PWM pins of Arduino.
  • Control motor direction.
  • Can run any small hobby DC motor consuming 250mA (Maximum).

Why a H Bridge?

  • Unlike my last attempt to control motor using a single transistor, the H bridge module consists of 4 transistors. Because, the single transistor motor driver was able to control the speed of motor. But, unable to control direction of the motor.
  • So, We need a H bridge of transistors in order to control speed as well as direction of the motor efficiently.
  • Also, This motor driver dose not cost any more than $1.25 USD making it super cheap.

Find the circuit on Autodesk Circuits here.

Step 1: Gather the Parts

Picture of Gather the Parts

In order to build our own H Bridge Module, we will need:

  • 4 x 2N2222 transistors
  • 4 x 1.2k ohm 1/4W resistors
  • 4 x IN4007 Diodes
  • 1 x 0.1 microfarad ceramic capacitor
  • 1 x Medium Perfboard
  • 1 x 2-position 3.5 mm terminal block
  • Male pin headers or male jumper wires.
  • 9V Battery clip
  • Wires
  • Soldering tools

Optional parts (For power indication):

  • A LED
  • 1 x 220 ohm 1/4 W resistor

For running and testing the motor driver module, we will need:

  • An Arduino UNO
  • A Breadboard (For prototyping)
  • Small DC Motor
  • 9V Battery

Step 2: Prototype

Picture of Prototype

It's always a good idea to test your circuit on a breadboard before you start to solder them together.

So, hookup all the components according to the circuit diagram shown above.

Before you connect the motor:

  • Solder the 0.1 microfarad ceramic capacitor to the motor to counter electrical noise.
  • Yes, to counter electrical noise the best way is to connect the capacitor as close as possible to the motor.
  • Ceramic capacitors are Non-Polar i.e, they can be connected either way to the motor. So, You do not need to worry about terminals of the capacitor.

Step 3: Arduino Sketch

Picture of Arduino Sketch

Once you have hooked up everything properly upload the following sketch to Arduino:

What does the sketch do?

  • The following sketch turns on the motor and runs it one way for 4 seconds.
  • Stops the motor for a sec.
  • Runs it the other way for 4 seconds.
  • Stops the motor for a sec.

The above process is repeated over again and again.

void setup()

{

pinMode(9, OUTPUT);

pinMode(10, OUTPUT);

}

void loop()

{

analogWrite(9, 220); //Any value between 0 to 255

digitalWrite(10, LOW);

delay(4000);//Wait for 4 secs

digitalWrite(9, LOW);

digitalWrite(10, LOW);

delay(1000);

analogWrite(10, 220); //Any value between 0 to 255

digitalWrite(9, LOW);

delay(4000);//Wait for 4 secs

digitalWrite(9, LOW);

digitalWrite(10, LOW);

delay(1000);

}

Step 4: Run the Motor

Picture of Run the Motor

Power up the arduino and the motor driver. And see your motor spinning.

If you have hooked up every thing properly the motor should spin.

Troubleshooting

A) Motor not spinning:

  1. Make sure you have placed the transistors correctly. i.e. Flat side of the transistors is in the correct side according to breadboard layout.
  2. Try Re-Uploading the sketch

B) Transistors getting too hot :

  1. The motor that I am using does not draws more than 250mA. But, If you are using any other DC motor then it could Draw more than 1000mA easily. Resulting in heating of the transistors.
  2. So, make sure that you are using the right motor.

If you are still having trouble, write in the comments below.

Step 5: Prepare Perfboard for Soldering

Picture of Prepare Perfboard for Soldering

Arrange all the components on the perfboard to get an idea about where all the parts will go.

Also, This will help to choose the right size of perfboard for soldering.

I have used a larger perfboard than, what is required to make things simple.

If you have just started with soldering checkout Instructables for awesome soldering tutorials.

Step 6: Solder the Transistors

Picture of Solder the Transistors

Solder the transistors to the perfboard.

I have bended base of the transistor in order to give proper space to collector, base and emitter for soldering.

This helps in soldering the transistor properly.

Make sure that the Flat surface of NPN transistor goes the correct way. As seen in the schematics and images.

Step 7: Solder the Resistors

Picture of Solder the Resistors

Solder the resistors to base of each transistors.

The resistors do not have polarity. So, they can be soldered either way.

Step 8: Solder the Diodes

Picture of Solder the Diodes

Solder the diodes adjacent to the transistors.

Make sure that the stripe on the diode is pointing the correct way.

Step 9: Solder the Wires

Picture of Solder the Wires

Solder wires and 2-position terminal block to connect the transistors and other components.

I have used solid cored wires as jumpers on the perfboard.

Step 10: Solder the Pin Headers.

Picture of Solder the Pin Headers.

Solder pin headers and Battery clip to motor driver module by referring to the pictures.

I have used male jumper wires after striping one of it's end.

Why to use male pin headers?

  • As a general standard if something is taking power it uses male headers and if something is giving power it uses female headers.
  • So, I used male pin headers on the motor driver module.
  • You can use either male headers or female headers according to your convenience.

Step 11: Done

Picture of Done

Once you have finished soldering all the components to a perfboard you are ready to go.

  • Just attach a 9V battery and motor to the motor driver.
  • Finally, connect the motor driver to Arduino and you are ready to spin your motor.

Thanks for viewing.

Further questions or suggestions are welcome.

Comments

ArhamF2 (author)2017-12-02

What kind of transistor should i use for a bigger dc motor. Plus, can i use the same bridge for two motors?

Anshu AR (author)ArhamF22017-12-04

Bigger DC motors?

In order to run bigger DC motors, find out how much current your motors are consuming at full speed with load(if any).

Finally, lookup transistors (or even better MOSFETs) that can withstand current higher than what your motors require.

same bridge for two motors?

If you want to control their individual speed at the same time then NO.

However, you can run two motors(As long as they are consuming current under the limit). But they will run with the same speed(If both connected in parrel) in the same direction.

Engineer AQ (author)2016-10-08

Great job dude but please upload a circuit diagram if possible.....

Anshu AR (author)Engineer AQ2016-10-08

Yes, I have created and linked breadboard layout using autodesk circuits.
Check it out in the description or in prototyping step.

Gaëld3 (author)Anshu AR2017-11-13

Hi,

On the photos, the diode stripe is towards the right leg of the transistor (when plane face on front of us) while it is the reverse on the diagram at circuits.io.

I suppose the right one is the photo as it was working ?

Thanks for this instructable !

Gaël

Anshu AR (author)Gaëld32017-11-14

Go with the fritzing schematics in step 2.
Anyways diodes should be pointing from the emitter towards the collector of the transistor.
Hope this helps.
:)

Gaëld3 (author)Anshu AR2017-11-18

Hi,

Thank you. After checking my transistors datasheet, the collector is on the right and the emitter on the left, so I had to reverse the schematic and it works.

With my initial setup, the motor was spinning even when the 9V battery was not connected to the breadboard. So, current was drawn from slots 9 and 10 of the Arduino ! Fortunately, it is a very little motor !

brianfit made it! (author)2017-10-16

Using this to run two motors scavenged from old DVD trays in series. It works!

brianfit (author)2017-10-11

I've looked at a bunch of H Bridge instructables and this one takes all the right precautions I'm seeing warnings about -- diodes and resistors to ensure no short throughs, noise reducing capacitor. Nice work. My question: I have a low-voltage motor is there any danger in running from the Arduino +5 volt pin as the power source instead of a 9 volt battery?

Anshu AR (author)brianfit2017-10-11

According to Arduino's website current between VCC and GND pin can be 200mA max.(Any more than this will start causing damage to Arduino)

So, If you are sure that your motor is not drawing that much current, go for it! Generally, small DC motors do not draw current any more than 100mA. But, always refer to data sheet from motor manufacturer.

Hope that helps :)

LorinC3 made it! (author)2016-12-21

I have successfully built this with BC547C NPN transistors and IN4007 diodes. I have replaced the resistors with considerably smaller ones: 75 Ohm instead of several KOhm. May I please ask what criteria you used to choose the value of the resistors?

Thank you for a very nice article.

Anshu AR (author)LorinC32017-08-02

Also I don't think that using 75 ohms is the right choice.

The transistors will be drawing way to much current from the Arduino to actually FRY it!

Anshu AR (author)LorinC32017-08-02

Woooah !! It looks awesome.

I choose resistors just to make sure that the transistors does not draws a lot of current from the Arduino.

Just enough to close the transistor switch.

Refer to the data sheet of transistor for details on how much minimum current is required for functioning. (i.e. min. base current)

Hope that helps.

blackbeard23 (author)2017-03-06

i am having issues with it only outputing .7 volts with a new 9 volt battery. how do you fix this

Anshu AR (author)blackbeard232017-08-02

Alright, Can you post some pictures of your motor driver module so that I can take a look.

Further, Have you modified the circuit or used the parts as suggested.

As per my own experience short-circuits due to bad soldering often led to such problems.

So, try prototyping on a breadboard it should work.

Shine_Santhosh (author)2016-10-07

I,ve triedit with IRF540 and IRF44 MOSFETS. Keep it up its great

Anshu AR (author)Shine_Santhosh2016-10-08

That's awesome!
Why don't you document and publish your work to instructables.
I would love to see it.

Shine_Santhosh (author)Anshu AR2016-10-10

I'm a tenth standard student and busy with studies but I'll try.

Kuuran (author)2016-10-08

Nice post, but the missing schematic makes it impossible to reproduce.

Anshu AR (author)Kuuran2016-10-09

Just added the schematics.

Check it in "Step 2: Prototype"

Anshu AR (author)Kuuran2016-10-08

Yes,
Few more people has faced the same problem.
I think I need to add fritzing breadboard layout and schematics.

mikenaly (author)2016-10-08

You commented about the possibility of the transistors getting hot if the motor pulls too much current. This could easily be tesolved by using higher power transistors.

Anshu AR (author)mikenaly2016-10-09

Yes,

I agree with you. Also, when it comes of powerful transistor MOSFETS are great.

I think that would be next that I would try.

JunezRiyaz (author)2016-10-07

Nice Job

Anshu AR (author)JunezRiyaz2016-10-08

Thanks!

About This Instructable

7,666views

84favorites

License:

Bio: So, I got a bunch of LEDs when I was 8 or 9 something.
More by Anshu AR:Scratch Built RC AirplaneH Bridge Motor Driver For Arduino Using TransistorsHow To Use A Piezo To Produce Tone : Basics
Add instructable to: