🐶 Smart Pet Feeder using ESP32 in Hotspot (Access Point) Mode + WiFi Serial Terminal
📦 Components Required
-
ESP32
-
SG90 Servo Motor
-
External 5V supply
-
Android phone
-
TCP Terminal App
Recommended App:
-
TCP Telnet Terminal
-
Serial WiFi Terminal
-
Any TCP Client app
🔌 Circuit Connection
Servo → ESP32
| Servo Wire | Connect To |
|---|---|
| Red (VCC) | 5V External Supply |
| Brown/Black (GND) | ESP32 GND |
| Orange/Yellow (Signal) | GPIO 18 |
⚠ IMPORTANT
Connect external GND and ESP32 GND together.
🌐 How This Version Works
1️⃣ ESP32 creates its own WiFi hotspot
2️⃣ Mobile connects to ESP32 WiFi
3️⃣ ESP32 runs TCP server
4️⃣ Mobile sends OPEN / CLOSE
5️⃣ Servo moves
6️⃣ Status shown in app
💻 Complete ESP32 Code (Hotspot Mode)
Copy & paste into Arduino IDE:
#include <WiFi.h>
#include <ESP32Servo.h>
const char* ssid = "Pet_Feeder_AP";
const char* password = "12345678";
WiFiServer server(23); // Telnet Port
Servo feederServo;
const int servoPin = 18;
int gateState = 0; // 0 = Closed, 1 = Open
void setup() {
Serial.begin(115200);
feederServo.attach(servoPin);
feederServo.write(0); // Start Closed
// Start Access Point
WiFi.softAP(ssid, password);
Serial.println("Access Point Started");
Serial.print("AP IP Address: ");
Serial.println(WiFi.softAPIP());
server.begin();
Serial.println("Server Started on Port 23");
}
void loop() {
WiFiClient client = server.available();
if (client) {
Serial.println("Client Connected");
client.println("Welcome to Smart Pet Feeder");
client.println("Type OPEN or CLOSE");
while (client.connected()) {
if (client.available()) {
String command = client.readStringUntil('\n');
command.trim();
if (command.equalsIgnoreCase("OPEN")) {
openGate(client);
}
else if (command.equalsIgnoreCase("CLOSE")) {
closeGate(client);
}
else {
client.println("Invalid Command!");
}
}
}
client.stop();
Serial.println("Client Disconnected");
}
}
void openGate(WiFiClient client) {
feederServo.write(90);
gateState = 1;
client.println("Food Gate is OPEN");
Serial.println("Gate Opened");
}
void closeGate(WiFiClient client) {
feederServo.write(0);
gateState = 0;
client.println("Food Gate is CLOSED");
Serial.println("Gate Closed");
}
🧠 Code Explanation (Clear Concept Teaching)
1️⃣ Create Hotspot
ESP32 becomes a WiFi router.
Mobile will see:
👉 Pet_Feeder_AP
Password:
👉 12345678
2️⃣ Get AP IP Address
Default IP usually:
You will use this in mobile app.
3️⃣ Create TCP Server
Port 23 is Telnet communication port.
4️⃣ Wait for Client
Checks if mobile connected.
5️⃣ Read Commands
Reads user message.
6️⃣ Control Servo
OPEN → 90°
CLOSE → 0°
📱 How To Use (Step-by-Step)
Step 1
Upload code
Step 2
Open Serial Monitor
You will see:
AP IP Address: 192.168.4.1
Server Started on Port 23
Step 3
Go to Mobile WiFi
Connect to:
Password:
Step 4
Open TCP Client App
Enter:
-
Host: 192.168.4.1
-
Port: 23
Click Connect
Step 5
Send Command
Type:
Response:
Type:
Response:
🎯 What Students Learn From This Version
-
Access Point Mode
-
Client-Server concept
-
TCP communication
-
Wireless embedded systems
-
Real-world IoT architecture
-
Offline IoT systems
🚀 Why This Version Is Powerful
✔ No router required
✔ No internet required
✔ Works anywhere
✔ Ideal for rural demo
✔ Professional IoT concept