RANDOM PAGE

SITE SEARCH

LOG
IN

HELP

# Picaxe LDR and LCD

This is the AQA version closing after June 2019. Visit the the version for Eduqas instead.

## The LDR

• The LDR and the 1kΩ resistor form a voltage divider.
• The output from this voltage divider is connected to the PIC chip ADC0 input.
• ADC0 measures the input voltage and converts it to a number between 000 and 255.

## A Subroutine to Convert 123 to "123"

This is a tricky concept for a programming beginner.

• The LDR sensor produces a voltage.
• The ADC converts this into a binary number like 123 = 01111011
• To display that as text, you need a "1" character, a "2" character and a "3" character.
• Writing the code to convert this is tricky.
• PICAXE BASIC has a built-in bintoascii subroutine. (Binary to ASCII)
• The ASCII code represents all the usual letters, numbers and punctuation marks on a keyboard for American English.

## Build the Circuit

Build this circuit and copy and paste the code below.

## The Code

```    setfreq m4        ; 4MHz Internal Clock

call    blank
start:

DEBUG             ; Comment this out if everything works OK

call    displayb0

jmp     start

; ==========================================
; ===== These are NOT AQA instructions =====
; ==========================================
; bintoascii converts a number like 135 into
; "1", "3", "5". These ASCII codes can be
; copied to the LCD display.
; ==========================================
displayb0:
bintoascii b0,b1,b2,b3
serout 7, N2400, (254, 128)   ' Blank First Line
serout 7, N2400, ("LDR = ",b1,b2,b3,"     ")
ret
; ==========================================
; A subroutine to blank both LCD lines.
; ==========================================
blank:
serout 7, N2400, (254, 128)   ' Blank First Line
serout 7, N2400, ("                ")
serout 7, N2400, (254, 192)   ' Blank Second Line
serout 7, N2400, ("                ")
ret
; ==========================================
```

This is not an accurate light meter but it demonstrates the principle.

This has only two "active devices" so, as it stands, it is not suitable for an A2 project.

Making an accurate light meter might be an ideal project.

reviseOmatic V3     Contacts, ©, Cookies, Data Protection and Disclaimers Hosted at linode.com, London