Tom's Main Menu

Physical Computing Home

Intro to Physical Computing Syllabus

Networked Objects

Sustainable Practices

blog

Resources

code, circuits, & construction

my del.icio.us links

 

Lab Assignment

 

DC Motor Control Using an H-Bridge

 

Minimum parts needed: (new parts in bold. see parts list for details)

  • Prototyping board (breadboard)
  • Power supply connector (2)
  • 5-15VDC power supply
  • Assorted wires
  • 5V regulator
  • PIC 18F452 or BX-24
  • Serial cable
  • DB9 female serial connector & headers
  • LED's
  • Switch
  • SN754410 (or L293) H-bridge
  • DC motor
  • power supply for DC motor
  • 10uF capacitor
  • 1uF capacitor
  • 10Kohm resistors
  • 220 ohm resistors

(Note: if you simply want to turn a motor on and off, and don't need to reverse it, for example if you're controlling a fan, try the TIP120 example).

To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. With any H-bridge, you will have certain elements:

  • Pins for logic input
  • Pins for Supply voltage
  • Pins for Logic voltage
  • Pins for Supply output
  • Pins for ground

The logic voltage pins want the same voltage and current as your microcontroller. The supply voltage wants whatever voltage and current you run your motors with. The logic inputs connect to the pins on your microcontroller that you use to output control signals to the H-bridge. And the supply output pins go to your motor. The configuration of these pins might vary slightly depending on the manufacturer of the H-bridge. They might also use slightly different names, but the concepts are the same.

This example uses an H-bridge integrated circuit, the Texas Instruments SN754410 (you can also use the L293, which is identical to ths TI chip). Acroname carries these chips, as do many other manufacturers. This particular chip has 4 half-H bridges, and can therefore control 2 motors. It can drive up to 1 amp of current, and between 4.5 and 36V. If your motor needs more than that, use a different H-bridge.

Step 1:

Get a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply in the lab. Try changing the voltage on it, and seeing what effect it has. Don't go over the motor's rated voltage. Connect a switch in series with the motor and use it to turn on the motor.

 
Step 2:

Connect the motor to the H-bridge as follows:

H-Bridge connected to a PIC. Note the motor supply wire. In this example, it runs to the 12V input from the DC power supply, because the motor runs on 12V. It may be different on your circuit, depending on the votlage your motor needs. Note also the 10Kphm pulldown resistor needed on the enable pin.

H-brige connected to a BX-24.

Most motors take a great deal more current than a microprocessor, and need their own supply. The example above uses 12V, run in paralle with the 7805 regulator. Whatever motor you use, make sure the power source is compatible (i.e. don't use a 9V battery for a 3V motor!).

Note that we've added two capacitors on either side of our regulator. They smooth out the power, as the motor will cause spikes and dips when it turns on and off.

Here's the schematic for the capacitors and the regulator:

If your power supply for the micocontroller is compatible with your motor, you can wire the motor supply in parallel with the 5V regulator. For example, I use a 12V DC 1000 mA power adaptor, so I can use a 12V motor, if the power from the motor is wired in parallel with the 5V regulator's input, like so:

Note that the motor and the microcontroller need a common ground (in our case, they get it through the transistor's base; see above schematic).

 
Step 3:

Program the microcontroller to run the motor through the H-bridge:

PIC:

' switch is on RC4:
switchPin	var portc.4
input switchPin

' H-bridge is on RC2 and RC3. Enable is on pin RC1
motor1Pin	var	portc.2
motor2pin	var	portc.3
speedPin 	var portc.1

output motor1Pin
output motor2pin
output speedPin

' start with speed on:
high speedPin

main:

	' switch direction:
	if (switchPin = 1) then
		low motor1Pin
		high motor2Pin
	else
		low motor2Pin
		high motor1Pin
	endif

	' blinking LED to tell that the program is still running:
	high portb.0
	pause 50
	low portb.0
	pause 50
goto main


BX-24:
' H-bridge is connected to pins 11 and 12.
' Switch is connected to pin 20
' motor enable pin is connected to pin 8

Const switchPin		as	byte = 20
Const motor1Pin		as	byte = 11
Const motor2Pin		as	byte = 12
Const motorEnablePin	as	byte = 8
Dim motorDirection as byte

Sub main()
	' initialize  variables:
	call putPin(motor1Pin,1)
	call putPin(motor2Pin,0)
	motorDirection =  getPin(motorEnablePin)

	do
		if motorDirection  = 1 then
			call putPin(motor1Pin,0)
			call putPin(motor2Pin,1)
		else
			call putPin(motor1Pin,1)
			call putPin(motor2Pin,0)
		end if
	loop
end sub
 
Step 5:

Use your motor to make something move, vibrate, rise, fall, roll, creep, or whatever you can think of, in response to user input from a digital input device (switch, floor sensor, tripwire, etc).