EasyManua.ls Logo

Revolution PICAXE-08 - Testing LDR Inputs; Digital and Analogue LDR Test Procedures

Revolution PICAXE-08
38 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
19
PICAXE-08 ALARM PROJECT
revolution
© copyright 2002 - AXE102 Alarm Student Project Notes Version 1.1
Revolution Education Ltd. Email: info@rev-ed.co.uk Web: www.rev-ed.co.uk
19
Supported by:
Testing the LDR (digital)
After connecting the LDR it can be tested as a
digital switch by a simple program like this:
main:
if input1 is on then dohigh
low 0
goto main
dohigh:
high 0
goto main
This program will switch output 0 on and off according to the light level.
Testing the LDR (analogue)
After connecting the LDR it can be tested
as an analogue sensor by a program like
this:
main:
readadc 1,b1
if b1 > 100 then do4
if b1 > 50 then do0
low 0
low 4
goto main
do4:
high 4
low 0
goto main
do0:
high 0
low 4
goto main
The ‘readadc’ command is used to read the analogue value (a number between 0 and
255) into variable b1. Once the number is in variable b1 it can be tested to see if it is
greater than 100 or greater than 50. If it is greater than 100 output 4 is switched on, if it is
between 50 and 100 output 0 is switched on, and if it is less than 50 both outputs are
switched off.
start
high 0low 0
pin1=1
Y
N
start
readadc 1,b1
b1> 100
Y
N
b1> 50
Y
N
high 0 high 4low 0
low 4 low 4 low 0