Ritesh Vernekar
Published

Weather Monitoring System

Weather Monitoring and Analyzing using DHT11 sensor and ThingSpeak along with Twitter.

IntermediateFull instructions provided1 hour1,484
Weather Monitoring System

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×2
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Supportive drivers

Driver for DHT11 sensor

Supportive drivers

Driver for ESP8266WiFi

Supportive drivers

Drivers if code shows missing driver error

Supportive drivers

Drivers if code shows missing driver error

Schematics

Circuit Connections

Connect as per Circuit Diagram

Code

finalcode.ino

Arduino
This is the final code for the project
#include <DHT.h>  // Including library for dht
#include <ESP8266WiFi.h>

String apiKey = "ABCD12345EFGFHIJ";     //  Enter your Write API key from ThingSpeak
 
const char *ssid =  "My Wifi";     // replace with your wifi ssid and wpa2 key
const char *pass =  "MyPassword";
const char* server = "api.thingspeak.com";
int count = 0; 
#define DHTPIN 0          //pin where the dht11 is connected D3
#define Temp D0           //LED for Temperature
#define Hum D1            //LED for Humidity
DHT dht(DHTPIN, DHT11);
 
WiFiClient client;
 
void setup() 
{
       pinMode(Temp, OUTPUT);
       pinMode(Hum, OUTPUT);
       Serial.begin(115200);
       delay(10);
       dht.begin();
 
       Serial.println("Connecting to ");
       Serial.println(ssid);
 
 
       WiFi.begin(ssid, pass);
 
      while (WiFi.status() != WL_CONNECTED) 
     {
            delay(500);
            Serial.print(".");
     }
      Serial.println("");
      Serial.println("WiFi connected");
 
}
 
void loop() 
{
  
      float h = dht.readHumidity();
      float t = dht.readTemperature();
      
              if (isnan(h) || isnan(t)) 
                 {
                     Serial.println("Failed to read from DHT sensor!");
                      return;
                 }
 
                         if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
                      {  
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(t);
                             postStr +="&field2=";
                             postStr += String(h);
                             postStr += "\r\n\r\n";
 
                             client.print("POST /update HTTP/1.1\n");
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
 
                             Serial.print("\nTemperature: ");
                             Serial.print(t);
                             Serial.print("C\n");
                             Serial.print("Humidity: ");
                             Serial.print(h);
                             Serial.print("%\n");
                             Serial.println("Sending to Thingspeak\n");
                             count = count+1;
                             
                             if (t>=40.00  t<=20.00)    //For Temperature
                             {
                              digitalWrite(Temp, HIGH);
                             }
                             else
                             {
                              digitalWrite(Temp, LOW);
                             }

                             if(h>=80.00)
                             {
                              digitalWrite(Hum, HIGH);    //For Humidity
                             }
                             else
                             {
                              digitalWrite(Hum, LOW);
                             }
                        }
          client.stop();
          Serial.print("Please wait 3 minutes for next reading\n");
  
  delay(180000); // 3mins = 180,000
}

Credits

Ritesh Vernekar

Ritesh Vernekar

1 project • 0 followers
Thanks to Raghuttam Bhavikatti, Sagar Siddappa Mualgund, , and Ashok Donkanavar.

Comments