Light sensing with an LDR
Your first real sensor, and the same divider from PRP 1 with one leg that changes on its own.
- Wire the LDR as one leg of a divider with a fixed resistor.
- Read it into the board and print the value to the serial monitor.
- Record readings in three conditions: covered, room light, and a torch on it. Write the numbers down.
- Change the fixed resistor to a different value and repeat all three. The readings will change.
- Decide which fixed resistor gives the most useful spread for the conditions you care about, and say why. This is a design decision.
- Calibrate. Using a light meter or a phone app as a reference, work out roughly what your numbers correspond to in real units.
What you'll learn
Convert a physical quantity into a number, and choose circuit values that make that number useful.
What you'll make
I chose a fixed resistor deliberately and justified it with my own readings.
What you need
LDR, resistor kit, breadboard, board, USB cable.
Build it up — 8 steps
Sample code
// PRP 3 — light sensing with an LDR.
// Wire the LDR and a fixed resistor as a divider, junction to A0.
const int LDR_PIN = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int reading = analogRead(LDR_PIN); // 0-1023, NOT a light level yet
Serial.println(reading);
delay(1000);
}
Quick chips
IPO chart
Inputs
- Ambient light falling on the LDR
Processing
- The LDR's resistance falls as light rises, changing the divider output; the ADC converts that voltage to a number 0-1023
Outputs
- A stream of readings on the serial monitor
Stuck? Common things to check Tap to open
That the ADC number is the measurement. It is a voltage, until calibrated.
Take it slower
Provide the sample sketch and two resistor values to compare, rather than asking the student to select from the whole kit.
Push further
Characterise the LDR across ten light levels and plot resistance against illuminance. Is it linear? Most students assume it is.
Done when…
Readings in three conditions for two different fixed resistors, plus a justified choice.
Reflect
What does your sensor read when nothing is changing, and how steady is it?