DPRG Events Shoptalk

Website design and hosting by NCC

DPRG Interfacing Primer

July 1997, Written by Jim Brown
August 2002, page format revised, links updated by NCC

This document still needs some more info, but I hope it may be helpful for newbies to the robotics field.

DC Motors

DC Motors basically work by applying DC power and the shaft spins. Depending on the polarity of the electricity applied the shaft will spin in one direction or the other.

Speed Control
The RPMs (revolutions per minute) are usually nearly linear to the voltage applied. Usually a potentiometer is ok for varying the speed, but you could burn out a motor if the amperage gets too high. A better way to vary the speed is by using PWM (pulse width modulation). PWM allows the voltage and current to remain constant, only the duty cycle is changed. PWM requires the addition of a circuit or computer to regulate the duty cycle. Where full power is full speed, 50% duty cycle is 50% speed, and no power is stop.

Direction Control
The direction of the spin of the shaft changes with the polarity of the power applied. Direction can be changed via an H-Bridge. An H-Bridge can be implemented with switchs, relays or a solid state electronic circuit. Common circuits are the LMD293 (?1 amp?) or the LMD18200 (?6 amp?).

       |               |            1   2   3   4    result
  1 ---@               @--- 3       ------------------------------
       |-------|(------|            on  off off on   foward spin
       |               |            off on  on  off  backward spin
       +-----(MOT)-----+            on  off on  off  break
       |               |            off on  off on   break
       |               |            
  2 ---#               #--- 4       @ = P channel mosfet
       |               |            # = N channel mosfet

If break is not necesary lines 1 & 4 and 2 & 3 may be tied together and switched with an inverter to make the direction only require one line for control.

Interfacing to a MCU
Due to the electrical noise put out by a DC motor that can damage an MCU or cause it to malfunction, DC motors should be isolated from the MCU's circuit. One common way to isolate the MCU from a DC motor is to make an H-Bridge with seperate power supplies and a common ground. Additional isolate on the I/O lines should include a resistor between the mcu and the h-bridge and possibly a filtering capacator across the motor leads.

Stepper Motors

Interfacing to a MCU
Stepper motors are usually controlled by a special stepper motor chip. A good stepper motor chips is the ?UCN5804? which will control a stepper by using to control lines: Step and direction. These parts are usually pricey ($5 or so).

I found out a nice alternative using a ULN2803 (or 2804). It's really is a nice way to go. I've gotten the ULN2804 version at Tanners! Works practically the same as the 2803 but available at Tanners. I think they were .50 or 1.00 or something like that. Well worth it!!! And the circuit makes sense! One can drive two steppers from one 2803 (or 2804) chip.

          |    _________    +-----------------+--- +12v
+-------+-+   |       10|---+     _________   |
| 8051 1|-----|1 2803 18|--------|         |  |
|      2|-----|2      17|--------| stepper |  |
|      3|-----|3      16|--------|         |--+
|      4|-----|4      15|--------|_________|  |
|       |     |         |                     |
|       |     |         |         _________   |
|      5|-----|5      14|--------|         |  |
|      6|-----|6      13|--------| stepper |--+
|      7|-----|7      12|--------|         |  
|      8|-----|8      11|--------|_________|  
|       |  +--|9        |                    
+---+---+  |  +---------+                   
    |      |                           

Each of the 8 buffers in the 2803 has a incoming resistor, 500ma sink, and a flyback diode.
                      |     |
                      |     _
              1k      |     ^
                      |\    |
to mcu  ----/\/\/\----| >---+--- to stepper

I think the only difference between the 2803 and the 2804 is that the 1k resistor in the 2803 is a 10k resistor in the 2804.

These 2803's work great for unipolar steppers. For the bipolar ones, I'd probably resort to a nasty stepper chip or just switch to a unipolar stepper.


Servos are basically a DC motor with a circuit built in to decode positioning information. A computer or timing circuit sends in pulses that indicate the position the shaft of the servo should be in. Most servos have about 120 degree range of motion. Many walking robots use servos.

Interfacing to an MCU
For power, I found out that most servos operate on 4.8 volts, but are ok with anything from 4.0 volts to 6.0 volts. Servos have three wires, and usually are: Red=+, Black=Gnd, White=Signal. The signal line should be at TTL level.

For the signal that controls the positioning of the servo, it needs a pulse of 1ms to 2ms and that pulse needs to be sent every 20ms to 30ms. The positioning goes that a pulse of 1.5ms is the shaft center position, and any other pulse width would move the shaft proportionally to the left or right.

Servo illustration For a proto design, I used one Tower Hobbies TS-53 servo, four AA batteries for the servo power, my 8031PCB for the brains, and a 9V to power the 8031PCB. I connected the grounds so that the signal line should have a path back to the 9V. Having seperate power for motor and SBC keeps unwanted noise from the motor from affecting the CPU (or so I'm told).

Click here if you want to see the C source code for to the servo controller.

The software just goes through a test pattern of: 1000us, 1250us, 1500us, 1750us, 2000us, 1750us, 1500us, 1250us, 1000us, 2000us, and repeats. In other words, it goes from left to right in steps, and then right to left in steps, and then quickly to the left and back to the right.


LEDs are light emitting diodes. LEDs usually take a few miliamps to turn them on. The higher the current (not the voltage) the brighter the LEDs. Too high a current will burn out the LEDs or burn out the circuit providing power to the LEDs. To figure out the current limiting resistor required use the formula: r = v/i where i = current, r = resistance, v = voltage (200ohm = 5v/0.025amp). Since LEDs are diodes, current only flows one way so polarity is important.

Interfacing to a MCU
Most microcontrollers do not sink or source enough amperage to drive an LED. So, to drive an LED you'll need a buffer chip such as a 7404 or 7414 and a current limiting resistor of about 220 ohms. A buffer chip like a 7404 or 7414 can drive several LEDs and control up to 6 seperate LED circuits.

                +--------+  | 
                |        |--+    220    LED
  to MCU  ------|  7414  |-----/\/\/\---|<--- +5v
                |   or   |
                |  7404  |
             +--|        |
             |  +--------+


IR pairs

Interfacing to a MCU

Buttons & Bumper Sensors

A button is just a mechanical device that connects or disconnects a circuit. Since the signal from a button may actually be several very quick pulses instead of one simple on signal, a debounce algorithm is usually implemented in software to check that a signal is actually sticking on. A debounce algorithm is handy if one is counting the number of signals actually received and where multiple signals for one actual touch is not desired. If the signal sticks on for more than about 50ms it's considered to really be on, otherwise it is a false signal and is ignored. If only a leading edge on detection is desired then the debounce algorithm is not required.

Interfacing to a MCU
A button is simple to interface to an MCU. All you have to do is hook one the MCU's I/O line to a line pulled through a resistor to ground, and hook the same line through a switch and to ttl high. Normally the line will be pulled low, but when the button is pressed, the ttl high takes presidence and pulls the signal to the MCU high.

       to MCU ---+----   --------- +5v
                 |     10k
                 +---/\/\/\---- gnd



An audio signal can be produced from a speaker connected to a driver circuit. A common amplifier chip is an LM386 (not to be confused with a 80386 cpu). The LM386 is a 8 pin power amplifier that puts out enough power to drive an 8 ohm speaker.

Interfacing to a MCU
The LM386 chip is an easy chip to use to amplify a simple square wave from an MCU. A square wave from 500 hz to 2000 hz generated from an MCU makes great audible tones.

                +-----+   |
                |     |---+
   to MCU ------|     |     10uf   /
                | 386 |-----|(----|  speaker
            +---|     |       +--- \
            |   +-----+       |



Sonars are basically a device that puts out an inaudible pulse, and counts the time it takes to get an echo. The Polaroid 6500 series sonar ranging module has a range of 6" to 35 feet.

Interfacing to a MCU
Polaroid makes the 6500 series sonar ranging module. Basically the init line is brought high and a timer is started, when the echo line goes high the time counted is run through a simple formula of 0.9 ms per foot to calculate the distance traveled to an object detected. An additional line may be brought to the MCU if object detection of distances less than 18 inches is desired.

                 +---------+   |
          init   |         |---+
   to MCU -------|  sonar  |
          echo   |  module |    /
          -------|         |===| transducer
                 |         |    \
             +---|         |
             |   +---------+


Copyright © 1984 - 2016 Dallas Personal Robotics Group. All rights reserved.