PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Sensors

Dark timer

MediumBudget $8Python · 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; below 0.5 is dark. Each time the light comes back after a dark spell, print how long it was dark, with one decimal:

Dark for 3.0 s

The test switches the light off from 2 s to 5 s and from 7 s to 8.5 s. Read at least every 0.05 s (an answer within 0.1 s is fine).

More in Sensors