
www.picaxe.com/products/axe171
AXE171 PICAXE-14 Audio Kit © Revolution Education Ltd 2015 v1.1
May be copied for educational use.
15
4.3.2 Using an LDR with a PICAXE microcontroller.
The electronic circuit for using the LDR is known as a ‘potential divider’. A
suitable value for the lower resistor is 10k. The voltage at the centre
position of the potential divider varies as the resistance of the LDR changes
in different light conditions.
The microcontroller contains an 'analogue to digital converter (ADC)' which
converts the varying voltage signal into a number between 0 and 255. This
number can then be stored in a variable and compared against a desired
‘threshold point’.
4.2.3 Testing the LDR
The AXE171 project board has an LDR on:
Input C.4
Therefore make sure the correct pin number is selected within each PICAXE command.
This program will switch an output on and off according to whether the light level is greater than
100. But who do you know 100 is the correct threshold value to use? See the next section…
Blockly
Flowchart
BASIC
symbol
varA
=
b1
do
readadc
C.4,
varA
; read ADC value on C.4
if
varA
>
100
then
; test value
high
B.2
; LED on
else
low
B.2
; LED off
end if
loop