🌍🐶 Smart IoT Pet Feeder using ESP32 + Servo + Blynk IoT (Cloud Dashboard)
📦 Components Required
-
ESP32
-
SG90 Servo Motor
-
External 5V power supply
-
WiFi connection
-
Blynk IoT account
🔌 Circuit Connection
Servo → ESP32
| Servo Wire | Connect To |
|---|---|
| Red (VCC) | 5V External Supply |
| Brown/Black (GND) | ESP32 GND |
| Orange/Yellow (Signal) | GPIO 18 |
⚠ IMPORTANT
Common ground between ESP32 and external supply.
🌐 Blynk IoT Setup (Very Important Section)
Go to:
👉 https://blynk.cloud
Login and follow steps below.
🔹 Step 1: Create Template
-
Click New Template
-
Template Name:
Smart Pet Feeder -
Hardware: ESP32
-
Connection Type: WiFi
-
Click Done
🔹 Step 2: Create Datastreams
Go to Datastreams → New Datastream
1️⃣ Virtual Pin V0 (Button Control)
-
Datastream Type: Virtual Pin
-
Pin: V0
-
Data Type: Integer
-
Min: 0
-
Max: 1
-
Default: 0
Purpose:
👉 1 = Open
👉 0 = Close
2️⃣ Virtual Pin V1 (Status Display)
-
Datastream Type: Virtual Pin
-
Pin: V1
-
Data Type: Integer
-
Min: 0
-
Max: 1
Purpose:
👉 Show gate status
🔹 Step 3: Create Device
-
Go to Devices
-
Click New Device
-
From Template
-
Select Smart Pet Feeder
-
Copy Auth Token
You will paste this into code.
🔹 Step 4: Dashboard Setup
Open Blynk Mobile App.
Add Widgets:
🔘 Button Widget
-
Datastream: V0
-
Mode: Switch
💡 LED Widget
-
Datastream: V1
-
ON color: Green
-
OFF color: Red
Now dashboard ready ✅
💻 FINAL ESP32 + Blynk Code
Install libraries first:
-
Blynk
-
ESP32Servo
Now paste code:
#define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID"
#define BLYNK_DEVICE_NAME "Smart Pet Feeder"
#define BLYNK_AUTH_TOKEN "YOUR_AUTH_TOKEN"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
char ssid[] = "YOUR_WIFI_NAME";
char pass[] = "YOUR_WIFI_PASSWORD";
Servo feederServo;
const int servoPin = 18;
int gateState = 0; // 0 = Closed, 1 = Open
BLYNK_WRITE(V0)
{
int value = param.asInt();
if (value == 1) {
feederServo.write(90);
gateState = 1;
Blynk.virtualWrite(V1, 1);
}
else {
feederServo.write(0);
gateState = 0;
Blynk.virtualWrite(V1, 0);
}
}
void setup()
{
Serial.begin(115200);
feederServo.attach(servoPin);
feederServo.write(0); // Start Closed
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
}
🧠 Code Explanation (Professional Understanding)
1️⃣ Template & Auth Token
#define BLYNK_AUTH_TOKEN
These connect ESP32 to:
-
Your Blynk cloud
-
Your specific dashboard
2️⃣ BLYNK_WRITE(V0)
This function runs automatically when:
User presses Button on dashboard.
If:
-
Button ON → value = 1
-
Button OFF → value = 0
3️⃣ Servo Control Logic
Opens gate.
Closes gate.
4️⃣ Status Update
Turns ON LED widget.
Turns OFF LED widget.
5️⃣ Blynk.run()
Maintains communication between:
-
ESP32
-
Blynk Cloud
-
Mobile App
Without this → IoT won’t work.
📱 Working Flow
-
ESP32 connects to WiFi
-
Connects to Blynk Cloud
-
User presses button
-
Cloud sends command
-
Servo rotates
-
Status LED updates
-
Real-time control from anywhere
🎯 What Students Learn From Final Version
-
IoT cloud architecture
-
Virtual Pins concept
-
Real-time cloud control
-
Dashboard design
-
Professional IoT system
-
Industry-level project structure
🚀 Advanced Upgrade Ideas (Next Level)
Shiv 👑 You can now upgrade to:
-
🕒 Scheduled feeding timer
-
📦 Food level sensor (ultrasonic)
-
📊 Feeding history graph
-
📱 Notification when feeding done
-
📷 Camera monitoring
-
🧠 AI-based feeding schedule
📌 Final Conclusion
This Smart IoT Pet Feeder project demonstrates:
-
Embedded Systems
-
Cloud IoT integration
-
Remote automation
-
Real-world application