Securing The Future Bit By Bit

Thursday, July 4, 2019

How to make a weather monitoring system using Google Firebase.

In this blog, I will explain you how to monitor weather and send the data to google firebase.

Components Required

1. Nodemcu(ESP8266)
2. DHT11/22 Sensor
3. Breadboard
4. Google Firebase Account
5. Jumper Wires

Circuit Diagram:

Connection 
DHT11              Nodemcu
 Gnd---------------Gnd
  Vcc---------------Vcc
  Data--------------D4

What is DHT11 Sensor?

DHT11 Temperature & Humidity Sensor features a temperature & humidity sensor complex with a calibrated digital signal output. By using the exclusive digital-signal-acquisition technique and temperature & humidity sensing technology, it ensures high reliability and excellent long-term stability. This sensor includes a resistive-type humidity measurement component and an NTC temperature measurement component, and connects to a highperformance 8-bit microcontroller, offering excellent quality, fast response, anti-interference ability and cost-effectiveness.


Google Firebase Setup
Firebase provides a realtime database and backend as a service. The service provides application developers an API that allows application data to be synchronized across clients and stored on Firebase's cloud. The company provides client libraries that enable integration with AndroidiOSJavaScriptJavaObjective-CSwift and Node.js applications. The database is also accessible through a REST API and bindings for several JavaScript frameworks such as AngularJSReactEmber.js and Backbone.js. The REST API uses the Server-Sent Events protocol, which is an API for creating HTTP connections for receiving push notifications from a server. Developers using the realtime database can secure their data by using the company's server-side-enforced security rules.

Step1 Make a account in google firebase and login .
Step2 Add a project with name.
Step3 Go to project overview then users and premissions.
Step4 Go to data base secret and then copy api key.
Step5 Go to database and change cloud firestore to realtime database.


Arduino Code
#include <ESP8266WiFi.h> // esp8266 library
#include <FirebaseArduino.h> // firebase library
#include <DHT.h> // dht11 temperature and humidity sensor library
#define FIREBASE_HOST "temp-and-humidity-monitoring.firebaseio.com" // the project name address from firebase id
#define FIREBASE_AUTH "ufKOoaJrqDbeK5rajoiheO7YcpKwFZSUrpm5jFRq" // the secret key generated from firebase
#define WIFI_SSID "Tenda_7F50C8" // input your home or public wifi name
#define WIFI_PASSWORD "Vansh024@" //password of wifi ssid
#define DHTPIN D4 // what digital pin we're connected to
#define DHTTYPE DHT11 // select dht type as DHT 11 or DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
delay(1000);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); //try to connect with wifi
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()); //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 temperature or humidity takes about 250 milliseconds!
float t = dht.readTemperature(); // Read temperature as Celsius (the default)
if (isnan(h) || isnan(t)) { // Check if any reads failed and exit early (to try again).
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
} Github Link:https://github.com/AmanJaiswal210 media Gallary


 



Share:

1 comment:

  1. Such a great blog, Thank you for sharing with us. Wireless sensor includes a resistive-type humidity measurement component and an temperature measurement component. It connects to a high-performance 8-bit microcontroller that changes the electronic signals. Visit Ubibot and buy the best grade remote temperature monitoring sensor for weather monitoring.

    ReplyDelete

ElectrocoreDIY.com

Search This Blog

Blog Archive

Powered by Blogger.

Privacy Policy