App + Web + Manual Switch Sync (Complete Guide)


5
π Introduction
Aaj ke smart world me Home Automation ek luxury nahi, balki necessity banti ja rahi hai.
Is project me hum ESP32 + Firebase Realtime Database ka use karke ek complete smart home system banate hain jisme:
β
Mobile App se control
β
Web Dashboard se control
β
Physical Manual Switch se control
β
Sab kuch real-time sync me
Matlab chahe aap light mobile se ON karo, switch se OFF, ya website se control β har jagah same state reflect hogi π₯
π§ System Overview (Kaise kaam karta hai?)
Is system ka core concept hai single source of truth β Firebase Realtime Database.
Flow:
Mobile App / Web / Manual Switch
β
Firebase Realtime Database
β
ESP32
β
Relays
ESP32 hamesha Firebase ko listen karta rehta hai, aur jaise hi koi value change hoti hai, relay turant ON/OFF ho jata hai.
π© Hardware Components Required



4
| Component | Description |
|---|---|
| ESP32 Dev Board | Main controller |
| Relay Module (4/8 Channel) | AC appliances control |
| Manual Switches | Physical ON/OFF |
| Bulb / Fan / Socket | Load |
| Power Supply | 5V / 12V |
| Connecting Wires | Jumper wires |
π» Software & Tools Used
| Software | Purpose |
|---|---|
| Arduino IDE | ESP32 programming |
| Firebase Realtime DB | Cloud sync |
| Android App / Kodular | Mobile control |
| Web Dashboard (PHP/JS) | Browser control |
βοΈ Firebase Realtime Database Structure

{
"devices": {
"device01": {
"relay1": 0,
"relay2": 1,
"relay3": 0,
"relay4": 1
}
}
}
π 0 = OFF
π 1 = ON
Yahi data App, Web aur ESP32 sab use karte hain.
π Relay Pin Configuration (ESP32)
#define RELAY1 23
#define RELAY2 22
#define RELAY3 21
#define RELAY4 19
βοΈ ESP32 Complete Code (Firebase + Relay + Manual Switch Sync)
#include <WiFi.h>
#include <FirebaseESP32.h>
#define WIFI_SSID "YOUR_WIFI"
#define WIFI_PASS "YOUR_PASSWORD"
#define FIREBASE_HOST "your-project.firebaseio.com"
#define FIREBASE_AUTH "DATABASE_SECRET"
FirebaseData fbdo;
int relays[] = {23,22,21,19};
int switches[] = {32,33,25,26};
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(500);
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
for(int i=0;i<4;i++){
pinMode(relays[i], OUTPUT);
pinMode(switches[i], INPUT_PULLUP);
}
}
void loop() {
for(int i=0;i<4;i++){
if(Firebase.getInt(fbdo,"/devices/device01/relay"+String(i+1))){
digitalWrite(relays[i], fbdo.intData());
}
if(digitalRead(switches[i])==LOW){
Firebase.setInt(fbdo,"/devices/device01/relay"+String(i+1), !digitalRead(relays[i]));
delay(300);
}
}
}
π₯ Is code ka fayda:
- App se ON β relay ON
- Switch se OFF β Firebase update
- Web pe live status update
π± Mobile App Control (Kodular / Android)
Mobile app Firebase ke same path ko read/write karti hai.
Features:
- Toggle buttons
- Real-time update
- Multiple devices support
- Login based control
π Web Dashboard Control
Web dashboard JavaScript + Firebase SDK use karta hai.
Web Features:
- Browser se control
- Live ON/OFF state
- Admin panel ready
- Multi-user support
π Manual Switch Sync (Most Important Feature π₯)
Normal home automation me issue hota hai:
Switch se OFF kiya β App me still ON dikhata hai β
Is project me:
β
Switch press β Firebase update
β
Firebase update β App & Web sync
β
No mismatch ever
π Security Best Practices
- Firebase rules enable karein
- User-wise device access
- Read/Write authentication
π Future Enhancements
- β± Timer & Scheduler
- π Voice control (Alexa / Google)
- π Energy monitoring
- π Control from anywhere
π― Final Conclusion
Ye ESP32 + Firebase Home Automation System ek complete production-ready solution hai jo:
β Real-time
β Scalable
β Secure
β Beginner-friendly
β Professional-grade
Agar aap Smart Home, IoT, ya Startup-level product banana chahte ho β ye system best base hai πͺπ₯
π Contact YaranaIoT Guru Empowering IoT Innovation | ESP32 | Home Automation | Smart Solutions | 50K+ Community
Weβd love to hear from you! Whether itβs IoT project queries, collaborations, tech support, custom PCB design, bulk orders, corporate training, college workshops, or freelance development β weβre just one message away.
βοΈ Email (Official)
For detailed inquiries, project support, business collaboration, sponsorships, or documentation: π© contact@yaranaiotguru.in π§ Alternate: support@yaranaiotguru.in β³ Response: Within 24 hours (MonβSat) π‘ Best for attachments (code, schematics, logs, etc.)
π± Phone / WhatsApp (24Γ7 Support)
Instant live help, troubleshooting, project consultation, or order updates: π +91 70527 22734 π¬ WhatsApp: Chat Now β° Call Hours: MonβSat, 10 AM β 7 PM IST π Emergency? WhatsApp anytime β reply within 1 hour
βΆοΈ YouTube Channel
Step-by-step IoT builds, live coding, ESP32, Blynk, Node-RED, MQTT, Home Assistant & more: π Yarana IoT Guru πΊ 1,200+ Videos | 52K+ Subs | 5.5M+ Views | 4.8β Rating π₯ New Video Every Week β π Subscribe & Turn On Notifications
π GitHub (100% Open Source)
All codes, Arduino sketches, PlatformIO projects, Node-RED flows, MQTT configs & docs: π github.com/YaranaIotGuru β 50+ Repos | 10K+ Stars & Forks
π₯ Top Projects:
- ESP32 WebSocket Real-Time Dashboard
- Smart Home with Blynk & Alexa
- IoT Irrigation System with Soil Moisture
- MQTT + Node-RED + MySQL Logging
- OLED Weather Station with API
πΈ Instagram
Daily reels, quick tips, live builds, student showcases & giveaways: π @YaranaIoTGuru π± 10K+ Followers | Reels | Stories | Live Sessions
πΌ LinkedIn (Professional Network)
B2B, IoT consulting, training, hiring & partnerships: π Yarana IoT Guru
π€ Services Offered:
- Custom IoT Product Development
- Embedded Systems Training
- College Workshops & FDPs
- PCB Design & Prototyping
π¦ Twitter / X
Real-time updates, polls, project launches & community Q&A: π @YaranaIoTGuru π’ Follow for instant alerts
π Hackster.io (Project Showcases)
In-depth write-ups, circuits, BOM, code & ratings: π hackster.io/yaranaiotguru π 50+ Projects | 100K+ Views | Top 5% Creator
π Community Platforms
| Platform | Link | Purpose |
|---|---|---|
| Telegram Channel | t.me/YaranaIoTGuru | Project files, PDFs, updates |
| Telegram Group | t.me/YaranaIoTCommunity | Peer support, doubts |
| Discord Server | discord.gg/yarana-iot | Live voice help, coding rooms |
| WhatsApp Community | Join Here | Announcements & polls |
π’ Office & Studio Address
Yarana Studio & Software (Yarana IoT Guru HQ) π Near Rookh Baba Mandir, Umariya Badal Urf Gainda, Allahabad (Prayagraj), Uttar Pradesh β 212507, India β Google Rating: 5.0 β (100+ Reviews)
π Opening Hours: MonβSat: 10:00 AM β 5:00 PM Sunday: Closed
π Associated Website: yaranawebtech.in πΊοΈ View on Google Maps: Search “Yarana Studio & Software” π Walk-ins welcome |