causing it to conduct and assert the collector low. This
works in a similar manner to the beam-break detector in
most garage door openers, but at a much closer range.
In Figure 5, you can see the IR LED that makes up half
of the upper limit switch (red arrows). The IR LED is
soldered to a piece of protoboard and mounted to the unit
in such a way that when the door is fully open it blocks
light from passing through to the other side, but otherwise
In Figure 6, you can see the phototransistor that
makes up the other half of this limit switch. When the light
from the IR LED is blocked from the phototransistor, it does
not conduct and is pulled high via a 10K resistor. However,
when the IR light does pass through, the phototransistor
conducts bringing the I/O pin low.
By monitoring the switches, we know when the door is
to be opened/closed. By monitoring the limit switches, we
know when the door is fully opened/closed. By reversing
the state of the I/O pins the status LED is connected to, we
can turn the LED green/red/off.
The example code available at the article link is for the
BASIC Stamp 2 and can easily be ported to any other
microcontroller. It defines all the I/O definitions first, as well
as the constants that define 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 blocked). 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,
Since we’re using a servo to move the door, it must
receive a pulse every 20 ms. This pulse needs to be the
right width to move the servo in the direction required to
open/close the door as needed, and will usually be 1 ms or
2 ms. The loop continues until the door reaches the limit
switch and then exits, setting the status LED to the
SERVO 09.2016 45
Figure 5. Close-up of IR LED side of upper limit
Figure 4. Close-up of control board.
Figure 6. Close-up of phototransistor side of
upper limit switch.