IoT Based Temperature and Humidity Monitoring using Google Firebase and ESP8266

IoT based Temperature and Humidity Monitoring using Google Firebase and ESP8266

There are number of IoT platforms which can be used for sending or receiving data over the internet. Earlier, we have done monitoring of Temperature and Humidity data using ThingSpeak and ESP8266. Here, we are sending Temperature and Humidity data to Google’s Firebase cloud using NodeMCU ESP8266. So, for that we just need to setup a database on Firebase and interface it with ESP8266 NodeMCU.

Not only google firebase but there are number of IoT platforms like Adafruit IO, IFTTT, ThingSpeak which are available for showcasing your IOT project data over the internet. But Google’s Firebase is a bit fast than other IoT platforms. It works without any delay with real-time IoT projects.

 

Components Required

  • NodeMCU ESP8266 Module
  • DHT11 Temperature and Humidity sensor

 

Circuit Diagram

Circuit Diagram for IoT based Temperature and Humidity Monitoring using Google Firebase and ESP8266

 

Setting up Firebase Console for ESP8266

If you are using firebase for the first time then you have to create account for firebase or can directly signup using Google Account:

  1. Open your browser and go for https://firebase.google.com
  2. At the right top corner click on “Go to Console”.

 Google Firebase for IoT Based LED Control using ESP32 NodMCU

 

  1. Click on “Add Project”.

Add Project to Google Firebase for IoT Based LED Control using ESP32 NodMCU

 

  1. Input your project name as you want and click on create project.

Create Project on Google Firebase for Data Monitoring

 

5. Now your project is created and click on “Continue

Temperature and Humidity Monitoring using Google Firebase and ESP8266

 

6. Now you will need host name and authorization key/secret key for this project while programming your ESP32; so now we will see how these parameters can be taken from this.

 

7. Go to setting icon and click on “Project Setting”.

Setup Project on Google Firebase for Data Monitoring

 

8. Now click on Service accounts and then Database secrets.

 Set Account Services on Google Firebase for Data Monitoring

 

9. Now on left control bar click on ‘Database’. And then click on ‘Create database’.

Create Database on Google Firebase for Data Monitoring

 

10. Now choose “Start in test mode” and click on Enable.

Testing Temperature and Humidity Monitoring using Google Firebase and ESP8266

 

11. Now your database is created and you will have to come here again to control your LED, for now just copy the given URL without slash and http in notepad this is your firebase host which you will be required later.

Database Created on Google Firebase for Data Monitoring

 

Just copy “dht11-10a43.firebaseio.com” without any slash and https. This will be your “FIREBASE_HOST”.

 

Programming ESP8266 for Google Firebase

Complete code for this project is given at the end of the tutorial.

First include all required libraries for this project

#include <ESP8266WiFi.h
#include <FirebaseArduino.h
#include <DHT.h>

 

The below two parameters will enable communication between Firebase and NodeCU.

#define FIREBASE_HOST "your-project.firebaseio.com"  
 #define FIREBASE_AUTH "FIREBASE_AUTH"

 

Define DHT pin connected to NodeMCU.

#define DHTPIN D2

 

For taking humidity and temperature readings from DHT sensor, we are using the below code.

dht.begin(); 
float h = dht.readHumidity();
float t = dht.readTemperature(); 

 

Using this case checks whether DHT sensor is working properly or not.

if (isnan(h) || isnan(t)) {                                             
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

 

And, for printing the coming temperature and humidity data from the sensor on serial monitor.

Serial.print("Humidity: ");  Serial.print(h);
  String fireHumid = String(h) + String("%");                                     
  Serial.print("%  Temperature: ");  Serial.print(t);  Serial.println("°C ");
  String fireTemp = String(t) + String("°C");   
 delay(4000);

 

Now, we are sending the DHT sensor data to Firebase using the path provided by you.

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

 

For confirming that the data is uploading to Firebase or not, we have added the below code.

    if (Firebase.failed()) {
      Serial.print("pushing /logs failed:");
      Serial.println(Firebase.error());  
      return;

 

After uploading your code to Arduino IDE, navigate to your Google’s Firebase account you will see the output will be shown as below.

 Getting Temperature and Humidity Monitoring using Google Firebase and ESP8266

 

Hence, we have successfully monitored the temperature and humidity data using Google’s firebase. You can also do this monitoring using ThingSpeak.

Code

#include <ESP8266WiFi.h>                 // esp8266 library

#include <FirebaseArduino.h>            // firebase library

#include <DHT.h>                            // dht11 temperature and humidity sensor library

 

#define FIREBASE_HOST "your_project_name.firebaseio.com"      // Project name address from firebase id

#define FIREBASE_AUTH "FIREBASE_AUTH"            //  Secret key generated from firebase

 

#define WIFI_SSID "WiFi Name"                                     // Enter your wifi name

#define WIFI_PASSWORD "WiFi Password"                  //Enter your 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);

  delay(500);               

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

  Serial.print("IP Address is : ");

  Serial.println(WiFi.localIP());                               // Will print local IP address

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);             // connect to firebase

  dht.begin();                                        //Start reading dht sensor

}

 

