Introduction: Control a DC Mototr Using H-Bridge

Picture of Control  a DC Mototr Using H-Bridge

So have you burnt a 293d IC while controlling a motor ?? yes,you would have because to run a 12V motor 293d IC cant drive it because the IC can hold maximum upto 8V so this overcome this problem we found a neat motor control module based on the L298N H-bridge IC that can allows you to control the speed and direction of two DC motor. Even the stepper motor can also be controlled.

The L298N H-bridge module can be used with motors that have a voltage of between 5 and 35V D. So if your supply voltage is up to 12V you can also source 5V from the board. So let’s get started!

Step 1: H-Bridge :-

Picture of H-Bridge :-
  • DC motor 1 “+” or stepper motor A+
  • DC motor 1 “-” or stepper motor A-
  • 12V jumper – remove this if using a supply voltage greater than 12V DC. This enables power to the onboard 5V regulator
  • Connect your motor supply voltage here, maximum of 35V DC. Remove 12V jumper if >12V DC
  • GND
  • 5V output if 12V jumper in place, ideal for powering your Arduino (etc)
  • DC motor 1 enable jumper. Leave this in place when using a stepper motor. Connect to PWM output for DC motor speed control.
  • IN1
  • IN2
  • IN3
  • IN4
  • DC motor 2 enable jumper. Leave this in place when using a stepper motor. Connect to PWM output for DC motor speed control
  • DC motor 2 “+” or stepper motor B+
  • DC motor 2 “-” or stepper motor B-

So i hope you have understood the reason why we use Dual bridge ??? if not please leave a comment below i would be glad to help you out.

Step 2: ELECTRONICS REQUIRED :-

Picture of ELECTRONICS REQUIRED :-
  • Arduino uno
  • Screw driver
  • Jumper wire
  • Dual Bridge or H-Bridge
  • DC Motor

So the bill of materials required for this project is very low. let's get started with the tutorials.

Step 3: BUILDING ELECTRONICS :-

Picture of BUILDING ELECTRONICS :-

If you’re using two motors for a robot (etc) ensure that the polarity of the motors is the same on both inputs.

Next, connect your power supply – the positive to pin 4 on the module and negative/GND to pin 5. If you supply is up to 12V you can leave in the 12V jumper (point 3 in the image above) and 5V will be available from pin 6 on the module. This can be fed to your Arduino’s 5V pin to power it from the motors’ power supply. Don’t forget to connect Arduino GND to pin 7 on the module as well to complete the circuit. Now you will need six digital output pins on your Arduino, two of which need to be PWM (pulse-width modulation) pins. PWM pins are denoted by the tilde (“~”) next to the pin number, for example in the image of the Arduino Uno's digital pins. Finally, connect the Arduino digital output pins to the driver module. In our example we have two DC motors, so digital pins D9, D8, D7 and D6 will be connected to pins IN1, IN2, IN3 and IN4 respectively. Then connect D10 to module pin 7 (remove the jumper first) and D5 to module pin 12 (again, remove the jumper). The motor direction is controlled by sending a HIGH or LOW signal to the drive for each motor (or channel). For example for motor one, a HIGH to IN1 and a LOW to IN2 will cause it to turn in one direction, and a LOW and HIGH will cause it to turn in the other direction. However the motors will not turn until a HIGH is set to the enable pin (7 for motor one, 12 for motor two). And they can be turned off with a LOW to the same pin(s). However if you need to control the speed of the motors, the PWM signal from the digital pin connected to the enable pin can take care of it. This is what we’ve done with the DC motor demonstration sketch. Two DC motors and an Arduino Uno are connected as described above, along with an external power supply.

Step 4: CODING :- FOR ONE MOTOR

void setup ()

{

pinMode (7 , OUTPUT);

pinMode( 8 , OUTPUT);

pinMode(9 , OUTPUT);

}

void loop()

{

digitalWrite(8 , HIGH);

digitalWrite(7 , LOW);

analogWrite(9 , 80);

delay(1000);

digitalWrite(8 , LOW);

digitalWrite(7, HIGH);

analogWrite(9 , 80);

delay(100);

}

Step 5: CODING :- FOR 2 MOTOR

// connect motor controller pins to Arduino digital pins

// motor one int enA = 10;

int in1 = 9;

int in2 = 8; //

motor two int enB = 5;

int in3 = 7;

int in4 = 6;

void setup() { // set all the motor control pins to outputs

pinMode(enA, OUTPUT);

pinMode(enB, OUTPUT);

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

pinMode(in3, OUTPUT);

pinMode(in4, OUTPUT); }

void demoOne() { // this function will run the motors in both directions at a fixed speed // turn on motor A digitalWrite(in1, HIGH);

digitalWrite(in2, LOW); // set speed to 200 out of possible range 0~255

analogWrite(enA, 200); // turn on motor B

digitalWrite(in3, HIGH);

digitalWrite(in4, LOW); // set speed to 200 out of possible range 0~255

analogWrite(enB, 200);

delay(2000); // now change motor directions

digitalWrite(in1, LOW);

digitalWrite(in2, HIGH);

digitalWrite(in3, LOW);

digitalWrite(in4, HIGH);

delay(2000); // now turn off motors

digitalWrite(in1, LOW);

digitalWrite(in2, LOW);

digitalWrite(in3, LOW);

digitalWrite(in4, LOW); }

void demoTwo() { // this function will run the motors across the range of possible speeds // note that maximum speed is determined by the motor itself and the operating voltage // the PWM values sent by

analogWrite() are fractions of the maximum speed possible // by your hardware // turn on motors

digitalWrite(in1, LOW);

digitalWrite(in2, HIGH);

digitalWrite(in3, LOW);

digitalWrite(in4, HIGH); // accelerate from zero to maximum speed

for (int i = 0; i < 256; i++) {

analogWrite(enA, i);

analogWrite(enB, i);

delay(20); } // decelerate from maximum speed to zero

for (int i = 255; i >= 0; --i) {

analogWrite(enA, i);

analogWrite(enB, i);

delay(20); } // now turn off motors

digitalWrite(in1, LOW);

digitalWrite(in2, LOW);

digitalWrite(in3, LOW);

digitalWrite(in4, LOW); }

void loop() {

demoOne();

delay(1000);

demoTwo();

delay(1000); }

I hope you followed this tutorial.So to have a update of Arduino and HTML and CSS tutorial kepp following me.thak you.if you have any doubt please do leave a comment below i would be plesed to help you

Comments

smandal13 (author)2015-08-10

very helpful. Thanks for this instructable

About This Instructable

7,206views

130favorites

License:

More by appytechie:Program the Linkit One Using a Raspberry PILinkit One Controlled El-wireLinkit One - Dice
Add instructable to: