Raspberry Pi practice problem · Motors & actuators
Reversing beeper
MediumBudget $20Python · gpiozero
A DC motor on an L298N (IN1 GPIO5, IN2 GPIO6, ENA GPIO12), an active buzzer on GPIO23 (pi.GPIO23 >> Buzzer() >> pi.GND; it may draw up to 25 mA) and a push button on GPIO27 (to ground, Pi pull-up).
While the button is held, the motor runs backwards at 60 % (about −60 rpm) and the buzzer beeps: 0.3 s on, 0.3 s off. When it is released the motor stops and the buzzer goes silent.
Feed the driver's +12V and +5V terminals from the Pi's 5 V and join the grounds. On 5 V the bridge leaves the motor about 3 V: roughly 100 rpm at full speed, proportional to the PWM duty.
The test holds the button from 1 s to 4 s.