Photoresistor (LDR)

A photoresistor is a resistor that lets less current through in the dark and more in the light; with one fixed resistor it measures brightness.

Sensors8 blocksMicroPythonC++
Photoresistor

At a glance

Pins and properties exactly as the circuit editor and simulator define this part. The text below explains how to use them.

Pinout

Pinout of the Photoresistor, drawn as in the circuit editor. Select a label to see that pin in the table below.

Pins

Pins of this part
PinLabelType
11Signal in
22Signal in

Properties

What you can change in the Property Inspector.

Properties of this part
PropertyRange or choicesDefault
Light Level0 to 1023512

A photoresistor (LDR, light-dependent resistor) changes its resistance with the light that falls on it. The simulated part follows a real GL5528 cell: about 1 MΩ in the dark and about 8 kΩ in bright light, on the power-law curve real cells have (it is a straight line on a log-log graph, not a straight line in brightness).

Wiring: a voltage divider

A board reads voltages, not resistances, so the photoresistor is used with a fixed resistor (around 10 kΩ):

  1. One leg of the photoresistor to 3V3 (or 5 V).
  2. The other leg to an analog input pin and, from the same point, a fixed resistor to GND.

With this arrangement the voltage on the pin rises with brightness, and the blocks treat a higher reading as brighter. Swapping the two parts reverses the direction.

Light level in the simulator

Drag the Light Level property (0 to 1023) to change the light on the part while the simulation runs.

Blocks

Drawing the blocks…

Troubleshooting

  • The reading never changes: check that the fixed resistor goes to GND and the pin is analog-capable.
  • Dark and bright are swapped: the two parts of the divider are the wrong way round.
  • It flickers around a threshold: use two different thresholds (one to switch on, one to switch off) so small changes do not toggle the result.