HBridge

This is based on the DC Motor Control Using an H-Bridge exercise at ITP.

An H-bridge is an electronic circuit which enables a voltage to be applied across a load in either direction. These circuits allow DC motors to run both forwards and backwards. H-bridges are generally used to reverse the polarity of a motor, but can also be used to 'brake' the motor, where the motor comes to a sudden stop.

This is what you will need for this exercise. Most of the parts are from your Adafruit Industries starter kit. You will be issued a DC motor, breadboard and a SN754410NE quadruple high-current half-H driver integrated circuit.

The notch running down the center of this board marks the centerline of the terminal strip and provides limited airflow (cooling) to dual in-line package (DIP) integrated circuits (ICs) straddling the centerline (such as the SN754410NE). This breadboard has a bus strip containing two columns, one for ground, one for a supply voltage on both its long edges. This is very handy for more complex circuits like the H-bridge you are about to assemble.

Start by linking the two supply voltage bus strips with a jumper wire, these are marked with a red line.

Do the same for the blue ground bus strips.

Attach one of the red supply voltage bus strips to +5v on your Arduino with a jumper wire. When you connect power it will be available available on both sides of the breadboard since both rails are connected.

Connect one of the blue supply voltage bus strips to gnd on your Arduino.

Plug a switch from your Arduino kit into the breadboard. You can learn more about switches here.

Only two legs on each side are actually connected together - so make sure you get the orientation right. You might need to straighten out the legs of the switch with a pair of pliers so it fits into the breadboard.

Connect one leg of the switch to the red supply voltage bus strip +5v on the breadboard.

Connect the other leg of the switch to a 10KΩ resistor.


Connect the other leg of the 10KΩ resistor to the blue supply voltage bus strip gnd on the breadboard.

Connect the second leg of the switch and the other leg of the 10KΩ resistor to pin 2 on your Arduino.

This is the SN754410NE quadruple high-current half-H driver integrated circuit (IC). Each chip has a 'U' notch at one end and 16 pins. In this circuit so we know which pin is which, the 'U' notch is oriented towards the switch and the Arduino. The SN754410NE is designed to provide bidirectional drive currents up to 1A at voltages from 4.5 V to 36 V. It is designed to drive inductive loads such as relays, solenoids, DC and bipolar stepping  motors, as well as other high-current/high-voltage loads. The datasheet for the SN754410NE is attached below.

Insert your SN754410NE into the breadboard so that its pins are on either side of the notch running down the center.

These are the connections you need to make (you are only connecting one motor so some of the pins will be unused):

pin 1 enables and disables the motor - HIGH or LOW
pin 2 is a logic pin for the motor (input is either HIGH or LOW)
pin 3 is for one of the motor terminals
pins 4 and 5 are connected to ground
pin 6 is for the other motor terminal
pin 7 is a logic pin for the motor (input is either HIGH or LOW)
pin 8 is the power supply for our motor, this should be given the rated voltage of your motor
pins 9-11 are unconnected as you are only using one motor
pins 12-13 are connected to ground
pins 14-15 are unconnected as you are only using one motor
pin 16 is connected to +5V

 pin 1
 pin 2  pin 7
 function
 HIGH  LOW  HIGH  Right
 HIGH  HIGH  LOW  Left
 HIGH  LOW  LOW  Stop
 HIGH  HIGH  HIGH  Stop
 LOW  X  X  Stop


Connect pins 4, 5, 12 and 13 of your SN754410NE to the blue supply voltage bus strips gnd on the breadboard.

Connect pins 8 and 16 of your SN754410NE to the red supply voltage bus strips +5v on the breadboard.

Connect pin 7 of your SN754410NE to pin 3 on the Arduino.

Connect pin 2 of your SN754410NE to pin 4 on the Arduino.

Connect pin 1 of your SN754410NE to pin 9 on the Arduino. This is the enable pin that will turn the motor ON or OFF. The motor logic pins (2 and 7) can send HIGH or LOW signals to have the motor turn in one direction, or LOW and HIGH to have it turn in the other direction. N.B. most motors require a higher voltage and higher current draw than an Arduino can supply.


Connect the motor to pins 3 and 6 of the SN754410NE. Put an LED in pin 13 on your Arduino - this will indicate that the system has reset.. 
Upload this code to your Arduino:

// Updated from http://itp.nyu.edu/physcomp/Labs/DCMotorControl

int switchPin = 2;    // switch input
int motor1Pin = 3;    // H-bridge leg 1 (pin 2, 1A)
int motor2Pin = 4;    // H-bridge leg 2 (pin 7, 2A)
int enablePin = 9;    // H-bridge enable pin
int ledPin = 13;      // LED 

  void setup() {
    // set the switch as an input:     pinMode(switchPin, INPUT);

    // set all the other pins you're using as outputs:     pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
    pinMode(enablePin, OUTPUT);
    pinMode(ledPin, OUTPUT);

    // set enablePin high so that motor can turn on:     digitalWrite(enablePin, HIGH);

    // blink the LED 3 times. This should happen only once.     // if you see the LED blink three times, it means that the module     // reset itself,. probably because the motor caused a brownout     // or a short.     blink(ledPin, 3, 100);
  }

  void loop() {
    // if the switch is high, motor will turn on one direction:     if (digitalRead(switchPin) == HIGH) {
      digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low       digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high     }      // if the switch is low, motor will turn in the other direction:     else {
      digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high       digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low     }   }   /*     blinks an LED    */   void blink(int whatPin, int howManyTimes, int milliSecs) {
    int i = 0;
    for ( i = 0; i < howManyTimes; i++) {
      digitalWrite(whatPin, HIGH);
      delay(milliSecs/2);
      digitalWrite(whatPin, LOW);
      delay(milliSecs/2);
    }
  }



Ċ
John Marshall,
Sep 16, 2009, 11:19 PM
Comments