Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » IoT Based LED Control using Google Firebase & ESP8266
ESP8266 Projects IoT Projects

IoT Based LED Control using Google Firebase & ESP8266

Mamtaz AlamBy Mamtaz AlamUpdated:August 21, 20224 Comments6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Google Firebase LED ESP8266
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

In this tutorial we will learn about how to Control LED using Google Firebase & ESP8266.


Overview: IoT Based LED Control using Google Firebase & ESP8266

Using the IoT hardware & cloud platform, we can control the IoT devices including LEDs from any part of the world. This mini IoT Based Projects deals with LED Control using Google Firebase Console & NodeMCU ESP8266 wifi Module. There are various methods of controlling of the LED such as using Web Server or Webpage, Blynk Application and using other API based services. But here we will only focus on Google Firebase

Google Firebase is a Google-backed application development software used for creating, managing,and modifying data generated from any android/IOS application, web services, IoT sensors & Hardware. To learn more about the Google Firebase Console, you can read the official Google Firebase Documentation from Google Firebase

Google Firebase




Bill of Materials

Following are the components required for making this project. All the components can be easily purchased from Amazon. The component purchase link is given below.

S.N.Components NameQuantityPurchase Links
1NodeMCU ESP8266 Board1Amazon | AliExpress
2LED 5mm Any Color1Amazon | AliExpress
3Resistor 220-ohm1Amazon | AliExpress
4Power Supply 5V1Amazon | AliExpress
5Connecting Jumper Wires10Amazon | AliExpress
6Breadboard1Amazon | AliExpress

Setting Up Hardware & NodeMCU LED Circuit

Here is a circuit diagram for connecting LED with NodeMCU ESP8266 Board. Connect the positive terminal of LED to GPIO5, i.e D1 of NodeMCU ESP8266 via 220ohm resistor as shown in the figure below.

ESP8266 LED Control


Installing Firebase & JSON Library

FirebaseArduino is a library to simplify connecting to the Firebase database from Arduino clients. It is a full abstraction of Firebase’s REST API exposed through C++ calls in a wiring friendly way. All JSON parsing is handled by the library and you may deal in pure C/Arduino types.

The library cannot work standalone. So you need to add the ArduinoJSON library as well.

1. ArduinoJSON Library

So first go to the library manager and search for “JSON” & install the library as shown in the figure below.

Note: The latest JSON library might not work with the code. So you may need to downgrade the library to version v5.13.5

2. Google FirebaseExtended Library

Now you need to install Google Firebase library as well. So, download the library from below link and add it to Library folder after extraction.

Download Google FirebaseExtended Library


Setting up Google Firebase

To Control the LED using Google Firebase & Nodemcu ESP8266, you need to setup the Google Firebase first. The step is little long but don’t be panic, because I have explained all the steps below.

Step 1: If you have Gmail id then you are already Sign Up for firebase. But if you don’t have Gmail id then first Sign Up for Gmail: https://gmail.com/

Step 2:Now visit https://firebase.google.com/ and click on Go to Console on the Top Right.

Step 3: Click on “Create a Project”.


Step 4: Give your “Project name”, then tick the “I Accept the Firebase Terms” & finally Click on “Continue”.

Step 5: Now, another window will appear. So click on “Continue”.

Step 6: Select the “google Analytics Account” that is made using the Gmail ID. And then click on “Create Project”.

Step 7: Your project is ready now. So you will get the following window. Click on “Continue”.

Step 8: Now click on “Project Setting”.

Step 9: Under Project Setting, Click on “Service Accounts”. Copy the secret key from below. The code is required in the Arduino Code.

Step 10: Click on “Create Database”.

Step 11: Choose “Start in Test Mode” and then click on “Next”.

Step 12: Now click on “Done” & from left side click on “Database”.

Step 13: Select the “Realtime Database” option from the Database List.

Step 14: Now your final project is ready. You can modify the “ON/OFF” line from the list.

Step 15: Copy the “secret key” & “Project name“. This are required in the Arduino code. The Project name looks something like this “https://your_project_name.firebaseio.com/”




LED Control using Google Firebase & ESP8266

Now we are done with the hardware setup & Google Firebase Setup both. You can upload the code to the NodeMCU ESP8266 Board. The complete code is given below.

NodeMCU ESP8266 LED Google Firebase

You can write “ON” to turn on the LED using Firebase. Similarly, if you want to turn ofF the LED you need to write “OFF”.

LED ON OFF ESP8266 Google Firebase


Source Code: IoT Based LED Control using Google Firebase & ESP8266

Here is a Source Code/Program for Control of LED using Google Firebase Control & ESP8266. Copy the code and upload it to the NodeMCU ESP8266 Board.

