Buzzer Sensor With Micropython Using BharatPi Board
by bharatpi in Circuits > Electronics
282 Views, 0 Favorites, 0 Comments
Buzzer Sensor With Micropython Using BharatPi Board
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 and Thonny IDE in our Bharat Pi github page you can find the link below,
> https://github.com/Bharat-Pi/MicroPython/blob/main/README.md
Type of Buzzers
There are several types of buzzers, each with its own characteristics and applications. Here are some common types:
- 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.
- 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.
- 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.
- 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.
- 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.
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
CODE Snippet
from machine import Pin
import time
# GPIO pin connected to the buzzer
BUZZER_PIN = 23
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()
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:
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Access Control Systems: Buzzers can be integrated into access control systems to provide audible feedback when granting or denying access to a secure area.
- 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.
- 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.