
www.picaxe.com/products/axe171
AXE171 PICAXE-14 Audio Kit © Revolution Education Ltd 2015 v1.1
May be copied for educational use.
16
4.2.3 Calibrating the analogue sensor
When using an analogue sensor you may not always know what the correct threshold value to use.
The threshold value is normally a number that is half way between the lowest (darkest) and highest
(brightest) analogue values possible.
Fortunately the PICAXE system has a special ‘debug’ command which can transmit the value of the
variable to the computer screen. Using this command you can therefore run an experiment – for
instance using your hand to cover the LDR to calculate the highest and lowest possible values.
The threshold value to use is the value that is half way between these maximum and minimum
values.
To try this out modify the previous program by inserting an extra ‘debug’ command (found in the
Serial Commands section) after the readadc command.
Blockly
Flowchart
BASIC
symbol
varA
=
b1
do
readadc
C.4,
varA
; read ADC value on C.4
debug
; send value to computer
if
varA
>
100
then
; test value
high
B.2
; LED on
else
low
B.2
; LED off
end if
loop