26 SERVO 12.2015
which alters its actions depending on your distance from it.
Steve O’Conner, the creator of the Garage of Evil website,
has done a wonderful job designing the project which
makes it straightforward to build. If you would like to see
his box in action, view it at http://tinyurl.com/oc6wmlk.
I have not had much experience using the BASIC
Stamp, but thought this would be a great project as Steve
had already completed the programming work. It was
simply a case of copying and pasting the code (see Sidebar
2) into the free editor software (see Resources) and
downloading it into the chip.
I used the Stamp 2 carrier board (see Resources) and
used a small add-on board from my parts bin for the servo
and sensor. It runs on a separate 5V power supply and was
e quickest way for me to get this project up and
running (do not forget to link the grounds between
the two boards). If I were to do it again, I would use
the Super Carrier Board (see Resources) that allows
for dual power supplies and has a layout that makes
adding the necessary header connections for the
servo and sensor a breeze.
I modified Steve’s design a bit and used a small
mailbox for my project. For the hardware portion of
the build, I used the Parallax Ultrasonic Sensor Kit (see
Resources). I used standoffs to mount the boards and
servo onto a piece of scrap plastic which was then installed
inside a mailbox.
The servo was mounted using some mounting brackets
from ServoCity ( http://tinyurl.com/nfuegep; Figure 6). I
then attached a piece of 2/56 threaded rod with a ball and
socket to the servo horn. I used a ball linkage on the other
end which was connected to the lid of the box with a bolt
and nylon lock nut. A couple of small holes were then
drilled to accommodate the sensor which was attached to
the box using the mounting bracket that was included in
the kit. One more hole was drilled in the back side of the
mailbox to accommodate the power cord.
All that was left to do then was to find an appropriate
DIY Animatronics
' {$STAMP BS2}
' {$PBASIC 2. 5}
' {$PORT COM6}
'---------variables-----------------------------------lid_servo VAR Word
repeat VAR Byte
rawDist VAR Word
inches VAR Word
'---------pins------------------------------------------Ping PIN 2
servo1 PIN 0
'---------constants----------------------------------Sonar CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
Baud CON $8000 | 6
RawToIn CON 889 ' 1 / 73.746 (with **)
Raw ToFt CON 889 / 12
'---setup--screen-----
'---------program-----------------------------------main:
GOSUB Get_Sonar ' get sensor value
inches = rawDist Raw ToIn ' convert to inches
DEBUG CRSRXY, 20, 3, DEC inches, CR
IF inches < 40 AND inches > 10 THEN GOSUB
move_servo
IF inches < 8 THEN GOSUB close_lid
GOTO main
move_servo:
lid_servo = inches 30 MAX 1050 MIN 300
FOR repeat = 0 TO 4
PULSOUT 0, lid_servo
PAUSE 12
NEXT
DEBUG DEC lid_servo
PAUSE 20
DEBUG CLS
RETURN
close_lid:
FOR repeat = 0 TO 5
PULSOUT 0, 240
PAUSE 15
NEXT
RETURN
Get_Sonar:
Ping = 0 ' make trigger 0-1-0
PULSOUT Ping, Sonar ' activate sensor
PULSIN Ping, 1, rawDist ' measure echo pulse
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
RETURN
SIDEBAR 2
Figure 6.