Controlling Buzzers with the Raspberry Pico device and Python code
Controlling the frequency and duty cycle of the buzzer via python code
A buzzer has just two wires the negative and positive, it can be used for creating beeps and tones using the PWM signals to generate different tones based on the frequency set and duty cycle.
The frequency changes the tone of the buzzer from 0 to 10000, and the duty cycle sets the volume of the buzzer, 0 to 65535.
To silence the buzzer set the duty to 0.
The negative goes to ground and the positive to GPIO13.
from machine import Pin, PWM
import time
buzzer = PWM(Pin(13))
buzzer.freq(1000)
buzzer.duty_u16(10000)
time.sleep(0.5)
buzzer.duty_u16(0)
And here is it for you to hear in all its glory.