IoT Based LED Control using Google Firebase & ESP8266
Mini IoT Based Projects deals with LED Control using Google Firebase Console & NodeMCU ESP8266 wifi Module. Learn Firebase Google’s database platform Code
- Suitable forB.Tech/Diploma ESP8266/IoT students
- Build time1-2 weeks
- LevelIntermediate
- Available atAjvika Labs, Kakinada
About this project
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
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 Name
Quantity
Purchase Links
NodeMCU ESP8266 Board
Amazon
AliExpress
LED 5mm Any Color
Amazon
AliExpress
Resistor 220-ohm
Amazon
AliExpress
Power Supply 5V
Amazon
AliExpress
Connecting Jumper Wires
Amazon
AliExpress
Breadboard
Amazon
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.
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.
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”.
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.
#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
#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
=
;
void
setup
(
)
{
Serial
begin
(
9600
)
;
delay
(
1000
)
;
pinMode
(
led
OUTPUT
)
;
WiFi
begin
(
WIFI_SSID
WIFI_PASSWORD
)
;
Serial
(
"Connecting to "
)
;
Serial
(
WIFI_SSID
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
Serial
(
"."
)
;
delay
(
)
;
}
Serial
println
(
)
;
Serial
(
"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.
#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.
#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.
#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.
WiFi
begin
(
WIFI_SSID
WIFI_PASSWORD
)
;
Serial
(
"Connecting to "
)
;
Serial
(
WIFI_SSID
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
Serial
(
"."
)
;
delay
(
)
;
}
This statement lets the Nodemcu connect with the firebase server. If the host address and authorization key are correct then it will connect successfully
Firebase
begin
(
FIREBASE_HOST
FIREBASE_AUTH
)
;
This is the class provided by the firebase library to
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
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 Name
Quantity
Purchase Links
NodeMCU ESP8266 Board
Amazon
AliExpress
LED 5mm Any Color
Amazon
AliExpress
Resistor 220-ohm
Amazon
AliExpress
Power Supply 5V
Amazon
AliExpress
Connecting Jumper Wires
Amazon
AliExpress
Breadboard
Amazon
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.
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.
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”.
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.
#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
#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
=
;
void
setup
(
)
{
Serial
begin
(
9600
)
;
delay
(
1000
)
;
pinMode
(
led
OUTPUT
)
;
WiFi
begin
(
WIFI_SSID
WIFI_PASSWORD
)
;
Serial
(
"Connecting to "
)
;
Serial
(
WIFI_SSID
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
Serial
(
"."
)
;
delay
(
)
;
}
Serial
println
(
)
;
Serial
(
"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.
#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.
#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.
#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.
WiFi
begin
(
WIFI_SSID
WIFI_PASSWORD
)
;
Serial
(
"Connecting to "
)
;
Serial
(
WIFI_SSID
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
Serial
(
"."
)
;
delay
(
)
;
}
This statement lets the Nodemcu connect with the firebase server. If the host address and authorization key are correct then it will connect successfully
Firebase
begin
(
FIREBASE_HOST
FIREBASE_AUTH
)
;
This is the class provided by the firebase library to
Technologies used
Hardware components
- ESP8266
- Arduino
Software & tools
- Blynk
- Firebase
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.