The circuit in question is designed to interface an ESP32 microcontroller with a buzzer module, an HC-SR04 ultrasonic sensor, and a traffic light module. The ESP32 is responsible for controlling the buzzer and the traffic light LEDs based on the distance measurements from the ultrasonic sensor. The circuit is likely intended for a smart garbage maintaining system, as indicated by the embedded code, which suggests functionality for detecting the fill level of a container and alerting when the container is full.
#define BLYNK_TEMPLATE_ID "TMPL3_mZ5JXni"
#define BLYNK_TEMPLATE_NAME "Smart Garbage Maintaining System"
#define BLYNK_AUTH_TOKEN "yrA62Lf3TT-rvYpnep6P5okcO-021lWy"
#define PIN_RED 25 // The ESP32 pin GPIO25 connected to R pin of traffic light module
#define PIN_YELLOW 26 // The ESP32 pin GPIO26 connected to Y pin of traffic light module
#define PIN_GREEN 27 // The ESP32 pin GPIO27 connected to G pin of traffic light module
#define RED_TIME 500 // RED time in millisecond
#define YELLOW_TIME 500 // YELLOW time in millisecond
#define GREEN_TIME 500 // GREEN time in millisecond
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <NewPing.h>
#define TRIGGER_PIN 19 // ESP32 pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 18 // ESP32 pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters).
BlynkTimer timer; // Creating a timer object
char ssid[] = "Training Hall_EXT";
char pass[] = "IRDT#1982";
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
const int buzzerPin = 23;
int bucketFilledUpto = 0;
void setup() {
Serial.begin(115200); // Starts the serial communication
lcd.init();
lcd.backlight();
show(0);
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, HIGH);
timer.setInterval(1000L, myTimerEvent); //Starting a timer
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_YELLOW, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
}
void myTimerEvent() // This loop defines what happens when timer is triggered
{
Blynk.virtualWrite(V0, bucketFilledUpto);
}
void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec).
float distanceCm = sonar.ping_cm();
Serial.print(bucketFilledUpto);
Serial.print("Ping: ");
Serial.print(distanceCm); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
digitalWrite(PIN_RED, LOW); // turn off
digitalWrite(PIN_YELLOW, LOW); // turn off
bucketFilledUpto = ((18 - distanceCm) * 100) / 18;
show(bucketFilledUpto);
if (distanceCm <= 5) {
digitalWrite(buzzerPin, LOW);
digitalWrite(PIN_RED, HIGH); // turn on
digitalWrite(PIN_YELLOW, LOW); // turn off
digitalWrite(PIN_GREEN, LOW); // turn off
delay(500);
} else {
digitalWrite(buzzerPin, HIGH);
digitalWrite(PIN_RED, LOW); // turn off
digitalWrite(PIN_YELLOW, LOW); // turn off
digitalWrite(PIN_GREEN, HIGH); // turn on
delay(500);
}
Blynk.run();
timer.run();
}
void show(float d) {
lcd.setCursor(0, 0);
lcd.print("Name : Anand,Anshu");
lcd.setCursor(0, 1);
lcd.print("Member: 3");
lcd.setCursor(0, 2);
lcd.print("Project Name: GMS");
lcd.setCursor(0, 3);
lcd.print("Status :");
lcd.setCursor(10, 3);
lcd.print(d);
lcd.print("%");
}
This code is designed to run on an ESP32 microcontroller. It uses the Blynk platform for IoT applications, an LCD for display, and a NewPing library for the ultrasonic sensor. The code manages the traffic light LEDs and the buzzer based on the distance measured by the ultrasonic sensor, indicating the fill level of a container. The Blynk platform is used to send the fill level data to a virtual pin for remote monitoring.