Basic Stamp II Project

BSII file of the code with less of the comments in the copy below


Parts List

Info Sources:  BasicStamps egroup    StampsInClass egroup   Parallax Inc(basic stamp)

The user turns it on using a slide switch which turns on a red LED and traffic light, sounds 3 warning beeps, and displays a message on the 2x16 character LCD about waiting.    User first picks whether there are one or two lines of archers then picks one of two distances for the round by pushing the corresponding button.  A timer countdown starts displaying on the LCD, a speaker beeps according to the stage of the countdown.  Green, yellow, and red LEDs AND TRAFFIC LIGHTS turn on and off to indicate what color of traffic light should be lit to cue the archers.  

This controller box interfaces with a 12 volt DC system that powers four sets of traffic lights, and could drive several more sets of lights easily.  The controller is connected to a central tower containing two sets of 12v 25w traffic lights (6 lights total) by 150 feet of category 5, 4-pair, conductor wire using RJ11 plugs.   

There is also a car horn mounted in the central tower, that is controlled manually by a push button on the timer box and powered using a 12v relay..  

A bright white LED on the timer box flashes once as a visual cue to the operator each time the horn should be sounded.  After the horn has been in use for awhile, I may elect to automate it, but initially I want the user to control it.   Of course, when I do automate it I will leave the manual method operational.

Archery Tournament Timer:

In olympic archery tournaments there are rules to the timing of the event.  From the 2000 FITA rulebook here are the rules that the timer must serve:


7.5.7 When the shooting is controlled by Lights:

RED     The Director of Shooting will give two sound signals for the designated competitors (A, B, C or AB, CD, as applicable) to occupy the shooting line all together.

GREEN     On the lights changing color 20 seconds later (10 seconds in all match competitions), the Director of Shooting will give one sound signal for shooting to begin.

YELLOW     This light will go on when only thirty (30) seconds are left.

RED     This means the Time Limit (see Article 7.5.4) is up and two sound signals will be given to indicate that shooting is to stop, even if all arrows have not been shot. Any competitor still on the shooting line is to retire behind the waiting line. The designated competitors will move up and occupy the shooting line and wait for the Green light as above for the shooting to begin: the whole procedure will be repeated as above, and so on until all have shot. When six (6) arrows are shot in two ends of three arrows, the above will be repeated before scoring. When the Red light comes on after one end of three, six (or two ends of three arrows) or nine arrows (3x3 arrows in the Team Event) according to the distances or rounds being shot three sound signals will be given for the scoring to begin.

7.5.8 Whenever the shooting line is vacated by all competitors having finished the shooting of their arrows before the end of the Time Limit, the appropriate signal for change or scoring shall be given immediately.

7.5.9 Twenty (20) seconds will be allowed for the competitors to vacate and the next designated competitors to occupy the shooting line at the beginning of each end and will, as seen under Article 7.5.7 above, be indicated by two sound signals. No competitor will occupy the shooting line except on the appropriate signal given when lights are operated.

To accomplish this, I set out to create a timer box based on a BASIC STAMP II.

It has to provide a way to time short distances and long distances, provide a countdown display, display colored LED lights and control corresponding color traffic lights that the archers use for shooting.   Stephen Swanson at Parallax Inc provided several schematic drawings and invaluable information on how to compose the hardware for this project.

Numerous people on the StampsInClass and BasicStamp newsgroup lists offered help that enabled me to succeed on this.   

Specific Thanks go to:

Bob Nicol,
MicroZed Computers
PO Box 634 [296 North Cooks Road]
ARMIDALE 2350 Phone (02) 6772 2777 [9-5 AEST]
AUSTRALIA may transfer to Mobile 0409 036 775
Facsimile (02) 6772 8987 [24hr]
web page


Dwayne Reid <>
Trinity Electronics Systems Ltd Edmonton, AB, CANADA
(780) 489-3199 voice (780) 487-6397 fax
Celebrating 16 years of Engineering Innovation (1984 - 2000)

Without the immense patience and help of these two individuals I could never have wired up the stamp as needed.  Part of the problem was that the 3 pairs of traffic light-style light bulbs were already wired up in a wooden tower 4.5 feet tall, with 3 relays encased in goop and a 12v power source, so I had to decipher how the hardware was designed before I could automate it with a basic stamp II.  The lights were controlled by a simple rotary dial switch with about 10 positions - 3 red positions, 3 green positions, 3 yellow positions, and 4 off positions.


Schematic of the design:

Basic II Code -  I opted to not worry about the size of the code and eliminated the space-saving loops of code.  This makes it easier to control what gets displayed on the LCD panel and to follow when evaluating what is happening.  BUT, I ran out of capacity on the Stamp, so I edited and cooked it down to about 54%, from 99%.  :)

In short:

There is an off/on switch for the 9 volt battery that normally supplies the stamp circuit.  This is a simple slider switch linked to a pair of the standard battery clips that usually attach to the clips on a 9v battery.   The leads have to be crossed on one of the two such clips used to keep the polarity straight as it connects to the battery and to the outlet of the stamp carrier board.  

The basic stamp II (BSII) Super Carrier board also allows the use of a wall wart power supply (12 volts DC, 500 mA output).

There are a total of FOUR push buttons SPST, NO, on the controller box.  One is labeled "SHORT" (distance) , one "LONG" (distance), one "HORN", and one is "RESET".

The reset button is linked to the RES pin of the carrier and to the ground, and when pushed resets the stamp, terminating the program and sending it to start over.  The code insures that upon reset (and when first turned on) the red light will always be displayed for archer safety.

The SHORT button is for distances of 20 and 30 meters (FITA)  and starts a loop that includes a 20 second-walk-while-red period, a 1.5 minute shoot while green period, and a 30 second shoot while yellow period.   When it starts there are two beeps on speaker and two flashes of the bright white LED to indicate ok to walk to the line, one beep/LED flash to begin the green shooting session, and finally, either 2 or 3 beeps/flashes when the yellow expires and the lights go to red.

The LONG button does the same except instead of a 1.5 minute green period there is a 3.5 minute green period.

There is a slide switch labeled "1 line 2" to indicate whether there is one line of archers, or two lines alternating.  The code beeps twice between the first and second lines, or three beeps at the end of the single & second line.  A yellow LED beside the switch lights if you choose 2 lines, and remains dark for 1 line.  

The control box has 6 leds.   There are separate green leds  beside the short & long button switches to indicate whether the short or long session has been chosen. One of these two remain lit the entire time shooting is permitted.   During the red, yellow, and green timing periods there are corresponding LEDs to display the same color.

There is a set of connections to 12 volt DC relays, which control traffic lights that the archers will refer to for timing.  Only one color of traffic light (and one corresponding color LED indicator light) can be lit at any time.

In addition to the lights, archers are conditioned to listen for audible cues as to the stage of the timing at hand.   The timer box uses a pin out from the stamp to drive a small speaker, and the speaker issues beeps and a brigh white LED flashes on and off, at the appropriate times as audible cues to the operator of the timer.  The operator can then press a large red button to close the circuit on a 12-volt car horn mounted in the central light tower to provide the audible clue.

In addition to the LEDs and the buzzer/horn, there is a 2x16 supertwist LCD display which provides messages throughout the execution of the BSII Code.   (serout commands below)

BSII code:

all text prefaced with a  '  is handled by the program as comments.  I have added excessive comments to assist you in following through the flow of code.

'Basic Stamp II program Archeryff
'this program is copyright A.Ron Carmichael, 2000. It may be used and reproduced
'noncommercially but may not be sold.

            ' 5432109876543210   this is useful to insure which pin is set how
dirs = %1111111111110000 'Define output (1) ports
outs = %0000000000000000 'Set the States of the ports (all off)
'pin 00 is a pushbutton to 5V+ with branch 10K resistor to ground (short distance)
'pin 01 is a pushbutton to 5V+ with branch 10K resistor to ground (long distance)
'pin 02 is slide switch to indicate one or two lines of archers
'pin 03 is not used
'pin 04 is not used
'pin 07 is 10 microfarad cap, 33 Ohm Resistor, and 8 Ohm speaker to ground

'pin 08 is 470 ohm resistor, green LED, to ground (short distance indicator)
'pin 09 is 470 ohm resistor, green LED, to ground (long distance indicator)
'pin 10 is output to the serial in of the LCD display, which in turn ties to both 5V+ and 5V-
'pin 11 is branched to 470 ohm to red LED to ground AND to pin 01 of a NTE2014 Darlington switch
    '(aka ULN2003).  there is a branch between pins 11 and 01 to a 10k ohm resistor to ground for this.
'pin 12 is branched to 470 ohm to yellow LED to ground AND to pin 02 of a NTE2014 Darlington switch
    '(aka ULN2003).  there is a branch between pins 12 and 02 to a 10k ohm resistor to ground for this.
'pin 13 is branched to 470 ohm to green LED to ground AND to pin 03 of a NTE2014 Darlington switch
    '(aka ULN2003).  there is a branch between pins 13 and 03 to a 10k ohm resistor to ground for this.
'pin 14 is 470 ohm resistor, bright white LED, to ground (Switch for # Lines of Archers Indicator)
'pin 15 is unused but may be used for automating the horn similarly to pin 11-13.

'RESET pin on the basic stamp is push-button switch, NO, SPST.
'Power in (Vin) uses two 9v battery adapter plugs to allow a battery to be placed in proximity to board without 'inserting onto the board's 9v sockets directly.  This makes it easier to fit into timer box and to change batteries.

