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 » Send Real-Time Sensor Data to Google Firebase with ESP8266
ESP8266 Projects IoT Projects

Send Real-Time Sensor Data to Google Firebase with ESP8266

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

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 NameQuantityPurchase Links
1NodeMCU ESP8266 Board1Amazon | AliExpress
2DHT11 Sensor1Amazon | AliExpress
3Micro-USB Cable1Amazon | AliExpress
4Jumper Wires1Amazon | AliExpress
5Breadboard1Amazon | 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

DHT11 NodeMCU ESP8266 Google Firebase

You can assemble the circuit on breadboard as I used a breadboard for Assembly too. You can see the image below.

Send Sensor value Google Firebase Database ESP8266

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.

1
2
3
4
#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.

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#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.print("Connecting to ");
  Serial.print(WIFI_SSID);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
 
  Serial.println();
  Serial.print("Connected");
  Serial.print("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.print("Humidity: ");  
  Serial.print(h);
  String fireHumid = String(h) + String("%");                   //Humidity integer to string conversion
  
  Serial.print("%  Temperature: ");  
  Serial.print(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.print("pushing /logs failed:");
      Serial.println(Firebase.error());
      return;
  }
}



Code Explanation

First, we include the library for Firebase & DHT11 Sensor

1
2
3
#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.

1
2
#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.

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

Then we define the DHT Sensor type & create the DHT Sensor instances.

1
2
3
#define DHTPIN D2                                          
#define DHTTYPE DHT11                              
DHT dht(DHTPIN, DHTTYPE);

These lines are for making the NodeMCU ESP8266 Board connect to the Wifi Network. Once connected, the serial monitor will display the Connection Status and prints the IP Address.

1
2
3
4
5
6
7
8
9
10
11
12
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");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());

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);  

Using this we are retrieving the humidity and temperature value from DHT11 Sensor.

1
2
float h = dht.readHumidity();          
float t = dht.readTemperature();

Then we convert the humidity and temperature Integer value to String.

1
2
3
4
5
6
7
8
Serial.print("Humidity: ");  
  Serial.print(h);
  String fireHumid = String(h) + String("%");                   //Humidity integer to string conversion
  
  Serial.print("%  Temperature: ");  
  Serial.print(t);  
  Serial.println("°C ");
  String fireTemp = String(t) + String("°C");

Now we are sending the data to google firebase using the path provided by the code.

1
2
Firebase.pushString("/DHT11/Humidity", fireHumid);    
Firebase.pushString("/DHT11/Temperature", fireTemp);

These verify whether the data is sent to the Google Firebase or not.

1
2
3
4
5
6
7
if (Firebase.failed())
    {
 
      Serial.print("pushing /logs failed:");
      Serial.println(Firebase.error());
      return;
  }




Send Real-Time Sensor Data to Google Firebase with ESP8266

After uploading the code, the Nodemcu will connect to the Wifi Network. Now you can open the serial monitor, it will show the temperature and humidity reading.

When the temperature and humidity data is displayed on Serial Monitor at the same time, the data is sent to Google Firebase Database. You can just open the google Firebase console window and check the real-time entry of the data.

Now if you want to send the data from Google Firebase to Android App you can follow this tutorial:


Video Tutorial & Complete Guide

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

