Photoresistor sensor module

A light-dependent resistor on the four-pin LM393 comparator board.

Aliases: photosensitive sensor module, LDR module, light sensor module, Wokwi's photoresistor sensor.

It gives the light two ways: AO, a voltage that falls as the light rises, and DO, the board's own comparator against the blue trimmer, high in the dark and low in the light. One for measuring, one for switching.

Pins

Pin What it does
VCC Supply, 3.3 to 5 V.
GND Ground.
DO Digital out: high when it is darker than the trimmer's setting, low when lighter.
AO Analog out: the LDR under a 10 k resistor, lower in more light.

Properties

threshold is the trimmer, as a fraction of the supply (0.5, about 100 lux, by default). rl10 is the cell's resistance at 10 lux in kilohms (50) and gamma the slope of its curve (0.7). lux is the light it starts in (500); the slider moves it while the sketch runs.

While it runs

The slider is the light on the cell. The DO lamp lights while DO is low, in the light.

Reading it on an Arduino

int light = analogRead(A0);            // lower is brighter
bool dark = digitalRead(2) == HIGH;    // the trimmer decides

What the model gets right

The divider. 10 k from VCC to AO and the cell from AO to ground, so AO is the supply times R / (R + 10 k), and it drives that voltage with the divider's own source resistance.

The cell's curve, R = rl10 x (10 / lux) ^ gamma, a megohm in the dark: 50 k at 10 lux, about 10 k at 100 lux, where AO crosses half the supply.

The comparator. The LM393 compares AO with the trimmer and pulls DO low through its open collector while AO is below it; high is the board's 10 k pull-up. That is the same board the flame and rain sensors stand on.

What it does not model

The cell's response time and light history, the LM393's lack of hysteresis (a real board chatters with the light right at the threshold), and color: lux here is the eye's lux.

Common mistakes

Expecting AO to rise with the light: on this module it falls.

Reading DO with analogRead: it is 0 or the supply, nothing between.

See it in action

Dusk switch turns a lamp on at dusk. Open it at /templates.