H Bridge From Scratch

by Arnov Sharma in Circuits > Arduino

2908 Views, 12 Favorites, 0 Comments

H Bridge From Scratch

Making Motor Driver from scratch by using Transistors
01 (107).gif
03 (101).gif
10 (102).gif
Image5.jpg

Hey Everyone how you doing?

So here's an interesting small project, a DIY Motor Driver made by using a few Transistors and Mosfets to drive a couple of small Micro Gear Motors that operate at a voltage of less than 5V.

The end goal of this project is to use this DIY H-Bridge Motor Driver to prepare a small Micro Robot concept.

In this Instructables, you will learn about how the Motor Driver works and how we can construct a simple H Bridge circuit for making our own Motor driver IC, so Let's get started.

Supplies

  • Perf Board
  • Arduino Nano
  • BC547 SOT23-3
  • AO3400 SOT23-3
  • 100 Ohms 1206 Package
  • 3.7V Li-ion cell
  • Seeed Grove Module
  • Breadboard

L293D Motor Driver

IMG_20221031_193418.jpg
fbd_slrs008d.gif
n0016a.png_large.png

Usually, for driving Motors, we tend to use common drivers like L293D or its higher version L298N which are both H Bridge-based Motor drivers that have two channels or two motor outputs.

L293D can handle peak current up to 1A and L293D Can handle up to 4A.

However, both of these Motor Drivers are for the operation of Motors from 4.5V to 40V which is ideal for bigger motors like 12V Gear DC motors or 24V Planmatary motors but what if we have a smaller motor variant that required a voltage less than 5V?

I'm preparing a Small Robot that runs with a 3.7V Li-ion cell which is connected to a boost module that outputs stable 5V for the Motor to run.

But here's the problem: If we increase the voltage through the boost module, the battery backup will decrease, so we have to prepare a 5V Operational DC Motor Driver system.

L293D can work with 5V but it's not ideal so instead of using that, we can make our own H-Bridge and a better L293D-like Setup that can run any motor even if the motor is rated for low voltage.

Here's the datasheet for L293D if you want to check out its specs in detail.

Datasheet- https://www.ti.com/product/L293D

H Bridge

hb_page-0001.jpg
07 (105).gif
08 (101).gif

H Bridge is a unique circuit that can switch the polarity of the voltage applied to any load, it's generally used with Motors for changing their rotation from backward to forward and can be made out of switches.

Above is the H Bridge that we are using currently and it comprises of FETs connected in an H Configuration.

This circuit was made in such a way that N Channel Mosfets or NPN Transistors can both be used here. Let me explain how.

Both the N Channel Mosfet and NPN transistor direction is the same, their current usage and internal composition are different but their working is similar.

Mosfets are Voltage controlled devices and Transistors are current-controlled ones, both can be operated by applying a signal to the gate or base of the FETs.

Here's how this H-Bridge Works

Four FETs are connected in such a way that the first two FETs (Q1 and Q2) Drain is connected to the VCC or Power source that will drive the motor.

Sources of Q1 and Q2 are both connected to the positive and negative of the motor.

Two more FETs Q3 and Q4 Drains are connected with sources of Q1 and Q2 along with the Motor's terminals.

Sources of Q3 and Q4 are connected with GND.

  • Gates of Q1 and Q4 are connected together and gates of Q2 and Q3 are connected together, if we apply a signal to Q1, Q4 will also get activated and if the signal is applied to Q2, Q3 will get activated.
  • 1 and 0 will be denoted for HIGH and LOW, we set Gate of Q1 to 1 and Q2 to 0, and this turns the motor in one direction, if we set Gate of Q1 to 0 and Q2 to 1, the Polarity of motor changes and it start rotating in opposite direction.
  • If both Q1 and Q2 are 1, then a short circuit will occur.

This is how the H-Bridge works. now let's see a practical example of this setup.

Bridge With BC547

Image2.jpg
02 (107).gif
03 (101).gif

So here's a practical version of the above H Bridge Circuit made from Four BC547 NPN transistors and a few resistors. Four 100 Ohms Resistors were connected in Parallel with the VCC side to limit the current flowing through the motor.

