ESP32 C3 Super Mini - Piezo Buzzer

A piezo buzzer is the easiest way to add sound to an ESP32 C3 Super Mini project. It costs very little, needs only one GPIO pin, and can beep, alarm, or even play a song.

In this tutorial, you'll learn:

ESP32 C3 Super Mini - Piezo Buzzer

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×3-24V Active Piezo Buzzer
1×Active Piezo Buzzer Module
1×Passive Piezo Buzzer Module
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Piezo Buzzer

The piezo buzzer is a small sound component that turns an electric signal into a beep, a tone, or music.

Key Features:

  • One signal pin: Only one ESP32 C3 Super Mini GPIO pin is needed
  • Very cheap: One of the lowest-cost output parts you can buy
  • Loud for its size: Easy to hear in a room
  • Two styles: Bare buzzer, or buzzer module with a driver on board
  • Easy code: The tone() function does all the hard work

Technical Specifications:

  • Working voltage: 3V to 24V for the 3V-24V active buzzer
  • Module voltage: 3.3V or 5V
  • Current: Small at 3.3V, safe for a GPIO pin
  • Tone range: About 200 Hz to 5000 Hz sounds best
  • Signal type: A square wave (PWM) from the ESP32 C3 Super Mini

Two ways to use the 3V-24V buzzer:

  • Direct to a GPIO pin: You get a normal beep. Good for keypad clicks and status sounds.
  • Through a relay and a 12V supply: You get a very loud sound. Good for alarms and warnings.

Note: For the loud 12V version, see the ESP32 C3 Super Mini - Buzzer tutorial.

Piezo Buzzer Pinout

A bare piezo buzzer has two pins.

  • Positive (+) pin: The ESP32 C3 Super Mini sends the control signal to this pin (directly, or through a relay)
  • Negative (-) pin: Connect this pin to GND (0V)
Piezo Buzzer Pinout

A piezo buzzer module has three pins.

  • GND pin: Connect to GND (0V)
  • VCC pin: Connect to 3.3V
  • I/O pin: Receives the signal from an ESP32 C3 Super Mini GPIO pin

How Piezo Buzzer Works

See How Piezo Buzzer works

Wiring Diagram between Piezo Buzzer and ESP32 C3 Super Mini

Connect the buzzer signal pin to GPIO7 on the ESP32 C3 Super Mini.

  • Note: ESP32 C3 Super Mini GPIO pins are 3.3V only. Never feed 5V back into a GPIO pin.
  • Note: Check the polarity of the bare buzzer. The (+) pin has a longer leg or a + mark.
  • Note: Do not use GPIO8 or GPIO9. They are boot pins on this board.
  • Note: If the sound is weak, use the buzzer module. Its driver gives more current than a GPIO pin.
  • The wiring diagram between piezo buzzer and ESP32 C3 Super Mini
The wiring diagram between ESP32 C3 Super Mini Piezo Buzzer

This image is created using Fritzing. Click to enlarge image

Buzzer Pin ESP32 C3 Super Mini Pin
Positive (+) GPIO7
Negative (-) GND

I modified the wiring diagram above into this artwork drawing that makes it look like a duck. If you like it, please share it!

The wiring diagram between ESP32 C3 Super Mini Piezo Buzzer Duck

This image is created using Fritzing. Click to enlarge image

  • The wiring diagram between piezo buzzer module and ESP32 C3 Super Mini
The wiring diagram between ESP32 C3 Super Mini Piezo Buzzer Module

This image is created using Fritzing. Click to enlarge image

Module Pin ESP32 C3 Super Mini Pin
GND GND
VCC 3.3V
I/O GPIO7

ESP32 C3 Super Mini Code

This sketch plays a short melody on the piezo buzzer using the tone() function.

What This Code Does:

  • Sets GPIO7 as the buzzer signal pin
  • Reads note names such as NOTE_C4 from a pitches.h file
  • Plays each note with tone() for a set time
  • Waits a short moment between notes so you can hear each one
  • Calls noTone() to stop the sound after every note

Detailed Instructions

