ESP32-S3 Lab · Day 10 of 30

Give the board
a voice

Today the board makes sound. You wire an active buzzer through a small transistor, add a push button, and upload a sketch that beeps the instant you press — a doorbell you built yourself. The beep is worth understanding: sound is air pushed rapidly back and forth, and how many pushes a second is the pitch you hear. An active buzzer fixes that number itself; a passive buzzer hands it to you to set.

About 25 minutesArduino firstMicroPython optionalNo electronics assumed
Agent assist code TSK-DAY10-BUZZER

Hand this to an agent so it can pull the lesson packet and coach you step by step.

01 First, know the pieces

What you need

Nine things, most of them tiny. Tap Define on any part you haven't met — the answer opens as a field note you can read and dismiss without losing your place.

Official manual photo of the ESP32-S3 development board.
Manual photo

ESP32-S3 board

The brain that runs your uploaded sketch.

Official manual image of the ESP32-S3 GPIO extension board.
Manual photo

GPIO extension board

Spreads the pins into rows you can reach and label.

Official manual photo of a small round active buzzer.
Manual photo

Active buzzer

Makes one fixed tone whenever it gets power.

Official manual photo of an NPN transistor with three legs.
Manual photo

NPN transistor

A tiny switch the pin controls to drive the buzzer.

Official manual photo of a four-pin push button switch with its pin pairs labelled 1 and 2.
Manual photo

Push button

A four-pin switch that closes the circuit when pressed.

Official manual photo of a resistor with coloured value bands.
Manual photo

1 kΩ resistor

Sits between the pin and the transistor's base to keep the current gentle.

Official manual photo of a resistor with coloured value bands.
Manual photo

2 × 10 kΩ resistors

Hold the button's pin at a steady level until you press.

Official manual image of a jumper wire.
Manual photo

Jumper wires

Temporary, solder-free connections.

Official manual screenshot of the Arduino IDE interface.
Manual screenshot

Arduino IDE

Uploads the sketch to the board.

02 Make the physical circuit

Chart the circuit

The official Freenove diagram is your chart — schematic on top, the same circuit built on a breadboard below. Click it to enlarge. Each connection tells you where the wire goes and why.

Official Freenove circuit — C Tutorial, Chapter 6 (Buzzer), page 80.
Buzzer + 5V rail The buzzer draws more current than a pin can give so it runs off 5V.
Transistor base (via 1 kΩ) GPIO 14 The pin switches the buzzer through the transistor.
Push button GPIO 21 The board reads this pin to catch the press.
10 kΩ resistor 3.3V Holds GPIO 21 HIGH until a press pulls it LOW.

Mind the transistor's legs. The transistor's three legs have their own jobs — emitter, base, and collector — so get them the right way round against the chart. Unplug USB before you move any wire.

03 One action at a time

Build it

This is the main path — you can finish the day without opening a single field note. Tap each step as you go to keep your place.

0 / 8 done
  1. Seat the ESP32-S3 on the GPIO extension board and keep USB unplugged while you wire.

  2. Place the transistor on the breadboard and note its three legs — emitter, base, and collector.

  3. Wire the buzzer's + pin to the 5V rail and its other pin down to the transistor.

  4. Connect the transistor's base to GPIO 14 through the 1 kΩ resistor.

  5. Wire the push button so one side reaches GPIO 21, then add its 10 kΩ pull-up to 3.3V.

  6. Compare every wire to the chart before you plug in USB.

  7. Open Sketch_06.1_Doorbell.ino in Arduino IDE and upload it.

  8. Press the button and listen.

The board can speak.

Press for a beep, release for silence — your first doorbell. Head to Test & debug to confirm the sound.

04 Read just enough code

Read the code

The whole sketch is short. Two lines set the pins up; the loop just asks the button and answers with the buzzer. Switch to MicroPython if you'd rather see the same idea in Python — the wiring never changes.

Sketch_06.1_Doorbell.ino
#define PIN_BUZZER 14
#define PIN_BUTTON 21

void setup() {
  pinMode(PIN_BUZZER, OUTPUT);
  pinMode(PIN_BUTTON, INPUT);
}

void loop() {
  if (digitalRead(PIN_BUTTON) == LOW) {
    digitalWrite(PIN_BUZZER, HIGH);   // pressed -> beep
  } else {
    digitalWrite(PIN_BUZZER, LOW);    // released -> silent
  }
}
digitalRead(PIN_BUTTON) == LOWTrue only while the button is held — a press pulls GPIO 21 LOW.
digitalWrite(PIN_BUZZER, HIGH)Sends the pin HIGH, which switches the buzzer on through the transistor.
ledcWriteTone(channel, freq)The passive-buzzer variant (Sketch_06.2_Alertor) uses ledcWriteTone to choose the pitch and sweep a siren.

