Adarsh Kumar Mauryamohnish vatsRohit Kumar
Published © MIT

Weather Monitoring And WeatherForeCasting

This Project Aims Weather Monitoring,predicting and Analyzing using DHT11 sensor and ThingSpeak along with Algorithms.

ExpertFull instructions provided5 hours366
Weather Monitoring And WeatherForeCasting

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Grove - Gas Sensor(MQ2)
Seeed Studio Grove - Gas Sensor(MQ2)
×1
Nova PM Sensor SDS011 High Precision Laser pm2.5 Air Quality Detection Sensor
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Male Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1

Software apps and online services

ThingSpeak API
ThingSpeak API
Visual Studio Code Extension for Arduino
Microsoft Visual Studio Code Extension for Arduino
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Systematic Diagram

ThinkSpeak And Diagram

Diagram

Code

Arduino Code

Arduino
This Code is for Arduino
//sender arduino

#include "DHT.h"
#define DHTPIN 8
#include <MQ2.h>
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);

//PM sensor init
#include "SdsDustSensor.h"
int rxPin = 11;
int txPin = 12;
SdsDustSensor sds(rxPin, txPin);
//pm end

//Gas configuration starts
int Analog_Input = A0;
int lpg, co, smoke;
MQ2 mq2(Analog_Input);
float Level;
//Gas configuration ends

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  dht.begin();
  mq2.begin();
  sds.begin();
}

void loop() {

PmResult pm = sds.readPm();
  if (pm.isOk()) {
    // Serial.print("PM2.5 = ");
    // Serial.print(pm.pm25);
    // Serial.print(", PM10 = ");
    // Serial.println(pm.pm10);

    // // if you want to just print the measured values, you can use toString() method as well
    // Serial.println(pm.toString());
  }




  // put your main code here, to run repeatedly:
  float t=dht.readTemperature();
  float h=dht.readHumidity();
  if(isnan(t) || isnan(h)){
    //Serial.println("Data is not available");
    return;
    }

  //gas

  float reading = analogRead(A0);

   Level = ((reading/1023)*100);

    if (isnan(Level))

      {
                return;

      }
  //float* values= mq2.read(true); //false

  //lpg = values[0];
  //lpg = mq2.readLPG();
  //co = values[1];
  //co = mq2.readCO();
  //smoke = values[2];
  //smoke = mq2.readSmoke();

  // lpg = mq2.readLPG();
  // co = mq2.readCO();
  // smoke = mq2.readSmoke();
  //gas end
  Serial.print(t);
  Serial.print(",");
  Serial.print(h);
  Serial.print(",");

  Serial.print(pm.pm25);
  Serial.print(",");
  Serial.print(pm.pm10);
  Serial.print(",");

  Serial.print(Level);
  Serial.print(",");
  
  Serial.println();

  delay(10000);
}

NodeMCU Code

C/C++
This Code for the NodeCMU WiFi Module
//receiver arduino
#include <iostream>
#include<ESP8266WiFi.h>
#include<WiFiClient.h>
#include<ESP8266HTTPClient.h>

String URL ="http://api.thingspeak.com/update?api_key=LG44GXA088QY9060&field2=";

//float t,h,pm25,pm10;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  //wifi
  WiFi.disconnect();
  delay(2000);
  Serial.print("Start connection");
  WiFi.begin("Google","adarsh1992");
  
  while((!(WiFi.status()== WL_CONNECTED))){
      delay(200);
      Serial.print("..");
    }
  Serial.println("Connected");

}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()>0)
  {
    String data=Serial.readStringUntil('\n');
    //Serial.println(data);
    // int comma=data.indexOf(',');
    // if(comma!=-1)
    // {
    //   float t=data.substring(0,comma).toFloat();
    //   float h=data.substring(comma+1).toFloat();
    //   Serial.print(t);
    //   Serial.println(h);
       
      
    // }
    splitstr(data);
    
  }

}


void splitstr(String data){
      String  str = data;
String strs[20];
int StringCount = 0;

  //Serial.println(str);

  // Split the string into substrings
  while (str.length() > 0)
  {
    int index = str.indexOf(',');
    if (index == -1) // No space found
    {
      strs[StringCount++] = str;
      break;
    }
    else
    {
      strs[StringCount++] = str.substring(0, index);
      str = str.substring(index+1);
    }
  }
float arr[5];
  // Show the resulting substrings
  for (int i = 0; i < StringCount; i++)
  {
    //Serial.print(i);
    //Serial.print(": \"");
    if(strs[i].toFloat()!=0.0)
    {
      Serial.println((strs[i]).toFloat());
      arr[i] = (strs[i]).toFloat();

    }
    
    //Serial.println("\"");
  }
  senddata(arr[0],arr[1],arr[2],arr[3],arr[4]);

}

void senddata(float t, float h, float pm10, float pm20, float l)
{
  WiFiClient client;
  HTTPClient http;
  String newUrl=URL+String(t)+"&field3="+String(h)+"&field4="+String(pm10)+"&field5="+String(pm20)+"&field6="+String(l);
  http.begin(client,newUrl);
  int responsecode=http.GET();
  String data=http.getString();
  Serial.println(data);
  http.end();
  
}

Algorithm Code

Python
This Code is for Training And Analysing the data ,further predicting the weather situation of upcoming Days
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
data = pd.read_csv("/content/DailyDelhiClimateTest.csv")
print(data.head())

print(data.describe())

print(data.info())

figure = px.line(data, x="date", 
                 y="meantemp", 
                 title='Mean Temperature in Delhi Over the Years')
figure.show()

figure = px.line(data, x="date", 
                 y="humidity", 
                 title='Humidity in Delhi Over the Years')
figure.show()

figure = px.line(data, x="date", 
                 y="wind_speed", 
                 title='Wind Speed in Delhi Over the Years')
figure.show()

figure = px.scatter(data_frame = data, x="humidity",
                    y="meantemp", size="meantemp", 
                    trendline="ols", 
                    title = "Relationship Between Temperature and Humidity")
figure.show()

forecast_data = data.rename(columns = {"date": "ds", 
                                       "meantemp": "y"})
print(forecast_data)

#Finally facebook prophet code to get upcoming days Weather Condition

from prophet import Prophet
from prophet.plot import plot_plotly, plot_components_plotly
model = Prophet()
model.fit(forecast_data)
forecasts = model.make_future_dataframe(periods=365)
predictions = model.predict(forecasts)
plot_plotly(model, predictions)

Credits

Adarsh Kumar Maurya

Adarsh Kumar Maurya

2 projects • 0 followers
mohnish vats

mohnish vats

0 projects • 0 followers
Rohit Kumar

Rohit Kumar

0 projects • 0 followers

Comments