🧠 Smart Dustbin (Blynk IoT Cloud Version)
🎯 Objective of This Lesson
Students will learn:
-
What is Cloud IoT
-
How to connect ESP32 to Blynk Cloud
-
How to create Datastreams
-
How to design Dashboard
-
How to monitor dustbin remotely
Now you can monitor dustbin from anywhere 🌍
🌐 What is Blynk IoT?
Blynk is a cloud IoT platform that allows:
-
Remote monitoring
-
Mobile dashboard control
-
Cloud data storage
-
Real-time updates
🧾 Step 1 – Blynk Account Setup
-
Go to: https://blynk.cloud
-
Create account
-
Click Create Template
-
Choose:
-
Hardware → ESP32
-
Connection → WiFi
-
-
Save template
🧾 Step 2 – Create Datastreams
Inside Template → Datastreams → Create:
🔹 Virtual Pin Setup
| Datastream Name | Virtual Pin | Type |
|---|---|---|
| Hand Status | V0 | String |
| Garbage Distance | V1 | Double |
| Dustbin Status | V2 | String |
Save all.
🧾 Step 3 – Create Device
-
Go to Devices
-
Click “New Device”
-
From Template
-
Copy:
-
Auth Token
-
Template ID
-
Template Name
You will paste this into code.
🧾 Step 4 – Design Dashboard
Open Web Dashboard or Mobile App.
Add Widgets:
1️⃣ Label → V0 → Hand Status
2️⃣ Gauge → V1 → Garbage Distance
3️⃣ Label → V2 → Dustbin Status
Now your IoT dashboard is ready.
🔌 Hardware Connections (Same as Before)
Ultrasonic 1 → GPIO 5, 18
Ultrasonic 2 → GPIO 17, 16
Servo → GPIO 13
🧾 Complete ESP32 Blynk Code (Copy–Paste Ready)
Replace WiFi and Blynk credentials before uploading.
#define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID"
#define BLYNK_TEMPLATE_NAME "SmartDustbin"
#define BLYNK_AUTH_TOKEN "YOUR_AUTH_TOKEN"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
// -------- WiFi Credentials --------
char ssid[] = "YOUR_WIFI_NAME";
char pass[] = "YOUR_WIFI_PASSWORD";
// -------- Pin Definitions --------
#define TRIG1 5
#define ECHO1 18
#define TRIG2 17
#define ECHO2 16
#define SERVO_PIN 13
Servo myServo;
BlynkTimer timer;
long duration;
float distanceHand;
float distanceGarbage;
// -------- Distance Function --------
float getDistance(int trigPin, int echoPin) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
float distance = duration * 0.034 / 2;
return distance;
}
// -------- Send Data to Blynk --------
void sendData() {
// Hand Detection
distanceHand = getDistance(TRIG1, ECHO1);
if (distanceHand > 0 && distanceHand < 20) {
myServo.write(90);
delay(3000);
myServo.write(0);
Blynk.virtualWrite(V0, "Hand Detected - Lid Opened");
}
// Garbage Level
distanceGarbage = getDistance(TRIG2, ECHO2);
Blynk.virtualWrite(V1, distanceGarbage);
if (distanceGarbage > 0 && distanceGarbage < 8) {
Blynk.virtualWrite(V2, "Dustbin is FULL");
} else {
Blynk.virtualWrite(V2, "Dustbin is NOT Full");
}
}
void setup() {
Serial.begin(115200);
pinMode(TRIG1, OUTPUT);
pinMode(ECHO1, INPUT);
pinMode(TRIG2, OUTPUT);
pinMode(ECHO2, INPUT);
myServo.attach(SERVO_PIN);
myServo.write(0);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(2000L, sendData);
}
void loop() {
Blynk.run();
timer.run();
}
🧠 Code Explanation (Step-by-Step)
1️⃣ Blynk Credentials
#define BLYNK_AUTH_TOKEN
These connect ESP32 to your cloud dashboard.
2️⃣ Blynk.begin()
Connects ESP32 to:
-
WiFi
-
Blynk Cloud Server
3️⃣ Virtual Write
Sends data to virtual pin V1.
Dashboard widget connected to V1 will show value.
4️⃣ Timer Function
Runs sendData() every 2 seconds.
Prevents blocking.
📊 Dashboard Output Example
V0 → Hand Detected – Lid Opened
V1 → 6.5 cm
V2 → Dustbin is FULL
🎓 Learning Outcomes
We now understand:
-
Cloud IoT Architecture
-
Virtual Pins
-
Real-time monitoring
-
Template & Device concept
-
Professional IoT structure