Course Content
IoT Engineering Course using ESP32 with 12 Real-World Projects

🌍🐶 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

  1. Click New Template

  2. Template Name:

     
     
    Smart Pet Feeder
     
  3. Hardware: ESP32

  4. Connection Type: WiFi

  5. 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

  1. Go to Devices

  2. Click New Device

  3. From Template

  4. Select Smart Pet Feeder

  5. 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_TEMPLATE_ID
#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

 
 
feederServo.write(90);
 

Opens gate.

 
 
feederServo.write(0);
 

Closes gate.


4️⃣ Status Update

 
 
Blynk.virtualWrite(V1, 1);
 

Turns ON LED widget.

 
 
Blynk.virtualWrite(V1, 0);
 

Turns OFF LED widget.


5️⃣ Blynk.run()

Maintains communication between:

  • ESP32

  • Blynk Cloud

  • Mobile App

Without this → IoT won’t work.


📱 Working Flow

  1. ESP32 connects to WiFi

  2. Connects to Blynk Cloud

  3. User presses button

  4. Cloud sends command

  5. Servo rotates

  6. Status LED updates

  7. 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

 

Scroll to Top