3.1 Beep

This is a simple project to make an active buzzer beep quickly four times every second.

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+

ESP32 Starter Kit

You can also buy them separately from the links below.

COMPONENT INTRODUCTION

PURCHASE LINK

ESP32 WROOM 32E

BUY

ESP32 Camera Extension

-

Breadboard

BUY

Jumper Wires

BUY

Resistor

BUY

Buzzer

-

Transistor

BUY

Available Pins

Here is a list of available pins on the ESP32 board for this project.

Available Pins

IO13, IO12, IO14, IO27, IO26, IO25, IO33, IO32, IO15, IO2, IO0, IO4, IO5, IO18, IO19, IO21, IO22, IO23

Schematic

../../_images/circuit_3.1_buzzer.png

When the IO14 output is high, after the 1K current limiting resistor (to protect the transistor), the S8050 (NPN transistor) will conduct, so that the buzzer will sound.

The role of S8050 (NPN transistor) is to amplify the current and make the buzzer sound louder. In fact, you can also connect the buzzer directly to IO14, but you will find that the buzzer sound is smaller.

Wiring

Two types of buzzers are included in the kit. We need to use active buzzer. Turn them around, the sealed back (not the exposed PCB) is the one we want.

../../_images/buzzer.png

The buzzer needs to use a transistor when working, here we use S8050 (NPN Transistor).

../../_images/3.1_buzzer_bb.png

Code

Note

  • Open the 3.1_beep.py file located in the esp32-starter-kit-main\micropython\codes path, or copy and paste the code into Thonny. Then, click “Run Current Script” or press F5 to execute it.

  • Make sure to select the “MicroPython (ESP32).COMxx” interpreter in the bottom right corner.

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.