Raspberry Pi practice problem · Sensors
Desk occupancy
HardBudget $8Python · gpiozero
An HC-SR04 (TRIG GPIO23, ECHO GPIO24 through a divider, or the 3.3 V-safe module) under a desk, and a green LED on GPIO17 meaning "occupied". Someone at the desk reads under 80 cm. But people walk past and sitters lean back, so:
- become occupied only after the reading has stayed under 80 cm for 1 s;
- become free only after it has stayed at 80 cm or more for 3 s.
Start free. Print PRESENT / AWAY on each change (not at start-up) and keep the LED lit while occupied.
The test: someone walks past (1.0–1.5 s), sits down at 3 s, leans back out of range from 6 s to 7.5 s, and leaves at 10 s. Read at least every 0.1 s.