1
2
3
4
#define FIREBASE_HOST "my1stproject-34e8e.firebaseio.com"    
#define FIREBASE_AUTH "KeiqJV41s********************LdNXL"
#define WIFI_SSID "Alexahome"                                          
#define WIFI_PASSWORD "12345678"  

Before uploading the code, make changes to the following parameters like FIREBASE_HOST, FIREBASE_AUTH, WIFI_SSID & WIFI_PASSWORD.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <ESP8266WiFi.h>                                              
#include <FirebaseArduino.h>                                        
 
#define FIREBASE_HOST "my1stproject-34e8e.firebaseio.com"              // the project name address from firebase id
#define FIREBASE_AUTH "KeiqJV41s********************LdNXL"       // the secret key generated from firebase
#define WIFI_SSID "Alexahome"                                          
#define WIFI_PASSWORD "12345678"                                  
 
String fireStatus = "";                                                     // led status received from firebase
int led = 5;  
                                                              
void setup()
{
  Serial.begin(9600);
  delay(1000);    
  pinMode(led, OUTPUT);                
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);                              
  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);
  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, 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, LOW);                                                         // make external led OFF
  }
  else
  {
    Serial.println("Command Error! Please send ON/OFF");
  }
}



Code Explanation

First, we include the libraries for using ESP8266 and firebase.

1
2
#include <ESP8266WiFi.h>                                              
#include <FirebaseArduino.h>

Then we define the two parameters FIREBASE_HOST & FIREBASE_AUTH. We get these parameters from Google Firebase Setup. These two parameters are very important to communicate with firebase. This enables the data exchange between the ESP8266 and firebase.

1
2
#define FIREBASE_HOST "my1stproject-34e8e.firebaseio.com"  
#define FIREBASE_AUTH "KeiqJV41s********************LdNXL"    

Then we define the WiFi SSID & Password. Replace SSID and password with your network SSID and password. The Nodemcu will connect to the network & communicates with Google Firewall.

1
2
#define WIFI_SSID "Alexahome"                                          
#define WIFI_PASSWORD "12345678"

This code will make Nodemcu ESP8266 connect to the network. Once connected it will display the WiFi SSID name.

1
2
3
4
5
6
7
8
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);                              
  Serial.print("Connecting to ");
  Serial.print(WIFI_SSID);
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(500);
  }

This statement lets the Nodemcu connect with the firebase server. If the host address and authorization key are correct then it will connect successfully

1
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);  

This is the class provided by the firebase library to send a string to the firebase server. The status of LED is changed using this.

1
Firebase.setString("LED_STATUS", "OFF");

Under the loop function, after sending one status string to the firebase path, write this statement to get the status of LED from the same path and save it to a variable.

1
2
3
4
5
6
7
8
9
10
11
12
fireStatus = Firebase.getString("LED_STATUS");                  =
  if (fireStatus == "ON") {                                                      
    Serial.println("Led Turned ON");                        
    digitalWrite(led, HIGH);                                                    
  }
  else if (fireStatus == "OFF") {                                            
    Serial.println("Led Turned OFF");
    digitalWrite(led, LOW);                                                    
  }
  else {
    Serial.println("Command Error! Please send ON/OFF");
  }

The LED will turn ON/OFF depending upon the String received as “ON” or “OFF respectively. If any other character is sent, the serial monitor will display “Command Error! Please send ON/OFF”

This was all about the controlling of LED using Google Firebase. Now there is another side of the tutorial, what if you want to send the sensor data to google Firebase? So for that, you can follow this post.

Send Real-Time Sensor Data to Google Firebase with ESP8266


Video Tutorial & Complete Guide

Google Firebase & ESP8266 Complete Guide - Sending/Receiving Data from ESP8266 & Firebase
Watch this video on YouTube.

Home Automation using Google Firebase & NodeMCU ESP8266

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleFire Alarm Circuit Using IC 555 Timer & Thermistor
Next Article Send Real-Time Sensor Data to Google Firebase with ESP8266

Related Posts

IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20261K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

Updated:February 1, 20261K
View 4 Comments

4 Comments

  1. Reebin Jose on February 28, 2021 9:48 PM

    sir i cant make the connection between firebase(server) and nodemcu 🙁 please help

    Reply
  2. cinar2000 on June 2, 2021 1:48 PM

    Not appear Database secret key.

    Database secrets are currently deprecated and use a legacy Firebase token generator. Update your source code with the Firebase Admin SDK.

    how can i add secret key in arduino codes?

    Reply
  3. Masidur Rahaman on March 19, 2022 3:47 PM

    How to add Firebase Admin SDK to Arduino Code ? please help !

    Reply
  4. Nikhil M Thoppil on May 22, 2023 3:08 AM

    Compilation error: exit status 1
    please help me

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
  • IoT Based Electricity Energy Meter using ESP32 & Blynk
    IoT Based Electricity Energy Meter using ESP32 & Blynk
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.