'NTE 2014 - This is a ULN2003 Darlington chip, rated to accommodate up to 15v, with 16 pins. 
'Pin 01 (input) drives pin 16 output, which is a positive lead to the relay for the RED traffic light.
'Pin 02 (input) drives pin 15 output, which is a positive lead to the relay for the YELLOW traffic light.
'Pin 03 (input) drives pin 14 output, which is a positive lead to the relay for the GREEN traffic light.
'Pin 08 is connected to ground AND to pin 09 through a 15v 1W zener diode (1N4744), banded end at 09. (or you 
'can use a combination of a 10k ohm resistor and a 10 microfarad capacitor in parallel between 08 and 09)


'declare variables
swtch var byte        'indicates position of slide switch, either a 0 or a 1
Walk var byte        '20 second delay for archers to get to shooting position
shooting var byte        'displays the current seconds left to shoot prior to yellow zone
alert var byte            'yellow zone countdown value
lupe var byte        'tracks the looping for either one or two iterations/lines of archers
setswitch var byte        'allows a 5 second countdown for user to choose the # of lines
main_loop var byte        'number of seconds for the green interval during shooting, either 120 or 240
countdown var byte        ' used for counting down seconds during shooting, either 120 or 240
tempbutton var byte        'var to hold choice from button in separate memory location
SHORTLONG var byte(10) ' An array to hold the string of either short or long for the LCD to display
LETTERS var byte (2)         'array for the letter s for plural lines

' default values
main_loop = 0 'minute for main cycle
countdown = 0 'count down from
swtch = 0 'if 1 then two lines of archers controlled by switch on pin 02
endit = 0 'if > 1 then stop processing lupe

out15=1    'turn white LED on 
out11=1    'turn red LED and red traffic light on
pause 500
GOSUB BEEP     '1 beep when powered up or reset
serout 10,16468,[254,128,"Set Switch For "]
serout 10,16468,[254,192,"# Archer Lines "]
pause 2000
gosub clearscreen

for setswitch = 4 to 1    'provide 5 seconds for user to set the switch for the number of lines of shooters
serout 10,16468,[254,128,"Switch Polled In"] 
serout 10,16468,[254,192,dec setswitch , " seconds......."]
PAUSE 1000
setswitch = setswitch - 1     'decrement variable
next        'goback to the last "for" and do again if true

gosub clearscreen

IF IN2 = 0 then TWOLINES     'check slide switch and go to label for Two Lines if True otherwise next line
Swtch = 1             'set value of variable 
serout 10,16468,[254,128,"1 line selected"]         'indicate on LCD
pause 1000

TWOLINES:         'set variable to different value due to slide switch
Swtch = 2
serout 10,16468,[254,128,"2 lines selected"] 
LETTERS(0) = "s":Letters(1)=1    'make LCD display plural value of "lines" rather than "line"
pause 1000

'outs = %0000100000000000 'turn red led & light on
out15=0        'white LED off
out11=1        'red remains

gosub clearscreen
serout 10,16468,[254,128,"Choose Distance!"] 
serout 10,16468,[254,192," LONG or SHORT"]

WaitFerButton:    'wait-for-a-button-push section, then goto label shortdist or longdist
button 0,0,200,255,tempbutton,1,shortdist' wait for input on button 
'when pressed start a short distance timing loop
button 1,0,200,255,tempbutton,1,longdist 
'if pressed then this should be the long minute timing loop 
goto WaitFerButton    'repeat this wait-for-button indefinitely

SHORTDIST: '2 minute timer 
gosub clearscreen
ShortLong(0) = "S":ShortLong(1) = "h" ' Store "Short" in first 5 memory cells of variable byte
ShortLong(2) = "o":ShortLong(3) = "r"
ShortLong(4) = "t":ShortLong(9) = 5 'Put length (5) in last cell
'debug str ShortLong\ShortLong(9) ' Show "SHORT" on the PC screen.
'serout 10,16468,[254,128, str shortlong]
'pause 1000
main_loop = 120 
countdown = 120 
'outs = %0000101000000000
'Set pin 9 to turn on the 1.5 LED indicator
out9=1 'and pin 11 to turn on the RED LED indicator
out11=1 '1.5 minute cycle green LED indicator
'red LED indicator while 20 seconds elapse
'out8 = 3.5 minute LED 
goto MAIN

LONGDIST: '3.5 minute timer

ShortLong(0) = "L":ShortLong(1) = "o" ' Store "HELLO" in first 5 cells...
ShortLong(2) = "n":ShortLong(3) = "g"
ShortLong(4) = " ":ShortLong(9) = 5 'Put length (5) in last cell
'debug str ShortLong\ShortLong(9) ' Show "LONG " on the PC screen.
'serout 10,16468,[254,128, str shortlong]