void loop() {

  float h = dht.readHumidity();                                 // Reading Humidity

  float t = dht.readTemperature();                           // Read temperature as Celsius

   

  if (isnan(h) || isnan(t)) {                                                // Check if any reads failed.

    Serial.println(F("Failed to read from DHT sensor!"));

    return;

  }

 

  Serial.print("Humidity: ");  Serial.print(h);

  String fireHumid = String(h) + String("%");                                         //convert integer humidity to string humidity

  Serial.print("%  Temperature: ");  Serial.print(t);  Serial.println("°C ");

  String fireTemp = String(t) + String("°C");                                                     //convert integer temperature to string temperature

  delay(4000);

 

  Firebase.pushString("/DHT11/Humidity", fireHumid);                                  //setup path and send readings

  Firebase.pushString("/DHT11/Temperature", fireTemp);                                //setup path and send readings

    if (Firebase.failed()) {

      Serial.print("pushing /logs failed:");

      Serial.println(Firebase.error()); 

      return;

  }

}

Video

18 Comments

I wanted to put you this tiny word to finally thank you very much yet again over the pleasant techniques you have provided at this time. It was quite seriously open-handed of people like you in giving publicly precisely what numerous people would've made available as an electronic book to earn some bucks on their own, principally given that you could have done it if you ever desired. These strategies additionally worked like the good way to be certain that many people have the identical desire the same as my personal own to figure out a good deal more regarding this problem. I am certain there are millions of more pleasant times in the future for individuals who look over your blog.

I as well as my pals came looking through the excellent tips and tricks found on your website while all of the sudden I had a horrible feeling I never thanked the site owner for those secrets. Most of the boys are actually consequently warmed to learn them and have very much been loving these things. Appreciation for simply being indeed helpful and then for opting for these kinds of fabulous resources most people are really needing to discover. Our honest regret for not saying thanks to you earlier.

I actually wanted to write a small comment in order to say thanks to you for all of the precious hints you are writing at this website. My prolonged internet research has at the end been honored with incredibly good information to write about with my companions. I 'd believe that most of us visitors are really blessed to exist in a fantastic site with very many outstanding individuals with interesting opinions. I feel very much happy to have used your entire webpage and look forward to plenty of more entertaining moments reading here. Thanks a lot once again for a lot of things.

Needed to send you that very little observation just to thank you so much the moment again with the pleasing thoughts you have documented in this case. It's tremendously generous of you giving publicly what many people could have distributed as an e-book to earn some dough for themselves, specifically seeing that you could have tried it if you desired. The good ideas likewise acted to be the good way to be aware that other people online have the same dreams really like my personal own to understand much more on the topic of this problem. I know there are many more fun instances in the future for individuals who find out your blog.

I would like to express some appreciation to this writer for rescuing me from this type of predicament. Right after looking out throughout the world-wide-web and seeing ideas which are not pleasant, I figured my entire life was done. Being alive without the presence of approaches to the issues you've fixed as a result of your entire blog post is a critical case, and ones that could have badly affected my career if I hadn't come across your web site. That mastery and kindness in controlling all the stuff was tremendous. I don't know what I would've done if I hadn't encountered such a solution like this. I can at this point look forward to my future. Thanks for your time so much for this professional and results-oriented help. I won't hesitate to suggest the sites to any person who would need care on this situation.

I simply wanted to develop a small comment to appreciate you for all of the marvelous steps you are sharing at this site. My particularly long internet research has finally been honored with useful know-how to talk about with my pals. I would point out that most of us readers actually are definitely blessed to dwell in a perfect website with so many perfect professionals with interesting ideas. I feel truly privileged to have seen the website page and look forward to plenty of more enjoyable moments reading here. Thank you again for everything.

