Most home automation projects work well only from mobile apps, but fail when manual switches are used.For example:
App shows Light ON
- App shows Light ON
But someone turns it OFF from wall switch
- But someone turns it OFF from wall switch
App and system go out of sync β
- App and system go out of sync β
This project was built to solve that exact real-world problem.
The goal was simple:
Create a smart home system where mobile app, web dashboard, and physical switches always stay perfectly synchronized in real time.
Create a smart home system where mobile app, web dashboard, and physical switches always stay perfectly synchronized in real time.π§ Core Concept (Easy to Understand)
This system uses Firebase Realtime Database as the central brain.
Think of Firebase as a live notebook in the cloud:
Everyone (App, Web, ESP32) reads from it
- Everyone (App, Web, ESP32) reads from it
Everyone writes to it
- Everyone writes to it
Any change updates instantly everywhere
- Any change updates instantly everywhere
So instead of controlling relays directly from app or switch,π everything talks to Firebase first.
π How the System Works (Step-by-Step)User presses a button on mobile app
- User presses a button on mobile app
App updates Firebase value (ON/OFF)
- App updates Firebase value (ON/OFF)
ESP32 listens to Firebase
- ESP32 listens to Firebase
ESP32 turns relay ON/OFF
- ESP32 turns relay ON/OFF
Status updates back to Firebase
- Status updates back to Firebase
Web dashboard & app show updated state
- Web dashboard & app show updated state
Same flow happens if:
Web dashboard is used
- Web dashboard is used
Manual wall switch is pressed
- Manual wall switch is pressed
β Result: No mismatch, no confusion
π§© System ArchitectureMobile App Web Dashboard Manual Switch
\ | /
Firebase
|
ESP32
|
Relay Module
|
Home Appliances
Mobile App Web Dashboard Manual Switch
\ | /
Firebase
|
ESP32
|
Relay Module
|
Home Appliances
π© Hardware Setup (Simple & Practical)Components UsedESP32 Development Board
- ESP32 Development Board
4-Channel / 8-Channel Relay Module
- 4-Channel / 8-Channel Relay Module
Manual Wall Switches
- Manual Wall Switches
AC Bulb / Fan (for testing)
- AC Bulb / Fan (for testing)
5V Power Supply
- 5V Power Supply
Jumper Wires
- Jumper Wires
ESP32 GPIO pins β Relay IN pins
- ESP32 GPIO pins β Relay IN pins
Relay COM & NO β AC load
- Relay COM & NO β AC load
Manual switches β ESP32 input pins (with INPUT_PULLUP)
- Manual switches β ESP32 input pins (with INPUT_PULLUP)
β οΈ Safety Tip:Always be careful while working with AC supply.If possible, test first with low-voltage loads.
β οΈ Safety Tip:Always be careful while working with AC supply.If possible, test first with low-voltage loads.βοΈ Firebase Realtime Database SetupStep 1: Create Firebase Project
Go to Firebase Console
- Go to Firebase Console
Create a new project
- Create a new project
Enable Realtime Database
- Enable Realtime Database
{
"devices": {
"device01": {
"relay1": 0,
"relay2": 0,
"relay3": 0,
"relay4": 0
}
}
}
{
"devices": {
"device01": {
"relay1": 0,
"relay2": 0,
"relay3": 0,
"relay4": 0
}
}
}
0 = OFF
0= OFF
1 = ON
1= ON
This structure is shared by ESP32, App, and Web.
π ESP32 Pin MappingRelay
ESP32 GPIO
Relay 1
GPIO 23
Relay 2
GPIO 22
Relay 3
GPIO 21
Relay 4
GPIO 19
Manual switches are connected to input pins like:GPIO 32, 33, 25, 26
ESP32 does three main jobs:
1οΈβ£ Connect to WiFiESP32 connects to home WiFi so it can talk to Firebase.
2οΈβ£ Listen to FirebaseIt continuously checks:
/devices/device01/relay1
/relay2
/relay3
/relay4
/devices/device01/relay1
/relay2
/relay3
/relay4
Whenever a value changes β relay updates instantly.
3οΈβ£ Read Manual SwitchesIf a wall switch is pressed:
ESP32 changes relay state
- ESP32 changes relay state
Updates Firebase
- Updates Firebase
App & Web auto-update
- App & Web auto-update
Without Firebase sync:
App shows wrong state β
- App shows wrong state β
User gets confused β
- User gets confused β
With this system:
Single source of truth = Firebase β
- Single source of truth = Firebase β
Real home usability β
- Real home usability β
Professional-grade automation β
- Professional-grade automation β
The mobile app:
Uses Firebase SDK
- Uses Firebase SDK
Reads relay values
- Reads relay values
Writes ON/OFF values
- Writes ON/OFF values
No direct ESP32 connection needed.Works from anywhere in the world π
π Web Dashboard ControlThe web interface:
Uses Firebase JavaScript SDK
- Uses Firebase JavaScript SDK
Shows live relay status
- Shows live relay status
Allows toggle control
- Allows toggle control
Perfect for:
Admin panel
- Admin panel
Browser-based control
- Browser-based control
Desktop users
- Desktop users
This is what makes the project special.
β Switch ON β App & Web show ONβ App OFF β Relay OFF + Switch syncβ No false statusβ Real-life usable system
π Security NotesUse Firebase authentication
- Use Firebase authentication
Apply database rules
- Apply database rules
Restrict device access
- Restrict device access
Never leave database open in production.
π Possible ImprovementsTimers & schedules
- Timers & schedules
Voice control (Alexa / Google)
- Voice control (Alexa / Google)
Energy monitoring
- Energy monitoring
Multiple rooms & users
- Multiple rooms & users
Device registration system
- Device registration system
This project is not just a demo βitβs a real, scalable, and practical smart home system.
Whether you are:
A beginner learning IoT
- A beginner learning IoT
A student building a project
- A student building a project
A developer planning a product
- A developer planning a product
This architecture gives you a solid foundation π₯









Comments