Introduction: Buzzer Sensor With Micropython Using BharatPi Board

About: Bharat Pi is an IoT prototyping platform for students, innovators, startups and developers. A simplified board with an all in one compute network and storage on a single board to build rapid prototypes, colleg…

A buzzer is an electrical device that produces a buzzing or humming sound when an electric current passes through it. It typically consists of a vibrating membrane or diaphragm that creates the sound. Buzzers are commonly used in alarm systems, electronic devices, appliances, and signaling devices to alert users of various events or conditions. They can vary in size, shape, and sound output depending on their intended application.

Supplies

Parts required:

Here’s a list of the parts you need,

1. ESP32

2. Buzzer sensor

3. USB Cable

4. Jumper wires

Pre required:

To follow this instruction you need an IDE to write and upload the code to your board, you can use uPyCraft IDE or Thonny IDE. you also need Micropython firmware installed in your ESP32 boards.

If you don't have the setup means then you can check the README file of installing and setup of uPyCraft in our Bharat Pi github page you can find the link below,

https://github.com/Bharat-Pi/MicroPython/blob/main/README.md

Step 1: Type of Buzzers

There are several types of buzzers, each with its own characteristics and applications. Here are some common types:

  1. Piezoelectric Buzzers: These buzzers generate sound through the piezoelectric effect, where a piezoelectric crystal vibrates when an electric current is applied to it. Piezoelectric buzzers are compact, lightweight, and have low power consumption. They are commonly used in electronic devices, alarms, and timers.
  2. Magnetic Buzzers: Magnetic buzzers use an electromagnet and a diaphragm to produce sound. When an electric current passes through the electromagnet, it attracts the diaphragm, causing it to vibrate and produce sound. Magnetic buzzers are often used in applications where a louder sound output is required, such as in industrial equipment and security systems.
  3. Mechanical Buzzers: Mechanical buzzers, also known as AC buzzers, consist of an electromechanical mechanism that produces sound through the rapid oscillation of a metal armature or reed. These buzzers are commonly used in older appliances, doorbells, and timers.
  4. Transducer Buzzers: Transducer buzzers are versatile devices that can produce sound by converting electrical signals into mechanical vibrations. They can be based on various technologies, including electromagnetic, piezoelectric, and electrodynamic principles. Transducer buzzers are used in a wide range of applications, including consumer electronics, automotive systems, and medical devices.
  5. Indicator Buzzers: Indicator buzzers are compact devices designed to provide audible alerts or indications in electronic equipment and control panels. They are often used in conjunction with other indicator lights or displays to provide both visual and auditory feedback.


Step 2: Schematic - Esp32 With Buzzer Sensor

In this section, we will see how to connect buzzer sensor with ESP32. The buzzer sensor will be connected with the ESP32 board with its 3 pins.

Follow the schematic diagram for the ESP modules and connect them accordingly. Connect the ESP32 device with the buzzer sensor as shown in the schematic diagram above:

Pinout of the buzzer Sensor :

buzzer Sensor - ESP32

VCC - Power Supply

Data - GPIO

GND - GND

Wire the buzzer sensor to the ESP32 as shown in the following schematic diagram. We’re connecting the vcc pin to 3v/5v and the buzzer pin to GPIO 23, but you can use any other suitable pins, and GND pin to GND of esp32.

ESP32 Wiring With buzzer Sensor :

Buzzer Sensor - ESP32

VCC - 5V / 3V

Data - 23 (ANY GPIO)

GND - GND


Step 3: CODE Snippet


from machine import Pin
import time

BUZZER_PIN = 23 # GPIO pin connected to the buzzer

def setup():
  global buzzer
  # Initialize the buzzer pin
  buzzer = Pin(BUZZER_PIN, Pin.OUT)

def buzz(duration_ms):
  # Turn on the buzzer
  buzzer.on()
  # Wait for the specified duration
  time.sleep_ms(duration_ms)
  # Turn off the buzzer
  buzzer.off()

def loop():
  # First loop
  for i in range(100):
    # Make a sound
    buzzer.on()
    time.sleep_ms(1) # Send high signal to buzzer
    buzzer.off()
    time.sleep_ms(1) # Send low signal to buzzer
  time.sleep(1)

  for j in range(50):
    # Make another sound
    buzzer.on()
    time.sleep_ms(4)
    buzzer.off()
    time.sleep_ms(4)
  time.sleep(1)

# Initialize setup
setup()

# Main loop
while True:
  loop()


Step 4: Applications

Buzzers have a wide range of applications across various industries and everyday scenarios due to their ability to produce audible alerts or signals. Some common applications of buzzers include:

  1. Alarms and Security Systems: Buzzers are frequently used in alarm systems for buildings, homes, and vehicles. They can alert occupants in case of intrusion, fire, smoke, or other emergencies.
  2. Electronic Devices: Many electronic devices incorporate buzzers to provide auditory feedback or alerts. For example, they are used in timers, clocks, microwave ovens, washing machines, and kitchen appliances to signal the completion of a task or indicate an error.
  3. Industrial Equipment: In industrial settings, buzzers are used for signaling various conditions such as equipment malfunction, low fluid levels, or completion of a process. They are essential for maintaining operational safety and efficiency.
  4. Automotive Systems: Vehicles utilize buzzers for a range of purposes, including indicating open doors, seatbelt warnings, low fuel warnings, and parking sensor alerts. Buzzers can also be integrated into car security systems.
  5. Medical Devices: In healthcare settings, buzzers are used in medical equipment and devices to signal alarms for critical conditions, medication reminders, or patient monitoring systems.
  6. Consumer Electronics: Buzzers are commonly found in consumer electronics such as smartphones, tablets, and laptops. They provide notifications for incoming calls, messages, and other events.
  7. Game and Entertainment Systems: In gaming consoles, arcade machines, and amusement park attractions, buzzers are often used to enhance the gaming experience or signal specific events.
  8. Access Control Systems: Buzzers can be integrated into access control systems to provide audible feedback when granting or denying access to a secure area.
  9. Educational and Training Tools: Buzzers are used in educational settings for quizzes, trivia games, and classroom activities. They provide a fun and engaging way to interact with students and reinforce learning.
  10. Navigation and Wayfinding Systems: In public transportation terminals, airports, and other crowded environments, buzzers may be used to guide individuals with visual impairments or signal approaching departures.