Introduction:
This experiment demonstrates how to use a buzzer with a Raspberry Pi Pico microcontroller to produce a continuous beep sound. The buzzer is controlled using GPIO pins, which allows you to create sound signals for various applications.
Scope:
The scope of this experiment includes:
Understanding the basic principles of using GPIO pins for controlling output devices.
Implementing a simple MicroPython program to control a buzzer.
Observing how changes in the code affect the buzzer's behavior.
Prerequisite:
3.1. Hardware:
Pico microcontroller
Breadboard
Buzzer
Jumper wires
USB cable (to connect the computer)
3 .2. Software:
Thonny Software(For micro python)
MicroPython firmware installed on Raspberry Pi Pico
ubuntu Terminal(For embedded C)
CMake,Pico SDK,GNU Arm Embedded Toolchain,WSL.
Connection Details:
Buzzer Connection: Connect one terminal of the buzzer to GPIO 15 of the Pico.
GND Connection: Connect the other terminal of the buzzer to one of the GND pins on the Pico.

Working Principle:
The buzzer is controlled by setting the GPIO pin to a high or low state. When the pin is set high (1), the buzzer produces sound. When the pin is set low (0), the buzzer is silent. By alternating between high and low states with a delay, a continuous beep sound can be created.
An audio signaling device like a beeper or buzzer may be electromechanical or piezoelectric or mechanical type. The main function of this is to convert the signal from audio to sound. Generally, it is powered through DC voltage and used in timers, alarm devices, printers, alarms, computers, etc. Based on the various designs, it can generate different sounds like alarm, music, bell & siren.
Buzzer Pin Configuration
The pin configuration of the buzzer is shown below. It includes two pins namely positive and negative. The positive terminal of this is represented with the ‘+’ symbol or a longer terminal. This terminal is powered through 6Volts whereas the negative terminal is represented with the ‘-‘symbol or short terminal and it is connected to the GND terminal.
Types of Buzzer
A buzzer is available in different types which include the following.
Piezoelectric
Electromagnetic
Mechanical
Electromechanical
Magnetic
Piezoelectric
As the name suggests, the piezoelectric type uses the piezoelectric ceramic’s piezoelectric effect & pulse current to make the metal plate vibrate & generate sound. This kind of buzzer is made with a resonance box, multi resonator, piezoelectric plate, housing, impedance matcher, etc. Some of the buzzers are also designed with LEDs.
The multi resonator of this mainly includes ICs and transistors. Once the supply is given to this resonator, it will oscillate and generates an audio signal with 1.5 to 2.kHz. The impedance matcher will force the piezoelectric plate to produce sound.
Electromagnetic
This type of buzzer is made with a magnet, solenoid coil, oscillator, housing, vibration diaphragm, and magnet. Once the power supply is given, the oscillator which produces the audio signal current will supply throughout the solenoid coil to generate a magnetic field.
Sometimes, the vibration diaphragm will vibrate & generates sound under the magnet & solenoid coil interaction. The frequency range of this ranges from 2 kHz to 4kHz.
Mechanical
These types of buzzers are subtypes of electromagnetic, so the components used in this type are also similar. But the main difference is that the vibrating buzzer is placed on the outside instead of the inside.
Electromechanical
The designing of these types of buzzers can be done with a bare metal disc & an electromagnet. The working principle of this is similar to magnetic and electromagnetic. It generates sound throughout the disc movement & magnetism.
Magnetic
Like a piezo type, magnetic is also used to generate a sound but they are different due to core functionality. The magnetic type is more fixed as compared to the piezo type because they work through a magnetic field.
Magnetic buzzers utilize an electric charge instead of depending on piezo materials to generate a magnetic field, after that it permits another element of the buzzer to vibrate & generate sound.
The applications of magnetic buzzers are similar to the piezo type in household devices, alarms such as watches, clocks & keyboards.
Application code:
MicroPython:
from machine import Pin
from time import sleep
buzzer = Pin(15, Pin.OUT)
while True:
buzzer.value(1) # Turn the buzzer on
sleep(1) # Beep for 1 second
buzzer.value(0) # Turn the buzzer off
sleep(1) # Pause for 1 second
Embedded C:
#include "pico/stdlib.h"
#define BUZZER_PIN 15
int main() {
// Initialize the GPIO pin for the buzzer
gpio_init(BUZZER_PIN);
gpio_set_dir(BUZZER_PIN, GPIO_OUT);
while (true) {
// Turn the buzzer on
gpio_put(BUZZER_PIN, 1);
sleep_ms(500); // Beep for 0.5 seconds
// Turn the buzzer off
gpio_put(BUZZER_PIN, 0);
sleep_ms(500); // Pause for 0.5 seconds
}
return 0;
}
Hardware Image:

Output:
When the code is executed, the buzzer will produce a beep sound with 1-second intervals of sound and silence, creating a continuous beeping pattern.
Video Demonstration:
Appendix:
Common CMakeLists:
cmake_minimum_required(VERSION 3.12)
# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)
project(pico_experiments C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
endif()
# Initialize the SDK
pico_sdk_init()
add_compile_options(-Wall
-Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
-Wno-unused-function # we have some for the docs that arent called
)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wno-maybe-uninitialized)
endif()
# Hardware-specific examples in subdirectories:
add_subdirectory(expt_10_LCD)
CMakeLists:
cmake_minimum_required(VERSION 3.13)
# Set the project name
project(buzzer_example)
# Set the Pico SDK path (update this if needed)
set(PICO_SDK_PATH ~/pico-sdk)
# Initialize the Raspberry Pi Pico SDK
include(pico_sdk_import.cmake)
# Add executable
add_executable(buzzer_example main.c)
# Link Pico SDK libraries to the executable
target_link_libraries(buzzer_example pico_stdlib)
# Enable USB serial communication
pico_enable_stdio_usb(buzzer_example 1)
# Enable the extra features
pico_enable_stdio_uart(buzzer_example 0)
# Include the standard libraries and directories
pico_add_extra_outputs(buzzer_example)
References:
These references provide comprehensive
| # | Topic | Date & time | Action |
|---|
0% Completed (0/1)