This circuit does look janky but it works.

Arduino Wiring

01.JPG

As for the Arduino Wiring, we need to connect 5V of Arduino to the VCC of Mosfet PCB, GND to GND, D2 to Base 1, and D3 to Base 2.

CODE

int in1 = 2;
int in2 = 3;


void setup() {

pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);

}

void demoOne() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(1000);

digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(1000);

digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
delay(1000);

}

void loop()
{
demoOne();

}


Here is the main code and it's quite simple, there are two pins that are set as output. In the demoOne Function, we set in1 High and in2 LOW, this will turn the motor in one direction.

After a Delay of 1 Second, in1 is set at LOW, and in2 is set at HIGH and this reverses the polarity of the motor, after this both in1 and in2 are set to LOW for 1 second.

In the loop section, demoOne is executed for continuous working.

RESULT

04 (108).gif
05 (106).gif
06 (101).gif

Here's the Result and as you can see, the motor is working and moving in both directions. It moves in one direction for a second and then changes its direction and then pauses for a moment, this happens in a loop all over again.

We connect a Multimeter in series with the Seeed Module to measure the current consumption of the whole system, idle current is below 60mA but it gets higher up to 140mA if we try to stop the rotation by hand, doing this is like replicating down drag by weight of where this motor will be mounted.

140mA is what we are getting through the BC547 Transistor setup which is really low and not usable for the robot project.

POWER SOURCE- SEEED GROVE Module

IMG_20220906_000148.jpg
IMG_20220906_000214.jpg

For powering this setup, I'm using a previously made project which was this SEEED Grove Module.

It's a Power Module that is based around IP5306 Power management IC which boosts 3.7V of Li-ion cell to stable 5V 2A output which is perfect for powering an Arduino Setup with a 5V Motor Load.

This Module was originally made as a Power hat for Raspberry Pi, but in this case, we use it to power this setup.

Seeed Studio Grove System is being used in this Module however because it's not a Sensor board, it's being utilized to add a battery to this module and distribute power through two remaining wires. Two wires are for Battery connection and the other two are for 5V Output and Charging IN.

As for its feature, it offers Low and High Cut Protection and even short circuit protection with thermal shutdown as well. It also has an indication setup for battery capacity level which is really handy as we can monitor the battery through it.

H Bridge With AO3400

Image1.jpg
09 (96).gif

Next, we try the same setup but with a Mosfet this time, AO3400 N-Channel Mosfet was used to construct an H-Bridge setup by following the above circuit.

This version is better than Transistor H-bridge in many ways, a most prominent one is the higher current output, meaning the motor can draw more current than the previous setup.

Arduino Wiring

02.JPG

As for wiring, we follow the same wiring as done before with the Transistor setup but this time, we add mosfet setup with the Arduino on the same breadboard by putting the VCC of H Bridge to 5V, and GND to GND, gate pins are connected with D11 and D12.

CODE

int in1 = 2;
int in2 = 3;
int in3 = 11;
int in4 = 12;


void setup() {

pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);

}

void demoOne() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(1000);

digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(1000);

digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(1000);

}

void loop()
{
demoOne();

}


same code as before, this contains two more Outputs that work exactly like the previous two outputs.

RESULT

10 (102).gif
11 (103).gif

Here's the result of the Mosfet-based H-Bridge setup that works, this one can flow more current meaning we can drive the same motor with a higher current.

250mA seems to be Max Current taken by the motor at 5V which is plenty for the low-powered mini robot.

CONCLUSION AND FURTHER USE

Making Motor Driver from scratch by using Transistors
12.gif
03.JPG
04.JPG

Overall result seems promising and I have already prepared two boards with the above H-Bridge setup, one is the "Minimal H-Bridge" which is similar to the perf board janky setup and the one is a working "Robot Motor driver" that contains two bridges for controlling two motors, this driver will be controlled by an ESP12F Board and I will make a separate article about that so stay tuned for that.

If you have any problem regarding this project, leave a comment.

Peace out.