the active/inactive state of the switches/sensors (yes/no).
During initialization, the code checks to see if the door is
partially open. It does this by checking to see if both limit
switch sensors read inactive (not closed). If this condition is
met, the door close routine is called. Otherwise, the code
enters the main loop while monitoring the pushbuttons.
The open/close routines are very simple. Upon entry
into the routine, the limit switch is checked. If it is active (in
this case, closed), the routine exits. This is always the first
thing done in the routine in case the door is already at its
limit when the routine is called. We don’t want to move the
door before verifying if it has reached its target position.
Since we’re using a stepper motor to move the door, it
must be controlled by a driver; in this case, the L293D. This
driver IC will receive four-bit phase steps on the four inputs
to control the motor direction. Opening or closing the door
simply involves outputting the phase steps in either a
forward or reverse fashion. The loop continues until the
door reaches the limit switch and then exits, setting the
status LED to the corresponding color for that routine:
green if the door is open; red if it is closed. The stepper
motor remains energized in the phase it was last in.
Stepper motors can require higher voltage and current
to operate than a servo or DC motor. Most stepper motors
run at 12 or 24 volts. The stepper motor used in this demo
is rated at 24V, but is being run at just under 12V, reducing
its effective torque.
Stepper motors also require four I/O pins to operate
directly, whereas the servo required one and the DC motor
Magnetic switches are sometimes a little finicky on
where they engage. So, while the stepper motor can
provide a degree of precision, the magnetic switches aren’t
quite so precise in most applications.
There’s also the possibility that a stray magnetic field
could trip one or both switches, resulting in a false reading.
While stepper motors are very common in precision
mechanisms, they are not usually used in door systems. On
the other hand, if you were trying to build a vent or baffle
system and needed precise positioning, the stepper motor
could help you achieve that.
Using two buttons in the demo was done for clarity,
completeness, and simplicity. The code and hardware could
easily be designed to work with just one button or even
none, but rather receive the command from some other
part of your code or a flag variable. SV
are to Board of
BOE powered by
jumper in either
Part numbers are
Savage///Circuits You Tube Channel:
For the finest in robots,
parts, and services, go to
com and click on
Robo-Links. ;; ;;;;;;;;;;;;
SERVO 11.2016 59
(1) Board of Education Full Kit USB (#28803)
(1) Li-Ion Power Pack Full Kit (#28989)
(1) Unipolar Stepper Motor
(1) Bi-Color T1-3/4 LED (#350-00005)
(1) 220 ohm 1/4W 5% Carbon Film Resistor (#150-02210)
( 4) 10K 1/4W 5% Carbon Film Resistor (#150-01030)
( 4) N.O. Pushbuttons/Switches/Contacts
(1) L293D or other H-Bridge Driver IC