Passive buzzer A passive buzzer requires an AC signal to make a sound. It is like an electromagnetic speaker, where a changing input signal produces the sound, rather than producing a tone automatically.
Active buzzer The active buzzer has a built in oscillating source that will make a sound when amplifying a power compare to passive buzzer does not have such a source so it means that no beep or sound will generate when it plug to the power source on this case you need to use a square wave frequency to make a sound between 2k and 5k.
from gpiozero import Buzzer
from time import sleep
buzzer = Buzzer(17)
while True:
buzzer.on()
sleep(1)
buzzer.off()
sleep(1)
while True:
buzzer.beep()
Reference adafruit
and code
#Libraries
import RPi.GPIO as GPIO
from time import sleep
#Disable warnings (optional)
GPIO.setwarnings(False)
#Select GPIO mode
GPIO.setmode(GPIO.BCM)
#Set buzzer - pin 23 as output
buzzer=23
GPIO.setup(buzzer,GPIO.OUT)
#Run forever loop
while True:
GPIO.output(buzzer,GPIO.HIGH)
print ("Beep")
sleep(0.5) # Delay in seconds
GPIO.output(buzzer,GPIO.LOW)
print ("No Beep")
sleep(0.5)