Table of Contents
KEY TAKEAWAYS
- Firebase Realtime Database provides a cloud-hosted JSON database accessible via REST API
- NodeMCU can send data to Firebase using HTTPS requests with the Firebase host and auth token
- Real-time data updates from Firebase can trigger actions on the NodeMCU (e.g., turning an LED on/off)
- Firebase is a good alternative to AWS IoT for simpler IoT projects with real-time sync
What is Google Firebase ?
Firebase is Google’s database platform which is used to create, manage and modify data generated from any android application, web services, sensors etc. For more information on Firebase please visit the official website of Firebase.Benefits of Using Google Firebase
- You can operate LED from anywhere using Internet (on Global Sever)
- Your Data will be stored and can be accessed anytime from anywhere
- Google Firebase is easy to understand and free for up to 10 GB data, which is sufficient for Home based Projects
Setting Up NodeMCU With LED
Before starting with Google Firebase, we need to set up the LED to NodeMCU. So, refer the components required section and connection figure below.Components required
- NodeMCU ESP8266(12E)
- Resistor (100 Ω)
- An LED
LED Connection from NodeMCU
- Positive terminal of LED to D3 Pin of NodeMCU (Via Resistor)
- LED Negative terminal to GND Pin of NodeMCU

Adding Required libraries for Firebase Connection
Their are two libraries which need to be downloaded for connection to Google Firebase in your Arduino IDE- Arduino JSON
- Firebase Arduino

Setting Up Firebase Console
Create a Project by going to : https://firebase.google.com/





Programming NodeMCU for using Google Firebase
Firstly include the libraries for using NodeMCU and firebase#include <ESP8266WiFi.h #include <FirebaseArduino.hDefine Firebase Database URL and Authentication Database Secrets Key
#define FIREBASE_HOST "your-project.firebaseio.com" // Database URL #define FIREBASE_AUTH "06dEpqanFg***************qAwnQLwLI" // the secret key generated from firebase Database SecretsDefine SSID (WIFI Name) and Password for Internet Connection
#define WIFI_SSID "xxxxxxxxxxxxx" // input your home or public wifi name #define WIFI_PASSWORD "xxxxxxxxxxxxxx" //password of wifi ssidInitialize Wifi and Firebase Connection
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebaseSetting Firebase String and Get request commandsFirebase.setString("LED_STATUS", "OFF"); //send initial string of led status
fireStatus = Firebase.getString("LED_STATUS"); // get ld status input from firebase
if (fireStatus == "ON" || fireStatus == "on") { // compare the input of led status received from firebase
Serial.println("Led Turned ON");
digitalWrite(LED_BUILTIN, HIGH); // make bultin led ON
digitalWrite(led, HIGH); // make external led ON
}
else if (fireStatus == "OFF" || fireStatus == "off") { // compare the input of led status received from firebase
Serial.println("Led Turned OFF");
digitalWrite(LED_BUILTIN, LOW); // make bultin led OFF
digitalWrite(led, LOW); // make external led OFF
}
else {
Serial.println("Wrong Credential! Please send ON/OFF");
}After Flashing this code you can go to your Realtime database console and change the LED_STATUS to “on” and observe that your LED will glowFull Code:
#include <ESP8266WiFi.h> // esp8266 library
#include <FirebaseArduino.h> // firebase library
#define FIREBASE_HOST "your-project.firebaseio.com" // the project name address from firebase id
#define FIREBASE_AUTH "06dEpqanFg***************qAwnQLwLI" // the secret key generated from firebase
#define WIFI_SSID "xxxxxxxxxxxxx" // input your home or public wifi name
#define WIFI_PASSWORD "xxxxxxxxxxxxxx" //password of wifi ssid
String fireStatus = ""; // led status received from firebase
int led = D3; // for external led
void setup() {
Serial.begin(9600);
delay(1000);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(led, OUTPUT);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected to ");
Serial.println(WIFI_SSID);
Serial.print("IP Address is : ");
Serial.println(WiFi.localIP()); //print local IP address
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // connect to firebase
Firebase.setString("LED_STATUS", "OFF"); //send initial string of led status
}
void loop() {
fireStatus = Firebase.getString("LED_STATUS"); // get ld status input from firebase
if (fireStatus == "ON") { // compare the input of led status received from firebase
Serial.println("Led Turned ON");
digitalWrite(LED_BUILTIN, LOW); // make bultin led ON
digitalWrite(led, HIGH); // make external led ON
}
else if (fireStatus == "OFF") { // compare the input of led status received from firebase
Serial.println("Led Turned OFF");
digitalWrite(LED_BUILTIN, HIGH); // make bultin led OFF
digitalWrite(led, LOW); // make external led OFF
}
else {
Serial.println("Wrong Credential! Please send ON/OFF");
}
} 📖 Related: How to Create a "Thing" in AWS IoT

Vivek Bhageria — Lead Firmware R&D Engineer, 12+ years. Ex-Bosch (automotive powertrain), MusicTribe (real-time audio), medical devices. M.Tech BITS Pilani. I write at NerdyElectronics — practical, register-level embedded systems for engineers who want to understand what’s actually happening under the hood.







