PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Sensors

No flicker

MediumBudget $9Python · gpiozero

An LDR on top of a 10 kΩ divider into channel 0 of an MCP3008 (or the light sensor + ADC board): brighter means a higher reading. A night light LED on GPIO17.

A single threshold makes a night light flicker at dusk. Use hysteresis instead:

  • switch the LED on when the reading drops below 0.3,
  • switch it off when the reading rises above 0.5,
  • in between, leave it as it is.

The test: bright at first (reading ≈ 0.95), dusk at 2 s (≈ 0.44), night at 4 s (≈ 0.20), dusk again at 6 s, bright at 8 s. So the LED is off until 4 s, on from 4 s to 8 s, and off after.

More in Sensors