05 / 20
Sound a siren
Sweep a passive buzzer between two frequencies.
Run this experiment →Why it’s here
Set the low and high tones, enable audio, and listen to the sweep.
How it works
Sweep a passive buzzer between two frequencies. The pitch rises. Frequency is measured in hertz; loudness is a separate property. This guided model targets the original ESP32 and Arduino-ESP32 3.x; radio, acoustics, loads and mechanics are simplified.
Try it
- Open this experiment
- Set the low and high tones, enable audio, and listen to the sweep.
Connections
- GPIO 25 / GND — Passive buzzer
Example sketch
void setup() {
ledcAttach(25, 1000, 8);
}
void loop() {
float phase = (millis() % 2000) / 2000.0f;
float sweep = 1 - abs(2 * phase - 1);
ledcWriteTone(25, 440 + sweep * (880 - 440));
}Check your understanding
What does a higher frequency change?
Show the answer
The pitch rises. Frequency is measured in hertz; loudness is a separate property.