configuration on the L293D and the same code, you could
actually run a bipolar stepper motor. The difference is the
bipolar motor would not have a COM wire. If you
connected the four phases in the same manner, it should
work, making this circuit ideal for either type of stepper
Magnetic Limit Switches
Magnetic limit switches can be any type that is
sensitive to magnetic fields. So, this could be a Hall-effect
sensor, reed switch, or even the magnetic switches used in
alarm systems (which are usually the reed switch type). The
sensors I used are shown in Figure 6. Essentially, it is a
normally open reed switch that closes when near a
magnetic field. So, you can use them in the same manner
you would use a normally open pushbutton switch.
In the schematic, each switch connects to ground and
to the signal line which is pulled to Vdd via a 10K resistor.
The program sees a high on the line when that sensor is
not active and a low when it is. When the magnet is near
the switch, it is closed. Figure 7 shows the upper limit
switch being triggered by the door moving up, stopping the
door at that point.
Figure 8 shows the lower limit switch being triggered
by the door moving down, stopping the door at that point.
I used tape to affix the magnetic switches and the magnet
since it allowed me to make adjustments more easily.
The magnet is also taped to the bottom right edge of
the door so it could be adjusted. This setup works quite
nicely, however, in a more professional application I would
embed the magnet in the door. I would probably use two
magnets as well — one for each direction limit which would
provide more control over the door travel. The switches
would be mounted so they could be adjusted. You might
have noticed the mounting holes allow for some
adjustment in one direction.
The example code 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
58 SERVO 11.2016
Figure 5. Power supply and stepper motor
Figure 8. Lower limit switch affixed with tape.
Figure 6. Magnetic switches and magnet.