Raspberry Pi practice problem · Sensors
Who goes there?
EasyBudget $6Python · gpiozero
A PIR motion sensor with OUT on GPIO4 (power it from 5 V). Wait for the first motion, then print when it happened, in seconds since power-on with one decimal, and stop:
Motion after 3.0 s
time.monotonic() counts seconds since power-on, and gpiozero's MotionSensor.wait_for_motion() blocks until OUT goes high. The test walks past at 3 s and again at 8 s — print only once. (The PIR samples every 0.1 s, so 3.0 or 3.1 are both right.)