Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
An ESP32 can connect physical wall switches, a mobile app and a browser dashboard through Firebase Realtime Database, giving each control method a shared view of appliance state. The basic flow is app, dashboard or switch → Firebase → ESP32 → relay → appliance.
This is a useful educational and prototyping architecture, but the example project should not be treated as a finished household installation. Its unrestricted database rules, embedded credentials, blocking Wi-Fi connection and limited failure handling require substantial security, electrical and reliability improvements before deployment. The reference project was published on January 30, 2026, and is marked “Beginner Showcase (no instructions).” See the original Hackster project.
What this project builds
The design uses an ESP32 Wi-Fi microcontroller as the local controller for lights, fans or other loads. Firebase Realtime Database acts as the shared cloud state store. An Android application, web dashboard and physical switches can all change the same values, while the ESP32 reads those values and drives relay outputs.
Android app / web dashboard / physical switches
↓
Firebase Realtime Database
↓
ESP32
↓
relay module or driver
↓
isolated test load
Firebase is not an appliance-control protocol. It provides cloud storage and synchronization. The firmware remains responsible for local switching, debouncing, reconnection, safe startup, offline behavior and deciding what to do when a cloud read fails.
#1 Best Overall
- 2.4GHz Dual Mode WiFi + Bluetooth Development Board
- Support LWIP protocol, Freertos
- SupportThree Modes: AP, STA, and AP+STA
- Ultra-Low power consumption, Compatible with Arduino IDE
- ESP32 is a safe, reliable, and scalable to a variety of applications
Why use Firebase Realtime Database?
A shared database can prevent each interface from maintaining a separate ON/OFF value. If a wall switch changes a light, the ESP32 can write the new state to Firebase; the app and browser dashboard can then display that same value. Conversely, a dashboard change can be read by the ESP32 and applied to the relay.
This works well for an educational project or a small cloud-connected prototype where several clients need to observe a small number of Boolean values. It is less suitable when the home must keep operating during an Internet outage, when deterministic local response is essential, or when the system controls safety-critical equipment.
Example database model
The source project uses a simple structure:
/home
/room1
light1: true
fan1: false
Here, true means ON and false means OFF. This is easy to understand, but it cannot tell the difference between a requested state and a state the ESP32 actually applied. A more dependable design separates those concepts:
/devices
/living-room-light
desiredState: true
reportedState: true
online: true
lastSeen: 1712345678
ownerUid: "user-id"
firmwareVersion: "1.0.0"
- Desired state: the requested appliance condition.
- Reported state: what the controller believes it applied.
- Online and lastSeen: communication status, not proof that a relay contact is physically healthy.
- Owner identity: authorization information for multi-user systems.
- Command history: optional timestamped records for diagnostics and auditing.
A relay output alone does not confirm that a lamp or motor actually operated. Add current sensing or another feedback mechanism if physical confirmation matters.
Hardware required
- ESP32 development board
- 4- or 8-channel relay module, or a properly designed relay driver
- Physical switches
- Regulated 5 V and/or 3.3 V power supply
- Jumper wires, terminal blocks, connectors and an enclosure
- Low-voltage test load such as an LED module or small DC lamp
- Optional sensors, status LEDs, display or current-monitoring hardware
Before choosing a relay board, verify its contact rating for the actual load, including motor or fan startup current. Also check whether its input accepts 3.3 V logic, whether it is active-low or active-high, whether it needs a separate 5 V supply and whether its isolation and enclosure are appropriate.
Rank #2
- Dual-Core Performance Up to 240 MHz: Run sensor processing, wireless communication, automation logic and connected-device tasks on a 32-bit dual-core ESP32 platform designed for responsive embedded and IoT projects
- Built-in Wi-Fi and Bluetooth 4.2: Connect to 2.4 GHz Wi-Fi networks or use Bluetooth Classic and BLE for wireless sensors, smart devices, remote controls, home automation and other connected projects
- Flexible Power-Saving Modes: ESP32 power-management features support dynamic clock scaling and low-power operating modes, helping developers reduce energy use in compatible sensing, monitoring and connected-device applications, suitable for battery-powered Internet of Things (IoT) devices.
- USB-C Programming with CP2102: Connect through USB-C for power, sketch uploads and serial monitoring, while GPIO, UART, SPI and I2C interfaces support sensors, displays, motor drivers and other modules (USB-C cable not included)
- Over-the-Air Update Support: Configure OTA functionality through a compatible ESP-32 software framework to update deployed firmware over Wi-Fi without reconnecting the board by USB for every revision
The example assigns GPIO 26 to the light relay, GPIO 27 to the fan relay, GPIO 32 to one switch and GPIO 33 to another. These are example assignments, not universal requirements. Confirm that the pins are available on the exact ESP32 board and that the relay module behaves as expected.
Electrical safety: keep mains work out of the beginner path
Do not connect household AC directly to an ESP32 or prototype exposed mains wiring on a breadboard. Start with an isolated low-voltage load. For fixed-house wiring, use a properly enclosed and rated relay or contactor, appropriate fusing and overcurrent protection, strain relief, insulation, creepage and clearance. A qualified electrician should install or inspect mains-connected equipment.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsFans and motors are inductive loads and can impose substantial startup currents. A relay’s printed rating may apply only to a resistive load, so check the manufacturer’s specifications for the intended voltage and load type. Provide a manual fallback where loss of Wi-Fi, Firebase or controller power could create an unsafe or inconvenient condition.
Software stack
The source project names the following tools:
- Arduino IDE
- ESP32 Arduino core
- Firebase ESP Client by Mobizt
- Firebase Realtime Database
- Android app written in Java or Kotlin
- HTML, CSS and JavaScript dashboard
- Optional WiFi Manager-style provisioning
Install “Firebase ESP Client by Mobizt” through the Arduino IDE Library Manager if following the source example. For a reproducible build, document the tested ESP32 core, library and Arduino IDE versions rather than assuming that future APIs will remain identical.
Firebase setup
- Open the Firebase Console and create a project.
- Create a Realtime Database in the required region.
- Create the initial device paths, such as
/home/room1/light1and/home/room1/fan1. - Enable an appropriate sign-in method through Firebase Authentication.
- Configure the ESP32 with placeholders for Wi-Fi, database URL and supported authentication credentials.
- Flash the firmware and test reads and writes from the console.
The source shows these rules for temporary testing:
Rank #3
- Powerful ESP-32 Board: Unlock the world of Internet of Things (IoT) and advanced electronics with the heart of this kit: the ESP-32 board. It features a powerful dual-core processor, integrated Wi-Fi and Bluetooth 4.2, making it perfect for building connected, smart devices that communicate with your phone or the cloud. It's fully compatible with the Arduino IDE for easy programming.
- Super Starter Kit: This kit contains over 35 different modules and electronic components, including sensors, displays, motors, and input devices. From LEDs and buttons to an OLED screen, servo motor, and keypad, you have everything needed to explore a vast range of projects in one box.
- Step by Step Online Tutorial: Jump right in with our detailed, beginner-friendly tutorial. Access 30+ projects with complete code, clear circuit diagrams, and step-by-step instructions. Learn the fundamentals of electronics, coding, and how to utilize the ESP-32's unique capabilities without any prior experience.
- Hands-on Learning for All Skill Levels: Perfect for students, makers, engineers, and hobbyists. Start with basic circuits and coding, then progress to intermediate and advanced IoT applications. Build practical projects like weather stations, smart home controllers, remote-controlled devices, and interactive gadgets. The skills you learn are the foundation for real-world innovation.
- Quality & Great Support: Elegoo is committed to quality. We provide a clear, detailed tutorial guide, refined code, and a well-organized component kit. All modules are carefully selected for reliability and ease of use. Our dedicated technical support team and active online community are ready to help you succeed in your learning journey.
{
"rules": {
".read": true,
".write": true
}
}
Never use those rules on a deployed system. They allow unauthenticated users to read and write the entire database. A real deployment should require authenticated users and restrict access to only the devices or paths each user is authorized to control. Consult the current Realtime Database Rules documentation when writing and testing the exact rule syntax.
Free tools Windows power users keep installed
One-click scans. No signup required.
How the example firmware works
Initialization
The sketch starts serial output at 115200 baud, configures relay pins as outputs, configures switch pins with INPUT_PULLUP, and sets the relay outputs HIGH. Because the example uses active-low logic, HIGH represents the inactive relay state and LOW activates it.
digitalWrite(RELAY_LIGHT, lightState ? LOW : HIGH);
digitalWrite(RELAY_FAN, fanState ? LOW : HIGH);
This polarity is hardware-dependent. Some boards are active-high, and some relay modules can briefly switch during ESP32 boot. Test the module with the load disconnected and define a safe startup state.
The sketch then calls WiFi.begin() and waits for WL_CONNECTED, printing a dot every 500 milliseconds. It configures the Firebase URL and authentication value, starts Firebase and enables Wi-Fi reconnection.
Main loop
- Read the light Boolean from Firebase.
- Read the fan Boolean.
- Convert each value into the relay output level.
- Read the physical switches.
- Compare switch readings with their previous states.
- Write a changed switch state back to Firebase.
- Wait 300 milliseconds after a switch update.
The fixed delay is a simple debounce technique, not a universal solution. A non-blocking stable-state timer is preferable because it allows the controller to continue processing communication and other inputs.
Recommended Free Tools
Rank #4
- 2.4GHz Dual Mode WiFi + Bluetooth Development Board
- Support LWIP protocol, Freertos;ESP32 is a safe, reliable, and scalable to a variety of applications
- SupportThree Modes: AP, STA, and AP+STA
- Ultra-Low power consumption, Compatible with Arduino IDE
- 1PCS 30Pin ESP32 Development Board 2.4GHz WiFi Dual Cores Microcontroller Integrated with Antenna RF Low Noise Amplifiers Filters
Important limitations in the example
- The project does not document tested software versions.
- The complete Android app and web dashboard are not supplied.
- Authentication and least-privilege authorization are not demonstrated.
- Credentials or a legacy database-secret pattern are placed in firmware configuration.
- The startup Wi-Fi loop can wait indefinitely.
- There is no watchdog strategy, exponential reconnect backoff or defined offline mode.
- A failed Firebase read is not clearly distinguished from an OFF value.
- There is no desired-versus-reported state.
- Simultaneous writes from the app, dashboard and switch have no arbitration policy.
- There is no OTA update process, audit log, scheduling, voice integration or energy measurement.
- No wiring diagram, enclosure design or mains procedure is provided.
The author presents the architecture as “production-ready” and aims to avoid ON/OFF mismatches, but the supplied implementation does not establish those claims through documented security review, latency measurements, conflict tests or outage tests. Treat them as design goals, not verified results.
Define failure behavior before installing anything
Wi-Fi loss
A robust controller should continue accepting physical switch input, preserve the last safe relay state, reconnect without blocking the control loop and mark itself offline after a timeout. Decide whether locally generated changes are queued, discarded or synchronized after reconnection.
Firebase read failure
Log the error code and reason, preserve the last known state and never convert an unknown or failed read into false automatically. The UI should show stale or offline status rather than claiming that the appliance is OFF.
Simultaneous writes
If an app writes ON while a wall switch writes OFF, define whether the latest valid command wins or whether a higher-level controller arbitrates commands. Timestamped commands, source metadata, device identifiers and separate desired/reported fields make conflicts easier to diagnose.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Reboot and power interruption
Choose a safe startup policy for each load. Restoring the last cloud state may be acceptable for a light but unsafe for a heater, pump, motor or lock. Some loads should remain OFF until an authenticated command is received and the controller is fully initialized.
Best Value
- 2.4GHz Dual Mode WiFi + Bluetooth Development Board
- Ultra-Low power consumption, works perfectly with the Arduino IDE
- Support LWIP protocol, Freertos
- SupportThree Modes: AP, STA, and AP+STA
- ESP32 is a safe, reliable, and scalable to a variety of applications
App and dashboard contract
Because the source does not include complete client implementations, the expected behavior should be specified clearly:
- A toggle writes a desired state, not an unverified physical result.
- The interface subscribes to the same device node used by the ESP32.
- Pending, confirmed, offline and error states are visually distinct.
- Changes made by a physical switch appear in both the app and browser.
- Users cannot edit another user’s device paths.
A polling loop that repeatedly calls getBool() should not automatically be described as an instant live stream. If lower latency and fewer repeated reads are required, use a supported streaming or event-driven approach and verify it against the current client-library documentation.
Testing checklist
- Turn the light ON from the app and verify the relay.
- Turn it OFF from the browser and verify the app updates.
- Operate the physical switch and confirm the database changes.
- Change Firebase directly and confirm the relay responds.
- Reverse or substitute relay polarity and confirm the firmware detects the configuration.
- Disconnect Wi-Fi while operating the physical switch.
- Make Firebase unavailable and observe the defined fallback.
- Reboot the ESP32 and verify the startup state.
- Write conflicting commands from two clients.
- Test switch bounce with the actual switch hardware.
- Interrupt power during a command.
- Inspect serial logs for connection, authentication and database errors.
Security hardening
- Use Firebase Authentication and restrictive per-user or per-device rules.
- Do not publish database secrets, tokens or Wi-Fi passwords.
- Rotate credentials if source code or firmware may have been exposed.
- Use unique device identities and least-privilege access.
- Plan authenticated OTA updates and rollback protection.
- Record important commands and authentication events where appropriate.
- Keep sensitive household data to the minimum required.
Credentials compiled into firmware can be extracted from shared binaries. A leaked database credential can compromise every device or path it can access, and changing it may require reflashing devices.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteCloud-first or local-first?
| Architecture | Advantages | Trade-offs |
|---|---|---|
| Cloud-first: app/dashboard → Firebase → ESP32 | Simple remote access, shared state and browser integration | Internet dependency, cloud outages, latency, credential risk and possible usage charges |
| Local-first: switch/app → local controller → ESP32, with cloud sync | Works during Internet loss, faster response and better privacy | More infrastructure, maintenance and remote-access design |
For a real home, local control with optional cloud synchronization is generally the safer direction. Firebase-only control remains valuable for learning, demonstrations and small non-critical prototypes.
When Firebase is a good or poor fit
Good fit: a quick cloud backend, a small number of synchronized values, a browser or mobile interface and an educational deployment where Internet dependence is acceptable.
Poor fit: safety-critical equipment, deterministic local control, high-frequency telemetry, privacy-sensitive households, systems that must operate without Internet or deployments seeking to avoid vendor dependence and recurring cloud usage charges. Review the current Firebase pricing before scaling.
Alternatives
- Home Assistant: strong local automation and broad integrations, with more setup and maintenance.
- ESPHome: fast ESP32 configuration and Home Assistant integration, but less appropriate when custom firmware is the main goal.
- Blynk: hosted dashboards and mobile controls with platform dependence and plan limits.
- MQTT with a local broker: flexible and efficient, but requires additional infrastructure and security configuration.
- Matter: an interoperability-focused smart-home direction, not a direct Firebase replacement.
Bottom line
This ESP32 and Firebase project is a clear demonstration of shared cloud state for smart-home controls. It is appropriate as a low-voltage prototype when readers understand that the original short sketch does not provide production security, reliable offline operation or safe mains installation. Build and test the controller with an isolated load first; for a household system, add authentication, restrictive rules, non-blocking firmware, explicit failure policies and professional electrical installation. The commercial distinction is important: an inexpensive educational demonstrator is not the same product as an enclosed, locally resilient and professionally installed automation system.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.


Leave a Reply