Building Real-Time IoT Dashboards with ESP32 and Firebase
Why Firebase for IoT?
Firebase Realtime Database gives you WebSocket-style updates with zero infrastructure — no MQTT broker to manage, no server to provision. For small-to-medium IoT projects where you need live data in a browser or mobile app without building a backend, it is the fastest path from sensor to dashboard.
Hardware Setup
Any ESP32 board works. For this project: an ESP32 DevKit v1, a DHT22 temperature and humidity sensor on GPIO 4, and a 3.3V power supply. Total BOM cost under $5.
Firmware
The ESP32 connects to WiFi, authenticates with Firebase using a database secret, and pushes sensor readings every 10 seconds.
#include <WiFi.h>
#include <FirebaseESP32.h>
#include <DHT.h>
FirebaseData fbData;
DHT dht(4, DHT22);
void loop() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
if (!isnan(temp) && !isnan(hum)) {
Firebase.setFloat(fbData, "/sensors/temperature", temp);
Firebase.setFloat(fbData, "/sensors/humidity", hum);
}
delay(10000);
}
Dashboard
Firebase's REST API streams data to a plain HTML page via EventSource. No framework required — a 50-line HTML file with Chart.js renders a live temperature graph with sub-second latency.
Latency and Bandwidth
At 10-second polling intervals, a single device consumes approximately 150 KB/day of Firebase bandwidth — well within the free Spark plan limit of 10 GB/month. End-to-end latency from sensor reading to browser update averages 800 ms on a local WiFi network.