I have to express appreciation to you just for bailing me out of such a problem. As a result of scouting throughout the search engines and seeing concepts that were not beneficial, I believed my life was gone. Being alive minus the strategies to the problems you have resolved by means of your post is a serious case, as well as those that would have adversely damaged my career if I had not come across your website. Your personal know-how and kindness in dealing with all things was useful. I don't know what I would have done if I hadn't come upon such a solution like this. It's possible to at this point look ahead to my future. Thanks for your time so much for the expert and sensible help. I will not hesitate to recommend your blog post to anybody who should get care about this topic.

I not to mention my friends happened to be digesting the good tips and hints located on your web site and then suddenly developed a horrible feeling I never thanked the web blog owner for those strategies. My boys had been certainly passionate to learn them and have now in truth been enjoying these things. We appreciate you being indeed helpful as well as for making a choice on this kind of exceptional resources millions of individuals are really desirous to discover. Our own honest apologies for not expressing gratitude to earlier.

I have to show thanks to you just for bailing me out of this type of circumstance. Right after looking out through the the web and seeing ideas that were not productive, I believed my life was well over. Living minus the strategies to the problems you've resolved by means of your blog post is a critical case, as well as the kind which may have negatively damaged my entire career if I hadn't noticed your site. Your own personal knowledge and kindness in dealing with all the things was helpful. I am not sure what I would've done if I had not discovered such a stuff like this. I can also now look ahead to my future. Thanks for your time so much for this impressive and amazing guide. I won't think twice to recommend the sites to anyone who will need support about this issue.

I am only commenting to let you know what a fantastic encounter my child developed visiting your webblog. She came to understand a good number of issues, including what it's like to possess an incredible giving character to have the others with ease know just exactly some problematic things. You actually exceeded visitors' expected results. Thank you for presenting these helpful, healthy, informative as well as cool tips on the topic to Ethel.

I just wanted to write down a small remark so as to appreciate you for all the fantastic instructions you are sharing here. My incredibly long internet search has at the end of the day been rewarded with pleasant details to share with my company. I 'd tell you that we readers actually are truly blessed to be in a good community with so many perfect professionals with good advice. I feel very much fortunate to have seen your entire website and look forward to plenty of more excellent moments reading here. Thank you once again for all the details.

I and also my pals appeared to be going through the great items located on your web site while at once I had an awful suspicion I never thanked the web site owner for those secrets. Those boys came as a consequence thrilled to read all of them and have in effect really been using them. Thanks for turning out to be really accommodating and then for getting varieties of helpful information most people are really desirous to know about. Our honest apologies for not expressing gratitude to earlier.

My wife and i got quite thrilled Raymond could do his research from your ideas he had from your site. It's not at all simplistic to simply continually be releasing procedures that many others could have been making money from. Therefore we fully grasp we've got the website owner to be grateful to for that. These explanations you've made, the simple website navigation, the friendships you will assist to engender - it is mostly astonishing, and it is letting our son in addition to our family feel that this article is brilliant, which is really vital. Thanks for the whole lot!

I precisely wished to say thanks all over again. I am not sure the things I might have undertaken without the entire tactics shared by you on that situation. This was a depressing problem for me personally, nevertheless being able to view your professional fashion you handled that took me to weep for delight. Now i am grateful for this advice and then expect you really know what an amazing job you are always undertaking instructing most people through your website. Most probably you have never encountered any of us.

Thanks a lot for giving everyone such a superb chance to read critical reviews from this website. It really is so cool and jam-packed with a good time for me personally and my office mates to visit your web site at the least three times in a week to study the fresh items you will have. And of course, we're usually fulfilled with the superb pointers you serve. Selected 1 facts in this posting are absolutely the finest we have had.

I simply needed to say thanks once more. I am not sure the things that I would have gone through in the absence of the actual smart ideas shown by you regarding such a area of interest. It has been a very scary setting for me personally, nevertheless taking a look at a new well-written way you solved that forced me to cry for delight. I am just happier for this guidance and in addition sincerely hope you know what an amazing job that you are undertaking educating some other people by way of your site. More than likely you haven't met any of us.

I am only writing to let you understand what a remarkable discovery my wife's princess gained browsing your blog. She came to find a good number of pieces, with the inclusion of how it is like to have a great teaching spirit to make a number of people without difficulty learn about chosen complex topics. You really exceeded our own expected results. Thank you for imparting such invaluable, trusted, informative not to mention unique thoughts on this topic to Lizeth.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.