Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An ESP32 can connect sensors or a low-voltage control circuit to Firebase Realtime Database over HTTPS. Firebase stores the project’s data as JSON and synchronizes changes to connected clients, while the ESP32 can use the database’s REST API to read commands and report device state. This guide lays out the architecture and implementation decisions; because no board, circuit, or authentication setup is specified, it does not prescribe pin assignments or claim a ready-to-upload sketch.

What you need to decide before building

ESP32 identifies a family of chips and boards, not one fixed project configuration. Before selecting libraries, wiring a sensor, or writing firmware, decide which board and development framework you will use, what the device will monitor or control, and how it will authenticate to Firebase.

  • Board and framework: Espressif’s ESP-IDF is its official framework for ESP32-series systems-on-chip. Espressif’s ESP-IDF User Guide for ESP32, SDK v5.3.5, describes development-board setup, but it does not select a board for unspecified peripherals. If you use Arduino tooling instead, choose libraries, board settings, and pin mapping that match that actual setup.
  • Inputs and outputs: Identify the sensor interfaces and the electrical requirements of anything being switched before choosing components. A generic ESP32-and-relay description is not a wiring plan.
  • Data ownership: Decide which client writes commands, which device reports applied state, and which users or devices can read each database path.
  • Authentication: Choose an identity and access policy before connecting a real device. A request that omits authentication succeeds only if the database rules allow that access.

Design the database around commands and reported state

Realtime Database is a JSON tree addressed by paths. A useful design separates what a user wants a device to do from what the device says it has done. For example, a project could organize data under a home and device, with separate branches for desired settings, reported state, and sensor readings:

homes/{homeId}/devices/{deviceId}/desired
homes/{homeId}/devices/{deviceId}/reported
homes/{homeId}/devices/{deviceId}/sensors

This is an example schema, not a Firebase requirement. The key distinction is that writing a command should not be presented as proof that the physical device changed. The ESP32 should report the state it has applied separately; a user interface can then distinguish a requested setting from the device’s response.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (3PCS)
  • 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

Keep paths aligned with your access policy. For instance, a user-specific home path can make it possible for rules to compare the path’s user key with the authenticated user’s ID. Give each branch a clear writer and reader: a web or mobile client might write desired settings, while the ESP32 writes reported state and sensor values.

Connect the ESP32 to the Realtime Database REST API

Firebase’s REST API accepts HTTPS requests to a database path when .json is appended to the path’s URL. Use the exact database URL shown for your Firebase project. The documented format differs by location: DATABASE_NAME.firebaseio.com is used for us-central1, while other locations use a regional firebasedatabase.app form.

Rank #2
Sale
ELEGOO 3PCS ESP-32 Dev Boards, ESP-WROOM-32, USB-C, WiFi Bluetooth 4.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

Choose the HTTP method according to the change you intend to make. They are not interchangeable:

Method Use Effect at the target path
GET Read a value Returns the data at that path.
PUT Set or replace a value Replaces the data at the target path.
PATCH Change selected children Updates the named children without deleting omitted children.
POST Add a new list item Creates a child under a generated key.
DELETE Remove data Deletes the value at the target path.

For example, a device reading a desired setting needs a read operation on that setting’s path. When it reports a sensor value, choose whether to replace the latest reading at one path or append a new record under a generated key. That choice affects how the data is retained and how clients consume it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
ELEGOO ESP-32 Super Starter Kit with Tutorial Compatible with Arduino IDE
  • 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.
  1. Connect to the network: Have the firmware establish its network connection and detect when it is unavailable.
  2. Form the request: Use the project’s database URL, the intended data path, the .json suffix, the correct HTTP method, and a JSON body when the operation writes data.
  3. Authorize it: Include the appropriate Firebase Authentication token when the rules require an authenticated request.
  4. Check the response: Handle HTTP status and returned data rather than assuming a request succeeded because it was sent.
  5. Recover deliberately: Define what the device does after a timeout, a rejected request, or a lost network connection. Retry behavior should avoid accidentally treating an unconfirmed command as an applied physical state.

