Send Real-Time Sensor Data to Google Firebase with ESP8266
Send the real-time sensor data to Google Firebase Console using NodeMCU ESP8266 & DHT11 Humidity Temperature Sensor. Data log in firebase with Source Cod
- Suitable forB.Tech/Diploma ESP8266/IoT students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
In this post, we will learn how to send the real-time sensor data to Google Firebase Console using NodeMCU ESP8266 & DHT11 Sensor.
Overview: Send Real-Time Sensor Data to Google Firebase with ESP8266
Earlier when there was no development of IoT, the
remote monitoring
of
sensor data
was limited. The device used to be placed near the observer to check the data on
display devices
. Since the advancement of IoT, the limitations have been removed and
data monitoring remotely
has been possible. Not only the monitoring of data remotely but also monitoring the data on a
real-time
basis has become possible.
So we are basically focusing on
IoT Based Remote Data Monitoring System
. In some of our earlier projects, we used the IoT platforms like
Thingspeak
Adafruit.io
&
Webpage
to monitor data remotely using
Nodemcu ESP8266
. But in this project, we will Send the Real-Time Sensor Data to Google Firebase with ESP8266 & DHT11 Humidity Temperature Sensor. The data will be read using DHT11 Sensor and sent to
Google Firebase Console
Database.
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
DHT11 Sensor
Amazon
AliExpress
Micro-USB Cable
Amazon
AliExpress
Jumper Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
Setting Up Hardware & NodeMCU DHT11 Circuit
Here is a circuit diagram for
connecting DHT11 Humidity Temperature Sensor with NodeMCU ESP8266 Board
. Connect the positive terminal of
DHT11
to 3.3V & negative terminal to GND. Connect the digital output pin to D2/GPIO4 of NodeMCU.
If you want to learn more about the DHT11 Humidity Temperature Sensor, you can follow this post:
Interfacing DHT11 Humidity Temperature Sensor with Arduino
You can assemble the circuit on breadboard as I used a breadboard for Assembly too. You can see the image below.
Now let us learn how we can
send Real-Time Sensor Data to Google Firebase with Nodemcu ESP8266
Installing Libraries
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
3. DHT11 Library
To read the temperature and humidity we need any temperature humidity sensor. For that DHT11 is the best and cheap sensor. We need to install DHT11 Library for that. Download the library from below and add to the Arduino IDE.
Download DHT11 Library
Setting up Google Firebase Console Database
Now the main thing that we need to do is Setting up Google Firebase Console Database. Once the setup is done, we can then Send Real-Time Sensor Data to Google Firebase with Nodemcu ESP8266.
But I won’t be explaining here how you can set up the Google Firebase Console Database because I have already explained the entire process in the previous tutorial. You can check the following tutorial to learn how to do the setup.
IoT Based LED Control using Google Firebase & ESP8266
Once the setup is done you will get the following window.
Source Code/Program: Send Sensor Data to Google Firebase with ESP8266
Now the hardware and Google Firebase Setup is done. So lets move to the programming part. So, here is a
Source Code/Program
to Send Real-Time Sensor Data to
Google Firebase
with
ESP8266
. Copy the code and upload it to the NodeMCU ESP8266 Board.
#define FIREBASE_HOST "mydhtsensor-26aa7.firebaseio.com"
#define FIREBASE_AUTH "90*******************************iiL"
#define WIFI_SSID "Alexahome"
#define WIFI_PASSWORD "12345678"
Before uploading the code, make sure to do the changes to
FIREBASE_AUTH
&
FIREBASE_HOST
. You can get these parameters from Google Firebase Console. Check the previous tutorial to learn more.
Also change the
WIFI_SSID
&
WIFI_PASSWORD
from the given code and replace it with your wifi SSID & Password.
Check the complete code here.
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <DHT.h>
#define FIREBASE_HOST "******************.firebaseio.com"
#define FIREBASE_AUTH "***********************************"
#define WIFI_SSID "***********"
#define WIFI_PASSWORD "**************"
#define DHTPIN D2 // Digital pin connected to DHT11
#define DHTTYPE DHT11 // Initialize dht type as DHT 11
DHT
dht
(
DHTPIN
DHTTYPE
)
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
dht
begin
(
)
;
//reads dht sensor data
WiFi
begin
(
WIFI_SSID
WIFI_PASSWORD
)
;
Serial
(
"Connecting to "
)
;
Serial
(
WIFI_SSID
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
Serial
(
"."
)
;
delay
(
)
;
}
Serial
println
(
)
;
Serial
(
"Connected"
)
;
Serial
(
"IP Address: "
)
;
Serial
println
(
WiFi
localIP
(
)
)
;
//prints local IP address
Firebase
begin
(
FIREBASE_HOST
FIREBASE_AUTH
)
;
// connect to the firebase
}
void
loop
(
)
{
float
h
=
dht
readHumidity
(
)
;
// Read Humidity
float
t
=
dht
readTemperature
(
)
;
// Read temperature
if
(
isnan
(
h
)
||
isnan
(
t
)
)
// Checking sensor working
{
Serial
println
(
F
(
"Failed to read from DHT sensor!"
)
)
;
return
;
}
Serial
(
"Humidity: "
)
;
Serial
(
h
)
;
String
fireHumid
=
String
(
h
)
+
String
(
"%"
)
;
//Humidity integer to string conversion
Serial
(
"% Temperature: "
)
;
Serial
(
t
)
;
Serial
println
(
"°C "
)
;
String
fireTemp
=
String
(
t
)
+
String
(
"°C"
)
;
//Temperature integer to string conversion
delay
(
5000
)
;
Firebase
pushString
(
"/DHT11/Humidity"
fireHumid
)
;
//setup path to send Humidity readings
Firebase
pushString
(
"/DHT11/Temperature"
fireTemp
)
;
//setup path to send Temperature readings
if
(
Firebase
failed
(
)
)
{
Serial
(
"pushing /logs failed:"
)
;
Serial
println
(
Firebase
error
(
)
)
;
return
;
}
}
Code Explanation
First, we include the library for Firebase & DHT11 Sensor
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <DHT.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 the firebase.
#define FIREBASE_HOST "*********************.firebaseio.com"
#define FIREBASE_AUTH "********************************"
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"
Then we define the DH
Overview: Send Real-Time Sensor Data to Google Firebase with ESP8266
Earlier when there was no development of IoT, the
remote monitoring
of
sensor data
was limited. The device used to be placed near the observer to check the data on
display devices
. Since the advancement of IoT, the limitations have been removed and
data monitoring remotely
has been possible. Not only the monitoring of data remotely but also monitoring the data on a
real-time
basis has become possible.
So we are basically focusing on
IoT Based Remote Data Monitoring System
. In some of our earlier projects, we used the IoT platforms like
Thingspeak
Adafruit.io
&
Webpage
to monitor data remotely using
Nodemcu ESP8266
. But in this project, we will Send the Real-Time Sensor Data to Google Firebase with ESP8266 & DHT11 Humidity Temperature Sensor. The data will be read using DHT11 Sensor and sent to
Google Firebase Console
Database.
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
DHT11 Sensor
Amazon
AliExpress
Micro-USB Cable
Amazon
AliExpress
Jumper Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
Setting Up Hardware & NodeMCU DHT11 Circuit
Here is a circuit diagram for
connecting DHT11 Humidity Temperature Sensor with NodeMCU ESP8266 Board
. Connect the positive terminal of
DHT11
to 3.3V & negative terminal to GND. Connect the digital output pin to D2/GPIO4 of NodeMCU.
If you want to learn more about the DHT11 Humidity Temperature Sensor, you can follow this post:
Interfacing DHT11 Humidity Temperature Sensor with Arduino
You can assemble the circuit on breadboard as I used a breadboard for Assembly too. You can see the image below.
Now let us learn how we can
send Real-Time Sensor Data to Google Firebase with Nodemcu ESP8266
Installing Libraries
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
3. DHT11 Library
To read the temperature and humidity we need any temperature humidity sensor. For that DHT11 is the best and cheap sensor. We need to install DHT11 Library for that. Download the library from below and add to the Arduino IDE.
Download DHT11 Library
Setting up Google Firebase Console Database
Now the main thing that we need to do is Setting up Google Firebase Console Database. Once the setup is done, we can then Send Real-Time Sensor Data to Google Firebase with Nodemcu ESP8266.
But I won’t be explaining here how you can set up the Google Firebase Console Database because I have already explained the entire process in the previous tutorial. You can check the following tutorial to learn how to do the setup.
IoT Based LED Control using Google Firebase & ESP8266
Once the setup is done you will get the following window.
Source Code/Program: Send Sensor Data to Google Firebase with ESP8266
Now the hardware and Google Firebase Setup is done. So lets move to the programming part. So, here is a
Source Code/Program
to Send Real-Time Sensor Data to
Google Firebase
with
ESP8266
. Copy the code and upload it to the NodeMCU ESP8266 Board.
#define FIREBASE_HOST "mydhtsensor-26aa7.firebaseio.com"
#define FIREBASE_AUTH "90*******************************iiL"
#define WIFI_SSID "Alexahome"
#define WIFI_PASSWORD "12345678"
Before uploading the code, make sure to do the changes to
FIREBASE_AUTH
&
FIREBASE_HOST
. You can get these parameters from Google Firebase Console. Check the previous tutorial to learn more.
Also change the
WIFI_SSID
&
WIFI_PASSWORD
from the given code and replace it with your wifi SSID & Password.
Check the complete code here.
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <DHT.h>
#define FIREBASE_HOST "******************.firebaseio.com"
#define FIREBASE_AUTH "***********************************"
#define WIFI_SSID "***********"
#define WIFI_PASSWORD "**************"
#define DHTPIN D2 // Digital pin connected to DHT11
#define DHTTYPE DHT11 // Initialize dht type as DHT 11
DHT
dht
(
DHTPIN
DHTTYPE
)
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
dht
begin
(
)
;
//reads dht sensor data
WiFi
begin
(
WIFI_SSID
WIFI_PASSWORD
)
;
Serial
(
"Connecting to "
)
;
Serial
(
WIFI_SSID
)
;
while
(
WiFi
status
(
)
!=
WL_CONNECTED
)
{
Serial
(
"."
)
;
delay
(
)
;
}
Serial
println
(
)
;
Serial
(
"Connected"
)
;
Serial
(
"IP Address: "
)
;
Serial
println
(
WiFi
localIP
(
)
)
;
//prints local IP address
Firebase
begin
(
FIREBASE_HOST
FIREBASE_AUTH
)
;
// connect to the firebase
}
void
loop
(
)
{
float
h
=
dht
readHumidity
(
)
;
// Read Humidity
float
t
=
dht
readTemperature
(
)
;
// Read temperature
if
(
isnan
(
h
)
||
isnan
(
t
)
)
// Checking sensor working
{
Serial
println
(
F
(
"Failed to read from DHT sensor!"
)
)
;
return
;
}
Serial
(
"Humidity: "
)
;
Serial
(
h
)
;
String
fireHumid
=
String
(
h
)
+
String
(
"%"
)
;
//Humidity integer to string conversion
Serial
(
"% Temperature: "
)
;
Serial
(
t
)
;
Serial
println
(
"°C "
)
;
String
fireTemp
=
String
(
t
)
+
String
(
"°C"
)
;
//Temperature integer to string conversion
delay
(
5000
)
;
Firebase
pushString
(
"/DHT11/Humidity"
fireHumid
)
;
//setup path to send Humidity readings
Firebase
pushString
(
"/DHT11/Temperature"
fireTemp
)
;
//setup path to send Temperature readings
if
(
Firebase
failed
(
)
)
{
Serial
(
"pushing /logs failed:"
)
;
Serial
println
(
Firebase
error
(
)
)
;
return
;
}
}
Code Explanation
First, we include the library for Firebase & DHT11 Sensor
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <DHT.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 the firebase.
#define FIREBASE_HOST "*********************.firebaseio.com"
#define FIREBASE_AUTH "********************************"
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"
Then we define the DH
Technologies used
Hardware components
- ESP8266
- Arduino
- DHT11
Software & tools
- Arduino IDE
- ThingSpeak
- 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.