SunFounder ESP32 Starter Kit
import machine
import time
# Create a Pin object representing pin 14 and set it to output mode
buzzer = machine.Pin(14, machine.Pin.OUT)
# Enter an infinite loop
while True:
# Iterate over the values 0 to 3 using a for loop
for i in range(4):
# Turn on the buzzer by setting its value to 1
buzzer.value(1)
# Pause for 0.2 seconds
time.sleep(0.2)
# Turn off the buzzer
buzzer.value(0)
# Pause for 0.2 seconds
time.sleep(0.2)
# Pause for 1 second before restarting the for loop
time.sleep(1)
When the script is running, the buzzer will beep quickly four times every second.
3.15 3.2 Custom Tone
We have used active buzzer in the previous project, this time we will use passive buzzer.
Like the active buzzer, the passive buzzer also uses the phenomenon of electromagnetic induction to work. The differ-
ence is that a passive buzzer does not have oscillating source, so it will not beep if DC signals are used. But this allows
the passive buzzer to adjust its own oscillation frequency and can emit different notes such as “doh, re, mi, fa, sol, la,
ti”.
Let the passive buzzer emit a melody!
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
ESP32 Starter Kit 320+
You can also buy them separately from the links below.
3.15. 3.2 Custom Tone 339