' 5432109876543210
'outs = %0000100100000000
goto MAIN

FOR lupe = SWTCH to 1          'if 2 lines of archers will repeat once
gosub clearscreen
'serout 10,16468,[254,128,"Mswitch = ",dec swtch ]
'serout 10,16468,[254,192,"Mlupe = " , dec lupe ]
'pause 1000

' 5432109876543210
'outs = %0000100000000000
'Set pin 9 to turn on the 1.5 LED indicator
'and pin 11 to turn on the RED LED indicator
'1.5 minute cycle green LED indicator
out11=1 'red LED indicator while 20 seconds elapse
out15=1 'put a beep here to walk to line during 20 secs
GOSUB BEEP        'two beeps to start walking to line prior to shooting

gosub clearscreen
for walk = 19 to 1 'pause 20 secs counting 2 secs for beeps to air
pause 930 'each second of realtime takes about 930 milliseconds for the stamp, counting display efforts
'debug dec ? walk
serout 10,16468,[254,128,"Shooting ",dec swtch," Line",str LETTERS]
serout 10,16468,[254,192,"Shoot in ",dec walk," secs"," "] 'go to line two

' 5432109876543210
'outs = %1010000000000000 
out15=1        'flash the white LED to remind user to push horn
out11=0        'red out
out13=1        'green on
pause 700
out15=0        'turn white LED off

GOSUB BEEP 'one beep = start shooting
pause 700
'outs = %0010000000000000 

gosub clearscreen

for shooting = countdown to 29 
'debug dec ? shooting
pause 930
serout 10,16468,[254,128,"Shooting ", str SHORTLONG]
serout 10,16468,[254,192,dec shooting, " seconds left "]
next 'go back to for until var shooting = 1
YELLOW:        'yellow alert zone, not much shooting time left, archers must finish up!
' 5432109876543210
'outs = %0001000000000000 'Set pin 9 for 1.5 indicator and 12 for YELLOW
out13=0 'pin 13 goes OFF (GREEN)
out12=1 'don't change whichever pin is on for cycle(9 or 8) but turn yellow ON

gosub clearscreen
serout 10,16468,[254,128," YELLOW ALERT!! "]

for alert = 29 to 1 'pause 30 secs
'debug dec ? alert
serout 10,16468,[254,192," ",dec alert, " seconds left "]
pause 930 

if lupe = 2 then AGAIN      'label again has two beeps then back to main 
' 5432109876543210
out12=0    'turn yellow led/light off
out11=1    'turn red led/light on
out15=1 'turn red led & red light and HORN lights on 
gosub BEEP
out15=0 'horn light off
out15=1 'horn light on
out15=0 'horn light off
out15=1 'horn light on
out15=0 'horn light off
gosub clearscreen
serout 10,16468,["Shooting Done "]
pause 2000

AGAIN: 'go again for next line of archers
' 5432109876543210
'outs = %1000100000000000 'turn red led & light on
gosub clearscreen
serout 10,16468,[254,128," Line Done "]
pause 100
gosub clearscreen

NEXT 'first shooting line is done, shoot second by returning to MAIN

'these are subroutines which save lots of space in code

serout 10,16468,[254,1] ' clear screen

Freqout 7,700,2500,3500

Freqout 7,200,0

The category 5 wire used to connect the controller box to the light tower is about 150 feet long, wound onto a wire spool keeper, with RJ11 jacks at each end.  One jack fits into the socket on the controller, and the other fits onto a socket at the tower.   Each end must be staked down securely during tournaments to insure that an archer doesn't trip over the wire and rip the wire out of the jack.   The jack uses 3 pair of the 4 pair currently, with the final pair reserved for a future enhancement (lighted indicator for which line of archers is up next, either AB or CD). 

The inner four wires are used for the lights, and the outer wire on each side is used in the loop for the horn.   The four inner wires must reverse.   If one jack is viewed from above, and the wires are Green/Blue/BluWhi/Orange/OrWhi/GreeWhi ,   then the other clip, viewed in the same perspective, must be

Green/OrWhi/Orange/BluWhi/Blue/GreeWhi . 

In the controller box, the socket  is wired using the same color scheme as the light tower, and the four primary color wires conform to the color of the lights - red, green, yellow, and black to ground.   The two other wires on the jack are blue and white.  In the controller box these two wires link directly to a SPST, NO, push button labelled HORN.  In the future, I may wire those same two wires ALSO or INSTEAD to another pin on the NTE2014 Darlington, and control it via the stamp.   I foresee that the operator will need to be able to sound the horn at will to interrupt shooting if necessary.  If I don't isolate the surge properly, though, the horn might cause the stamp to reboot.


back to home page