
16
PICAXE-08 ALARM PROJECT
revolution
© copyright 2002 - AXE102 Alarm Student Project Notes Version 1.1
Revolution Education Ltd. Email: [email protected] Web: www.rev-ed.co.uk
16
Supported by:
Using switches
A switch is used with a resistor as shown in the diagram. The
value of the resistor is not that important, but a 10k resistor
is often used. When the switch is 'open' the 10k resistor
connects the microcontroller input pin down to 0V, which
gives an off (logic level 0) 0V signal to the microcontroller
input pin.
When the switch is activated, the input pin is connected to
the positive battery supply (V+). This provides an on (logic
level 1) signal to the microcontroller.
Testing the switch
After connecting the switch it can be tested by a simple program like this. This program
will switch an output on and off according to if the switch is pushed or not.
main:
make a label called main
if input3 is on then flash
jump if the input is on
goto main
else loop back around
flash:
make a label called flash
high 0
switch output 0 on
wait 2
wait 2 seconds
low 0
switch output 0 off
goto main
jump back to start
In this program the first three lines make up
a continuous loop. If the input is off the
program just loops around time and time
again.
If the switch is then pushed the program
jumps to the label called
‘flash’
. The
program then flashes output 0 on for two
seconds before returning to the main loop.
Note carefully the spelling in the
if…then
line –
input3
is all one word (without a
space). You can use the word
pin3
or
input3
to mean the same thing. Note also that only
the label is placed after the command
then
– no other words apart from a label are
allowed at this point.
V+
0V
10k
Pin
start
high 0
low 0
pin3=1
Y
N
wait 2