Project 02 · Photoresistor
Light as a voltage.
Analog input, a voltage divider, and a screen that brightens with the room. Cover the LDR with a notebook; the bar should collapse.

Bright light → LDR resistance falls → analog value climbs toward 1023. Darkness does the opposite. Students should predict the number before covering the cell.
const int sensorPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int lightValue = analogRead(sensorPin);
Serial.println(lightValue);
delay(200);
}import processing.serial.*;
Serial myPort;
int lightLevel = 0;
void setup() {
size(420, 220);
myPort = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
float shade = map(lightLevel, 0, 1023, 20, 240);
background(shade);
fill(lightLevel > 500 ? 20 : 240);
textSize(20);
text("Light intensity: " + lightLevel, 40, 48);
fill(0, 100, 255);
rect(40, 90, map(lightLevel, 0, 1023, 0, 320), 32);
}
void serialEvent(Serial p) {
String val = p.readStringUntil('\n');
if (val != null) {
val = trim(val);
if (val.matches("\\d+")) lightLevel = int(val);
}
}Basic Print the number.
Intermediate Proportional bar.
Advanced Background color tracks light.
Challenge Night-light LED on the Uno, or a timestamped log.
| Stuck at | Check |
|---|---|
| 0 forever | Open circuit / LDR not in the divider |
| 1023 forever | Missing 10kΩ or missing GND |
| Jitter | Loose breadboard; average a few samples if needed |
