How to Build an Ultrasonic Buzzer System using ESP32
Introduction
The Ultrasonic Buzzer System is a useful tool for detecting objects within a certain range and sounding an alarm when an object is detected. In this tutorial, we will show you how to build an Ultrasonic Buzzer System using the ESP32 microcontroller. The ESP32 is a powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities, making it ideal for IoT projects. With this system, you can create a range of projects, from security systems to home automation.
Components Required
To build this system, you will need the following components:
ESP32 Development Board
Ultrasonic Sensor
Buzzer
Jumper Wires
Breadboard
Wiring Diagram
The following wiring diagram shows how to connect the components:
Ultrasonic Buzzer System Wiring Diagram
Code
The following code should be uploaded to your ESP32 using the Arduino IDE:
How It Works
The Ultrasonic Buzzer System works by measuring the distance between an object and the ultrasonic sensor. The ultrasonic sensor emits high-frequency sound waves and measures the time it takes for the sound waves to bounce back from an object. The distance is then calculated based on the time it takes for the sound waves to travel.
The ESP32 microcontroller reads the distance value and triggers the buzzer to sound an alarm when an object is detected within a certain
The following code should be uploaded to your ESP32 using the Arduino IDE:
scssconst int trigPin = 12; //Trigger Pin const int echoPin = 13; //Echo Pin const int buzzer = 14; //Buzzer Positive terminal long duration; int distance; void setup() { Serial.begin(115200); pinMode(trigPin, OUTPUT); pinMode(buzzer, OUTPUT); pinMode(echoPin, INPUT); } void loop() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = duration * 0.034 / 2; Serial.print("Distance: "); Serial.print(distance); Serial.println("cm."); delay(500); if(distance > 50) { digitalWrite(buzzer, LOW); } else { digitalWrite(buzzer, HIGH); } }