Back to the lesson

Build yours at home

Light sensor

What we're doing

Build a light sensor (light sensor) from the kit. More light on it lets more electricity through, so the LED glows brighter. Then, if you like, watch its number on a computer.

About 20 minutes. Plus 20 for the number version.

Goes with these lessons

No kit? Try this

Get a solar garden light. In daylight, cover its top with your hand. It switches on, because its solar panel doubles as a light sensor and thinks it's night.

Get these parts

New to breadboards? See Getting set up
  • 4×AA battery holder with a switch (electronics shop or online)
  • One photoresistor, one LED, one 220 Ω resistor, the breadboard and jumper wires (Elegoo kit)
  • A flashlight (a phone light works) (household)
  • For the number version: the Mega, its USB cable and one 10k resistor (Elegoo kit), and a computer with the Arduino app Computer (household)

Fill each holder with the matching number of AA batteries (household).

Keep it safe

Battery power only, never household power. Use AA packs matched to the parts, not a 9V battery. A grown-up connects and disconnects the pack. Stop immediately if any part warms. Never join the pack's two metal ends: the wires can get hot. Coin cells stay with grown-ups, locked away. CPSC warns a swallowed button or coin cell can burn through a child's throat in about two hours; suspected swallowing needs emergency medical care immediately.

A grown-up handles the Mega, the USB connection and all sketch uploads. The board stays on a dry, non-metal table while it is plugged in.

Steps

  1. 1

    With the switch off, push the battery's red wire into the + line and its black wire into the − line.

  2. 2

    Push the photoresistor's legs into two empty rows. Add a jumper from the + line to its first row.

  3. 3

    Push the LED's long leg into the photoresistor's second row and its short leg into an empty row.

  4. 4

    Put the 220 Ω resistor from the LED's short-leg row to the − line.

  5. 5

    Switch on. Shine the flashlight on the sensor: the LED glows. Cover the sensor: it goes dark. More light, more electricity through.

    Not working? Turn the LED round. A dim room isn't enough: use the flashlight.

  6. 6

    Switch off and take the parts out.

  7. Number version (grown-up, needs Getting set up)

    7

    Push the photoresistor's legs into two empty rows. Add a jumper from the Mega's 5V pin to the first row, and one from the second row to pin A0.

  8. 8

    Put the 10k resistor from the second row into an empty row. Add a jumper from that row to a GND pin on the Mega.

  9. 9

    Plug in the USB cable and upload the sketch below. Then choose Tools → Serial Plotter.

  10. 10

    Cover the sensor, then shine the flashlight. The line drops near 0 in the dark and climbs with more light.

  11. 11

    Unplug the USB cable.

Talk while you build

  • What changes when you cover the light sensor?
  • What happens when you shine the flashlight on it?

Spot it at home

  • Phone screens that dim in the dark, streetlights that switch on at dusk, solar garden lights that come on at night.

How does the streetlight know it's night?

Light sensor sketch · prints the reading to the Serial Plotter

// Light sensor: print the sensor's reading so kids can watch it change.
// Wiring: photoresistor between 5V and A0, 10 kΩ resistor from A0 to GND.
const int EYE_PIN = A0;

void setup() {
  Serial.begin(9600);  // then open Tools -> Serial Plotter
}

void loop() {
  int reading = analogRead(EYE_PIN);  // 0 = dark, 1023 = bright
  Serial.println(reading);            // one number per line
  delay(100);                         // ten readings a second
}