Cyber Chasse- Firebase Controlled LED

Firebase controlled LED using Node MCU

What is Firebase?? 
The Firebase Realtime Database is cloud-hosted where the data is saved as JSON and contemporized in real-time with all the connected clients. 
1. Open “” 
2. If you have a Gmail id, you don’t have to Sign Up for firebase. If you don’t have a Gmail id, Sign Up for firebase and proceed to the next step. 
3. Click on “Go to Console” from the top right corner. 

Firebase controlled LED

4. Select “Add project”. 

Firebase controlled LED

5. Type your Project Name. 
6. Accept the terms and conditions, create a new project, and select “Continue”. 
7. Click on “Project Settings” from the settings option. 

Firebase controlled LED

8. Now go to “Service Accounts”. 

Firebase controlled LED

9. You will see “Firebase admin SDK” and “Database Secrets” options. 
10. Go to “Database Secrets”. 
11. Hover the cursor over your project name. The option “Show” will appear on the right side of your project. 
12. Click on “Show” and the secret key generated for your project appears.  


13. Copy and save the secret key in notepad. This is your “FIREBASE_AUTH” string, written in the Arduino program. 
14. Now, go to “Database” from the left control bar. 
15. Scroll down to select “Create Database”. 

Firebase controlled LED

16. Choose “Enable” from “Start in test mode”. 
17. You will see this right above the database: 

Firebase controlled LED

18. Copy “” without https and slash. Save this also to notepad along with the secret key. 
19. This is your “FIREBASE_HOST” string, written in the Arduino program. 
Upload the sketch when the “FIREBASE_AUTH” and “FIREBASE_HOST” are added in Arduino program. Now both the sections are set up and the complete Arduino Program is available. 
1. NodeMcu 
2. Neopixel 
1. Arduino IDE 
2. Firebase service 

Firebase controlled LED

Source code: 

 #include “FirebaseESP8266.h” 
 #include <ESP8266WiFi.h> 
 #include <Adafruit_NeoPixel.h> 
 #define PIN 5 
 #define NUM_LEDS 1 
 const char* ssid = “XXXXXX”; 
 const char* password = “XXXXXXX”; 
 FirebaseData firebaseData; 
 Adafruit_NeoPixel leds(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800); 
 // Current color values 
 int redValue = 0; 
 int greenValue = 0; 
 int blueValue = 0; 
 void setup() { 
 void loop() { 
   if (Firebase.getInt(firebaseData, “/red”)) { 
     if  (firebaseData.dataType() == “int”) { 
       int val = firebaseData.intData(); 
       if (val != redValue) { 
         redValue = val; 
   if (Firebase.getInt(firebaseData, “/green”)) { 
     if  (firebaseData.dataType() == “int”) { 
       int val = firebaseData.intData(); 
       if (val != greenValue) { 
         greenValue = val; 
   if (Firebase.getInt(firebaseData, “/blue”)) { 
     if  (firebaseData.dataType() == “int”) { 
       int val = firebaseData.intData(); 
       if (val != blueValue) { 
         blueValue = val; 
 void connectWifi() { 
   // Let us connect to WiFi 
   WiFi.begin(ssid, password); 
   while (WiFi.status() != WL_CONNECTED) { 
   Serial.println(“WiFi Connected….IP Address:”); 
 void setLedColor() { 
   for (int i=0; i < NUM_LEDS; i++)  
     leds.setPixelColor(i, leds.Color(redValue, greenValue, blueValue));; 

view rawFirebase.ino hosted with ❤ by GitHub 

1) From include library function in Arduino and WIFI Library, add FirebaseESP8266 library. Use Neopixel to change the LED color. 

  • #include “FirebaseESP8266.h” 
  • #include <ESP8266WiFi.h> 
  • #include <Adafruit_Sensor.h> 

2) Setup wifi connection using connectWifi(). 

  • void connectWifi() { 
  •   // Let us connect to WiFi 
  •   WiFi.begin(ssid, password); 
  •   while (WiFi.status() != WL_CONNECTED) { 
  •     delay(500); 
  •     Serial.print(“.”); 
  •   } 
  •   Serial.println(“…….”); 
  •   Serial.println(“WiFi Connected….IP Address:”); 
  •   Serial.println(WiFi.localIP()); 

3) Setup function. 


To connect with firebase, use firebase host and Auth token.  
4) Loop function checks the status of LED value and calls the function setLedColor. 

  • if (Firebase.getInt(firebaseData, “/red”)) { 
  •     if  (firebaseData.dataType() == “int”) { 
  •       int val = firebaseData.intData(); 
  •       if (val != redValue) { 
  •        redValue = val; 
  •          setLedColor(); 
  •       } 

5) The function setLedColor sets the neopixel color accordingly. 

  • void setLedColor() { 
  •   for (int i=0; i < NUM_LEDS; i++)  
  •     leds.setPixelColor(i, leds.Color(redValue, greenValue, blueValue)); 

If you still face issues in this topic, do not hesitate to post your queries in the Comment Box below. Also, for more such informative topics, follow us on 👍 Social Networks😉