Raspberry Pi practice problem · Motors & actuators
Siren
MediumBudget $3Python · gpiozero
A passive buzzer on GPIO18, with a series resistor that keeps the pin under 16 mA (220 Ω does it). Make it wail like a siren: sweep the pitch up from 600 Hz to 1200 Hz over 1 s, jump back to 600 Hz and repeat, forever.
Change the frequency in small steps (e.g. 600, 650, … 1200 Hz: 13 steps of 1/13 s each) — pwm.ChangeFrequency(f) on an RPi.GPIO.PWM running at 50 % duty does it.
The test checks the pitch stays within 600–1200 Hz (±20 Hz), that every 1.2 s span reaches both below 700 Hz and above 1100 Hz, and that the top of the sweep comes round once a second.