Firebase documents Server-Sent Events as an option for streaming database changes. A REST client that uses streaming must handle events and redirects; it is not the same as periodically issuing a read request. The appropriate choice depends on whether the device needs continuous updates, connection resources, and the implementation effort the selected framework can support.

Choose REST or a Firebase SDK for the device

Firebase SDKs handle authentication and database communication automatically in supported client environments. Direct REST works through HTTPS and standard HTTP methods, but the firmware must implement the details itself. The best fit depends on SDK availability for the chosen framework, memory and connection needs, authentication lifecycle, whether the device needs a persistent stream, and the maintenance burden.

Rank #4
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (1 PCS)
  • 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
Approach What it provides What to account for
Firebase SDK Automatic authentication and database communication in supported environments, according to Firebase. Confirm that a suitable SDK supports the selected board and framework.
REST over HTTPS Path-based database access using standard HTTP operations; Firebase also documents Server-Sent Events. Implement request handling, authentication and token renewal where applicable, JSON parsing, status checks, network recovery, and any streaming behavior.

Do not assume the SDK is available for every embedded framework or that REST is automatically simpler. Compare support and connection behavior for the exact board and software stack you select.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Secure the database before connecting a device

Firebase Realtime Database Security Rules are enforced on the server. By default, rules deny access; .read and .write determine who can read or write, while .validate can constrain incoming data. Google Firebase’s “Understand Firebase Realtime Database Security Rules” explains the default-deny behavior. Rules that grant read or write access cascade to descendants, while validation rules do not cascade in the same way.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
HiLetgo ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA for Arduino IDE
  • 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
  • Require an appropriate authenticated identity for device and user access, then scope permissions to the paths that identity should use.
  • Use validation rules to constrain expected data types or required children rather than trusting every client to send well-formed values.
  • Review every parent rule: a broad grant at a higher path can extend access to its descendants.
  • Do not leave test-mode permissions in a deployed project. Firebase warns that test mode can allow anyone to read and overwrite data.

Firebase supports ID tokens and OAuth access tokens for REST authentication. For a device or user acting under database rules, use an appropriate Firebase Authentication identity and its ID token. Do not embed a service-account key or other privileged server credential in ESP32 firmware, a public repository, or a web or mobile client. Firebase’s REST authentication guidance warns that exposing such credentials can compromise project security; privileged OAuth access belongs in a protected server environment.

Keep the physical control circuit within its evidence and safety limits

The components, pinout, power supply, and load are project-specific. Neither a generic ESP32 board nor a relay module establishes that a household appliance can be switched safely. First match every component to the selected board’s electrical interface and the circuit’s voltage and current requirements.

Keep an example circuit within a documented low-voltage design. For mains applications, use an appropriately certified, enclosed switching device and qualified electrical guidance. ESP-IDF includes platform security features, but that capability does not establish that a particular circuit, firmware configuration, or installation is safe, reliable, or tested.

Test the data flow before relying on automation

  1. Confirm that the ESP32 can connect to the network and that it is using the database URL for the correct project and location.
  2. Test a read and a write against the intended paths, using the authentication method and rules the deployed device will use.
  3. Check that writes use the intended operation: replacing a path with PUT is different from updating selected children with PATCH.
  4. Verify that invalid or unauthorized requests are rejected and that the firmware handles the response without reporting a failed action as successful.
  5. Check the separation between desired and reported state: the device should update its reported branch only after it has applied the command it can actually confirm.
  6. Test what happens when the network is interrupted or a request fails before connecting the system to any real load.

These checks verify the database communication flow; they do not certify the electrical design or establish real-world reliability. Firebase APIs and Espressif framework documentation can change, so verify the applicable documentation for the versions used in a project.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.