Introduction: QuickStart Bi-directional Motor Control

This is a full H-Bridge bi-directional control circuit for DC motors for the
Parallax QuickStart board.

There are six transistors, four for motor control, the other two connect the
micro-controller output pins to the motor controller.
See the schematic below for the gory details.
It is not a difficult circuit to build on a breadboard.
And it can use larger transistors for larger motors.
Depends on what you need for your project...

4 each 2N3904 NPN transistors
2 each 2N3906 PNP transistors
Motor (this one is a geared motor)
Breadboard, wires, etc.


The demo program is written in SPIN for the Parallax Propeller micro-controller.
It is very straight forward. No drivers or other objects are required as all this
demo does is run the motor back and forth.  It does this by setting ONE of the
motor control output pins to 1 to turn on the transistors for that direction.

Note the warning in the code - only turn on ONE output bit at a time.
Turning on both at the same time makes the transistors very angry.
(THEN you'll be sorry!)

For a fancier driver see my one-transistor trick. It shows how to do a soft-start /
speed controller via software generated PWM (Pulse Width Modulation).
(Hey, it was only one transistor. I had to do something to make it interesting!)

{ BiDirectionalMmotorDemo.spin Richard Lamb - June 16, 2013 }

_XINFREQ =5_000_000

' define times
MSec   = _XINFREQ / 1_000
' define IO pins
' note only one motor pin may be turned on at any one time!
LED_LFT = 23
LED_RIT = 16


PUB  Throb
dira [LED_LFT] := 1               ' leds
dira [LED_RIT] := 1
dira [0..1] := 1                          ' motors set outputs
outa [MOT_RIT] := 0               ' start with both pins low
outa [MOT_LFT] := 0

Repeat                            ' repeat forever
    Outa[LED_LFT] := 1              ' LED on
    OUTA[MOT_LFT] := 1            ' motor on


    Outa[LED_LFT] := 0              ' LED off
    OUTA[MOT_LFT] := 0            ' motor off

    wait(500)                 ' intermissioin

    Outa[LED_RIT] := 1              ' LED on
    OUTA[MOT_RIT] := 1            ' motor on


    Outa[LED_RIT] := 0              ' LED off   
    OUTA[MOT_RIT] := 0            ' motor off

PUB wait(MS)