LDR (Light Dependent Resistor)

A Light Dependant Resistor (LDR) is a resistor that changes in value according to the light falling on it. An LDR commonly has a high resistance in the dark, and a low resistance in the light.

By placing the LDR as the top or bottom resistor in a potential divider circuit varying light level can be turned into varying voltages which a PICAXE can read.

Related Commands:

Print Page

Share

Schematic

PCB

Reading an LDR light level

The following program will read the LDR light level value and display it as the contents of the 'b1' variable.

Code Example:
main:	readadc C.0, b1		; read the value
	debug			; show the value read
	pause 1000		; wait a short while
	goto main		; repeat
Copy Code Submit an Example

Light level indicator

This program will read the LDR value and, depending on that value, will light one of three LEDs to indicate what light level range it is in.

Code Example:
main:	readadc C.0, b1		; read the value
	if b1 < 100 then light1 ; range 0-100   = 1
	if b1 < 145 then light2 ; range 100-145 = 2
	if b1 < 175 then light3 ; range 145-175 = 3
	goto main

light1:	high B.1		; switch on  LED 1
	low  B.2		; switch off LED 2
	low  B.3		; switch off LED 3
	goto main		; loop

light2:	low  B.1		; switch off LED 1
	high B.2		; switch on  LED 2
	low  B.3		; switch off LED 3
	goto main		; loop

light3:	low  B.1		; switch off LED 1
	low  B.2		; switch off LED 2
	high B.3		; switch on  LED 3
	goto main		; loop
Copy Code Submit an Example

Create Module

The LDR create module provides an analogue input signal to the PICAXE on the motherboard which varies as brightness changes.

Bill of Materials

DescriptionCodeQty
Miniature light dependant resistor SEN002 1 Buy Now
10k resistor (pack 100) RES10K 1 Buy Now

Simulation

No Image Selected

Submit Your Own Code!

You must be logged in to submit code examples. Login now.