Arduino: Zero to First Project · EPISODE 4 · 2:45

Read a Light Sensor + the Serial Monitor

Give your Arduino eyes! Wire a light sensor (LDR), read it with analogRead, and watch the numbers live in the Serial Monitor — cover it with your hand and the numbers fall, shine a torch and they jump. Explained from zero, in under 3 minutes.

// CHAPTERS · TAP TO JUMP
// IN THIS EPISODE

What you'll learn

  • A light-dependent resistor (LDR): a few thousand ohms in bright light, close to a million in the dark.
  • The Arduino reads volts, not ohms — so the sensor goes in a chain with a 10 kΩ resistor from 5 V to ground (a voltage divider). The middle point goes to pin A0. More light → lower resistance → more volts at A0.
  • digitalRead gives 2 answers (HIGH / LOW). analogRead(A0) gives a number from 0 to 1023: 0 V → 0, 5 V → 1023, 2.5 V → about 512. That's 1,024 steps of about 4.9 mV each.
  • The code:
    void setup() { Serial.begin(9600); }
    void loop() { int light = analogRead(A0); Serial.println(light); delay(100); }
  • Serial.begin(9600) sets the talking speed: 9600 bits a second. Upload, then click the magnifier icon (top right) to open the Serial Monitor and set it to 9600 baud too. About 10 numbers a second scroll in.
  • Cover the sensor → the numbers drop. Shine your phone's flashlight → they jump up.
  • Weird junk characters? The speeds don't match — set both to the same number.
// 30-SECOND SHORTS ON THIS

Quick refreshers