05 Understand, don't memorise

What sound is, and why pitch is frequency

Today's doorbell uses an active buzzer, which plays one fixed note. The idea worth carrying is what that note actually is, because the passive buzzer later lets you choose it. Sound is moving air, and the pitch you hear is a number.

Air

Sound is vibration

A buzzer holds a thin disc that snaps back and forth, shoving the air in front of it. Each full back-and-forth is one cycle, and your ear reads a stream of those pushes as a sound rather than separate clicks.

Rate

Pitch is frequency

How many cycles happen each second is the frequency, measured in hertz. More cycles a second arrives as a higher note, fewer as a lower one, so the pitch is simply a count you can name and set.

Active

Its own oscillator

An active buzzer carries a tiny oscillator inside that vibrates the disc at one built-in rate, so bare power plays one set note. That is the beep in today's doorbell, and why the pin only has to switch it on or off.

Passive

You set the rate

A passive buzzer has no oscillator and stays silent on steady power. The pin has to switch it on and off itself, and how fast it does that becomes the pitch. The frequency you drive it at is the frequency you hear.

Notes

Music is frequencies

A musical note is a named frequency: 262 Hz is a middle C, 392 Hz is the G above it, 440 Hz is the A an orchestra tunes to. Feed those numbers to a passive buzzer and it plays them; tone() generates exactly that.

The model on/off cycles per second = frequency = pitch (Day 7 varied on-time for brightness; here the rate sets the note)

The tie back to Day 7

Day 7's pin also flicked far too fast to watch, and its duty cycle, the share of each cycle held on, set the brightness. Here the duty stays near half and the frequency is the knob, so the same fast-switching pin makes pitch instead of light.

Why the active buzzer ignores all this

Its built-in oscillator fixes its own pitch, so switching it faster from the pin just chops the same note on and off. Only a passive buzzer hands you the frequency, which is why melodies and sirens need the passive kind.

Where the transistor fits

The pin still can't supply the buzzer's current, so it switches a transistor and the transistor drives the 5V buzzer. The pin decides on or off; the transistor does the lifting.

06 Know it worked

Test & debug

Nothing prints to the screen today — the proof is the sound under your finger.

What you should hear
Buzzer
  • Press and hold the button — a steady beep sounds at once.
  • Let go — silence.
  • Every press sounds the same note, for as long as the board has power.

An active buzzer plays one fixed tone — choosing the pitch is the passive-buzzer variant's job.

If it doesn't
  • No sound at all? Check the transistor legs are the right way round, and that the buzzer + goes to 5V.
  • Always sounding? The button or its 10 kΩ pull-up is likely miswired on GPIO 21.
  • Very faint? The buzzer may be on 3.3V instead of 5V — move it to the 5V rail.
  • Upload fails? Swap in a data-capable USB cable.

07 Make the idea yours

Try this: play a pitch, then a phrase

The doorbell proved a pin can make sound. This proves the pitch is a number you choose. Swap in the passive buzzer, drive it with tone() the way Sketch_06.2_Alertor.ino does, and hear frequency become pitch in your own ear. It fits inside today's session.

Play three notes

Swap in the passive buzzer and, using tone() on GPIO 14, sound 262 Hz, then 392 Hz, then 523 Hz for about half a second each. Those are a middle C, the G above it, and the C above that — each higher frequency is an unmistakably higher note. That mapping from frequency to pitch is the whole idea of the day.

Build a tiny phrase

Now play 330 Hz, 392 Hz, then 523 Hz in a row with short gaps between them — a three-note rising figure you can hum back. You have turned bare numbers into music. Try the same on the active buzzer and it can't follow: its oscillator only ever knows its one note.

08 Learn it with a hand on the tiller

Coach me through it

Every lesson ships with a code and a machine-readable packet, so an agent can guide you with full context.

Lesson code

TSK-DAY10-BUZZER

How the agent should behave: guide one physical connection at a time and wait for confirmation, but make sure the learner leaves understanding that pitch is frequency and why an active buzzer plays one fixed note while a passive buzzer can be tuned. Always check transistor orientation, wiring, board, port, and USB before code.

Keep your place

Finished Day 10?

Mark it complete — it shows on your course map, and your place is saved on this device.

Field note

Shortcut

Prompt copied