🐶 Smart Pet Feeder (Serial Bluetooth Terminal App)
-
📱 Control gate from mobile
-
🔵 Use Bluetooth (no WiFi required)
-
📟 See gate status in app
-
🎮 Send OPEN / CLOSE commands
📦 Components Required
-
ESP32
-
SG90 Servo Motor
-
External 5V supply (recommended)
-
Android phone
-
Serial Bluetooth Terminal app
🔌 Circuit Connections
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
📲 App Setup (Serial Bluetooth Terminal)
Use:
-
Serial Bluetooth Terminal by Kai Morich (Android)
Steps:
-
Install app from Play Store
-
Turn ON Bluetooth
-
Upload code to ESP32
-
Open app
-
Search devices
-
Connect to ESP32 (Default name we set in code)
💻 Complete ESP32 Bluetooth Code
Copy & paste into Arduino IDE:
#include <ESP32Servo.h>
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
Servo feederServo;
const int servoPin = 18;
int gateState = 0; // 0 = Closed, 1 = Open
void setup() {
Serial.begin(115200);
SerialBT.begin("Smart_Pet_Feeder");
feederServo.attach(servoPin);
feederServo.write(0); // Start closed
Serial.println("Bluetooth Pet Feeder Started");
Serial.println("Device Name: Smart_Pet_Feeder");
}
void loop() {
if (SerialBT.available()) {
String command = SerialBT.readStringUntil('\n');
command.trim();
if (command.equalsIgnoreCase("OPEN")) {
openGate();
}
else if (command.equalsIgnoreCase("CLOSE")) {
closeGate();
}
else {
SerialBT.println("Invalid Command! Send OPEN or CLOSE");
}
}
}
void openGate() {
feederServo.write(90);
gateState = 1;
SerialBT.println("Food Gate is OPEN");
}
void closeGate() {
feederServo.write(0);
gateState = 0;
SerialBT.println("Food Gate is CLOSED");
}
🧠 Code Explanation (Line by Line Concept)
1️⃣ Include Required Libraries
#include “BluetoothSerial.h”
-
ESP32Servo → Controls servo motor
-
BluetoothSerial → Enables Bluetooth communication
2️⃣ Create Objects
-
SerialBT → Used for Bluetooth communication
-
feederServo → Used to control servo
3️⃣ Start Bluetooth
This sets Bluetooth device name.
When you scan in mobile, you will see:
👉 Smart_Pet_Feeder
4️⃣ Attach Servo
Connects servo to GPIO 18.
5️⃣ Check for Bluetooth Data
Checks if mobile sent any data.
6️⃣ Read Command
Reads message until Enter key.
Example:
OPEN
CLOSE
7️⃣ Compare Commands
Case insensitive:
-
open
-
OPEN
-
Open
All work.
8️⃣ Open Gate Function
Rotates servo to 90°
Gate opens.
9️⃣ Close Gate Function
Rotates servo to 0°
Gate closes.
📱 How to Use in App
After connecting:
Type:
→ App shows: Food Gate is OPEN
Type:
→ App shows: Food Gate is CLOSED
🎯 What Students Learn From This Version
-
Bluetooth communication
-
Serial data handling
-
Mobile app control
-
Real-time feedback
-
Embedded system wireless control
🚀 Next Level Upgrade Options
Shiv 🔥 You can now upgrade to:
-
🕒 Automatic close after 5 seconds
-
📊 Send gate status continuously
-
🔐 Password protected Bluetooth
-
📱 Custom Android app
-
🌐 Web server control
-
📦 Add food level sensor
-
🧠 Add feeding schedule timer