You can follow the following more tutorials about the Google Firebase:

  1. Send Sensor Data to Android Using Google Firebase & ESP8266

  2. Send Sensor Data to Firebase using GSM & Arduino

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleIoT Based LED Control using Google Firebase & ESP8266
Next Article Send Sensor Data to Android Using Google Firebase & 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. Rafael Moura on July 3, 2020 2:09 AM

    Its possible connect with firebase using lan cable (W5500) ?

    Reply
  2. Daniel Fernandes on September 2, 2021 11:27 PM

    Is it possible in the same code to use, for example, a Display ILI9341 to show the Temperature and Humidity? How to make? Thanks

    Reply
  3. SARATHKUMAR R on May 9, 2022 10:05 AM

    it alwasy shows push/log failed i dont know why this problem i give all info are correct

    Reply
  4. Rushikesh Pandit on July 11, 2022 7:52 PM

    Hello I was trying the same project of blinking led using firebase
    i did the firebase set up properly and copied the codes as it is but still I’m getting errors

    I’m posting the errors as well below, kindly someone help

    thankyou

    error:-
    Arduino: 1.8.19 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”

    C:\Users\ranja\OneDrive\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp: In member function ‘virtual void FirebaseHttpClientEsp8266::begin(const string&)’:
    C:\Users\ranja\OneDrive\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp:47:50: error: no matching function for call to ‘begin(const char*, const char [60])’
    47 | http_.begin(url.c_str(), kFirebaseFingerprint);
    | ^
    In file included from C:\Users\ranja\OneDrive\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp:9:
    C:\Users\ranja\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:166:10: note: candidate: ‘bool HTTPClient::begin(String, uint16_t, String)’ (near match)
    166 | bool begin(String host, uint16_t port, String uri = “/”) attribute ((error(“obsolete API, use ::begin(WiFiClient, host, port, uri)”)));
    | ^~~~~
    C:\Users\ranja\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:166:10: note: conversion of argument 2 would be ill-formed:
    C:\Users\ranja\OneDrive\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp:47:30: error: invalid conversion from ‘const char‘ to ‘uint16_t’ {aka ‘short unsigned int’} [-fpermissive]
    47 | http_.begin(url.c_str(), kFirebaseFingerprint);
    | ^~~~~~~~~~~~~~~~~~~~
    | |
    | const char

    In file included from C:\Users\ranja\OneDrive\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp:9:
    C:\Users\ranja\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:167:10: note: candidate: ‘bool HTTPClient::begin(String, const uint8_t)’ (near match)
    167 | bool begin(String url, const uint8_t httpsFingerprint[20]) attribute ((error(“obsolete API, use ::begin(WiFiClientSecure, …)”)));
    | ^~~~~
    C:\Users\ranja\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:167:10: note: conversion of argument 2 would be ill-formed:
    C:\Users\ranja\OneDrive\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp:47:30: error: invalid conversion from ‘const char
    ‘ to ‘const uint8_t‘ {aka ‘const unsigned char‘} [-fpermissive]
    47 | http_.begin(url.c_str(), kFirebaseFingerprint);
    | ^~~~~~~~~~~~~~~~~~~~
    | |
    | const char*
    C:\Users\ranja\OneDrive\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp: In member function ‘virtual void FirebaseHttpClientEsp8266::begin(const string&, const string&)’:
    C:\Users\ranja\OneDrive\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp:51:60: error: invalid conversion from ‘const char‘ to ‘const uint8_t‘ {aka ‘const unsigned char‘} [-fpermissive]
    51 | http_.begin(host.c_str(), kFirebasePort, path.c_str(), kFirebaseFingerprint);
    | ^~~~~~~~~~~~~~~~~~~~
    | |
    | const char

    In file included from C:\Users\ranja\OneDrive\Documents\Arduino\libraries\firebase-arduino-master\src\FirebaseHttpClient_Esp8266.cpp:9:
    C:\Users\ranja\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266HTTPClient\src/ESP8266HTTPClient.h:168:70: note: initializing argument 4 of ‘bool HTTPClient::begin(String, uint16_t, String, const uint8_t*)’
    168 | bool begin(String host, uint16_t port, String uri, const uint8_t httpsFingerprint[20]) attribute ((error(“obsolete API, use ::begin(WiFiClientSecure, …)”)));
    | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
    exit status 1
    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    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
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • IoT Based Drinking Water Quality Monitoring with ESP32
    IoT Based Drinking Water Quality Monitoring with ESP32
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • DIY IoT Water pH Meter using pH Sensor & ESP32
    DIY IoT Water pH Meter using pH Sensor & ESP32
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
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.