0% found this document useful (0 votes)
6 views5 pages

Buzzer Program

This document provides instructions for integrating an active DC buzzer into a gas leakage notification system using an ESP32. It includes a list of required components, detailed wiring instructions, and code modifications necessary to control the buzzer when gas is detected. The complete modified code is also provided for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Buzzer Program

This document provides instructions for integrating an active DC buzzer into a gas leakage notification system using an ESP32. It includes a list of required components, detailed wiring instructions, and code modifications necessary to control the buzzer when gas is detected. The complete modified code is also provided for implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

To add an active DC buzzer to your gas leakage notification system, follow

these instructions:

### Components Needed

- Active DC Buzzer

- Resistor (optional, for current limiting)

- Jumper wires

- Breadboard (optional)

### Wiring Instructions

1. **Connect the Buzzer:**

- Connect the positive terminal of the active DC buzzer to a digital pin on


the ESP32 (e.g., GPIO 23).

- Connect the negative terminal of the buzzer to the ground (GND) of the
ESP32.

### Code Modifications

Add the following code snippets to your existing code to control the buzzer
when gas leakage is detected.

1. **Define the Buzzer Pin:**

At the top of your code, define a pin for the buzzer:

```cpp

const int buzzerPin = 23; // Change to the GPIO pin you connected the
buzzer to

```

2. **Setup the Buzzer:**


In the `setup()` function, initialize the buzzer pin:

```cpp

pinMode(buzzerPin, OUTPUT);

```

3. **Activate the Buzzer on Gas Detection:**

Modify the `sendSensor()` function to activate the buzzer when gas is


detected:

```cpp

if(data > sensorThres){

[Link]("gas_alert","Gas Leakage Detected");

digitalWrite(buzzerPin, HIGH); // Turn the buzzer on

[Link](0, 0);

[Link]("Gas Detected:");

[Link](0,1);

[Link]("Gas Value: ");

[Link](data);

} else {

digitalWrite(buzzerPin, LOW); // Turn the buzzer off

[Link]();

[Link]("No Leakage");

```

### Complete Modified Code

Here is the updated code snippet with the buzzer integration:


```cpp

#define BLYNK_TEMPLATE_ID "TMPL3hcslF41i"

#define BLYNK_TEMPLATE_NAME "Gas Leakage Notification"

#define BLYNK_AUTH_TOKEN "PX8K-


cCupwFDdsfPZiiFjhyUqDrklPgMKqklbMHot"

#define BLYNK_PRINT Serial

#include <WiFi.h>

#include <BlynkSimpleEsp32.h>

#include <LiquidCrystal_I2C.h> //LCD DISPLAY

int lcdColumns = 16;

int lcdRows = 2;

LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "WiFi Username";

char pass[] = "WiFi Password";

const int smokeA0 = 34;

const int buzzerPin = 23; // Buzzer pin

int data = 0;

int sensorThres = 100;

BlynkTimer timer;

void setup(){

pinMode(smokeA0, INPUT);
pinMode(buzzerPin, OUTPUT); // Initialize buzzer pin

[Link](115200);

[Link](auth, ssid, pass);

[Link]();

[Link](3,0);

[Link]("Tech Trends");

delay(1000);

[Link]();

[Link](3,0);

[Link]("Gas Leakage");

[Link](3,1);

[Link]("Notification");

delay(1000);

[Link]();

[Link](1000L, sendSensor);

void sendSensor(){

int data = analogRead(smokeA0);

[Link](V0, data);

[Link]("Pin A0: ");

[Link](data);

if(data > sensorThres){

[Link]("gas_alert","Gas Leakage Detected");

digitalWrite(buzzerPin, HIGH); // Turn the buzzer on

[Link](0, 0);
[Link]("Gas Detected:");

[Link](0,1);

[Link]("Gas Value: ");

[Link](data);

else {

digitalWrite(buzzerPin, LOW); // Turn the buzzer off

[Link]();

[Link]("No Leakage");

void loop(){

[Link]();

[Link]();

```

### Notes

- Adjust the `buzzerPin` variable to match the pin you used for the buzzer.

- Ensure your buzzer is rated for the voltage you are using with your ESP32.

You might also like