Follow these steps to run the ESP32 C3 Super Mini piezo buzzer example.

  • New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
  • Wire the parts: Follow the wiring diagram above.
  • Connect the board: Plug the ESP32 C3 Super Mini into your computer with a USB Cable Type-C.
  • Open the IDE: Launch the Arduino IDE on your computer.
  • Select the board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
  • Select the port: Pick the COM port of your board.
  • Copy the code: Copy the code below and paste it into the Arduino IDE.
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-piezo-buzzer */ #include "pitches.h" #define BUZZZER_PIN 7 // The ESP32 C3 SuperMini pin connected to piezo buzzer int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; void setup() { for (int thisNote = 0; thisNote < 8; thisNote++) { int noteDuration = 1000 / noteDurations[thisNote]; tone(BUZZZER_PIN, melody[thisNote], noteDuration); int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); noTone(BUZZZER_PIN); } } void loop() { }
  • Create the pitches.h file in the Arduino IDE by:
    • Either click on the button just below the serial monitor icon and choose New Tab, or use Ctrl+Shift+N keys.
    Arduino IDE 2 adds file
    • Give the file the name pitches.h and click the OK button.
    Arduino IDE 2 adds file pitches.h
    • Copy the code below and paste it into the new pitches.h file.
    /************************************************* * Public Constants *************************************************/ #define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978
    • Upload the code: Click the Upload button in the Arduino IDE.
    How to upload ESP32 C3 Super Mini code on Arduino IDE
    • Listen: The buzzer plays the melody one time after the board starts.
    • Open the Serial Monitor: Set the baud rate to 115200 if you add your own Serial.print() lines.
    • Pro Tip: Hear nothing? Swap the two buzzer legs. A bare buzzer only works one way round.

Modifying ESP32 C3 Super Mini Code

Let's change the ESP32 C3 Super Mini code to play the Jingle Bells song.

  • Only two arrays change: int melody[] and int noteDurations[]
  • melody[]: The list of notes to play, in order
  • noteDurations[]: How long each note lasts. 4 is a quarter note, 8 is an eighth note
  • Everything else stays the same: Same GPIO7 pin, same tone() calls
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-piezo-buzzer */ #include "pitches.h" #define BUZZZER_PIN 7 // The ESP32 C3 SuperMini pin connected to piezo buzzer // notes in the melody: int melody[] = { NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_G5, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_D5, NOTE_D5, NOTE_E5, NOTE_D5, NOTE_G5 }; // note durations: 4 = quarter note, 8 = eighth note, etc, also called tempo: int noteDurations[] = { 8, 8, 4, 8, 8, 4, 8, 8, 8, 8, 2, 8, 8, 8, 8, 8, 8, 8, 16, 16, 8, 8, 8, 8, 4, 4 }; void setup() { // iterate over the notes of the melody: int size = sizeof(noteDurations) / sizeof(int); for (int thisNote = 0; thisNote < size; thisNote++) { // to calculate the note duration, take one second divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000 / noteDurations[thisNote]; tone(BUZZZER_PIN, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // The note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(BUZZZER_PIN); } } void loop() { // no need to repeat the melody. }

Application/Project Ideas

A piezo buzzer adds sound to almost any ESP32 C3 Super Mini project.

  • Door Alarm: Beep when a door sensor or motion sensor is triggered
  • Button Feedback: Play a short click every time a button is pressed
  • Kitchen Timer: Sound a tune when the countdown reaches zero
  • Parking Sensor: Beep faster as an ultrasonic sensor sees an object get closer
  • Music Box: Store several melodies and pick one with a button
  • Low Battery Warning: Play a warning tone when the battery voltage drops

Challenge Yourself

Try these small tasks to learn more about sound on the ESP32 C3 Super Mini.

  • Easy: Change the melody to play "Happy Birthday" with notes from pitches.h
  • Easy: Move the melody code from setup() into loop() so it repeats forever
  • Medium: Add a button on GPIO6 so the melody plays only when you press it
  • Medium: Make a doorbell with a two-note chime and a short pause before the next ring
  • Advanced: Build a Morse code beeper that spells out a short text message
  • Advanced: Sweep the tone from 200 Hz to 4000 Hz to find the loudest frequency of your buzzer

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!