RAJESH SINHA
Published © CERN-OHL

IoT Based Weather Monitoring System Using Arduino

It is a system that involves in acquiring weather and environment data using advanced electronic sensors and sending them to a web server vi

AdvancedFull instructions provided5,633
IoT Based Weather Monitoring System Using Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
MQ 135
×1
12c Adapter
×1
RGB LCD Shield Kit, 16x2 Character Display
RGB LCD Shield Kit, 16x2 Character Display
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

IoT Based Weather Monitoring System Using Arduino

Code

Code for Esp 8266

Arduino
#include "ThingSpeak.h"
#include <ESP8266WiFi.h>

//------- WI-FI details ----------//
char ssid[] = "SSID"; //SSID here
char pass[] = "PASSWORD"; // Password here
//--------------------------------//

//----------- Channel details ----------------//
unsigned long Channel_ID = 123456; // Your Channel ID
const char * myWriteAPIKey = "ABC123CDE456"; //Your write API key
//-------------------------------------------//

const int Field_Number_1 = 1;
const int Field_Number_2 = 2;
const int Field_Number_3 = 3;
const int Field_Number_4 = 4;
const int Field_Number_5 = 5;
String value = "";
int value_1 = 0, value_2 = 0, value_3 = 0, value_4 = 0, value_5 = 0;
WiFiClient  client;

void setup()
{
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  ThingSpeak.begin(client);
  internet();
}

void loop()
{
  internet();
  if (Serial.available() > 0)
  {
    delay(100);
    while (Serial.available() > 0)
    {
      value = Serial.readString();
      if (value[0] == '*')
      {
        if (value[14] == '#')
        {
          value_1 = ((value[1] - 0x30) * 10 + (value[2] - 0x30));
          value_2 = ((value[3] - 0x30) * 10 + (value[4] - 0x30));
          value_3 = ((value[5] - 0x30) * 10000 + (value[6] - 0x30) * 1000 + (value[7] - 0x30) * 100 + (value[8] - 0x30) * 10 + (value[9] - 0x30));
          value_4 = ((value[10] - 0x30) * 10 + (value[11] - 0x30));
          value_5 = ((value[12] - 0x30) * 10 + (value[13] - 0x30));
        }
      }
    }
  }
  upload();
}

void internet()
{
  if (WiFi.status() != WL_CONNECTED)
  {
    while (WiFi.status() != WL_CONNECTED)
    {
      WiFi.begin(ssid, pass);
      delay(5000);
    }
  }
}

void upload()
{
  ThingSpeak.writeField(Channel_ID, Field_Number_1, value_1, myWriteAPIKey);
  delay(15000);
  ThingSpeak.writeField(Channel_ID, Field_Number_2, value_2, myWriteAPIKey);
  delay(15000);
  ThingSpeak.writeField(Channel_ID, Field_Number_3, value_3, myWriteAPIKey);
  delay(15000);
  ThingSpeak.writeField(Channel_ID, Field_Number_4, value_4, myWriteAPIKey);
  delay(15000);
  ThingSpeak.writeField(Channel_ID, Field_Number_5, value_5, myWriteAPIKey);
  delay(15000);
  value = "";
}

Code for Arduino

Arduino
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <dht.h>
#include <Wire.h>
#include <BMP180.h>
dht DHT;
LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial mySerial(10, 11);
BMP180 myBMP(BMP180_ULTRAHIGHRES);
#define DHT11_PIN A0
#define mq135_pin A2
#define LDR A1
void ReadDHT(void);
void ReadBMP(void);
void ReadAir(void);
void send_data(void);
bool BMP_flag = 0;
bool DHT_flag = 0;


void setup()
{
  mySerial.begin(115200);
  pinMode(mq135_pin, INPUT);
  pinMode(LDR, INPUT);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("  IoT  Weather  ");
  lcd.setCursor(0, 1);
  lcd.print("Monitor System");
  delay(1500);
}

void loop()
{
  ReadDHT();
  ReadBMP();
  ReadAir();
  Readlight();
  send_data();
}

void  ReadDHT(void)
{
  lcd.clear();
  int chk = DHT.read11(DHT11_PIN);
  switch (chk)
  {
    case DHTLIB_OK:
      DHT_flag = 1;
      lcd.setCursor(0, 0);
      lcd.print("Temp: ");
      lcd.print(DHT.temperature, 1);
      lcd.print(" *C");
      lcd.setCursor(0, 1);
      lcd.print("Humi: ");
      lcd.print(DHT.humidity, 1);
      lcd.print(" %");
      break;
    case DHTLIB_ERROR_CONNECT:
      lcd.setCursor(0, 0);
      lcd.print("NO DHT11 SENSOR");
      lcd.setCursor(0, 1);
      lcd.print("     FOUND!     ");
      break;
    case DHTLIB_ERROR_CHECKSUM:
    case DHTLIB_ERROR_TIMEOUT:
    case DHTLIB_ERROR_ACK_L:
    case DHTLIB_ERROR_ACK_H:
    default:
      DHT_flag = 0;
      lcd.setCursor(0, 0);
      lcd.print("  DHT11 SENSOR  ");
      lcd.setCursor(0, 1);
      lcd.print("     ERROR      ");
      break;
  }
  delay(2000);
}

void ReadBMP(void)
{
  lcd.clear();
  if (myBMP.begin() != true)
  {
    lcd.setCursor(0, 0);
    lcd.print(" BMP180  SENSOR ");
    lcd.setCursor(0, 1);
    lcd.print("    NOT FOUND   ");
    BMP_flag = 0;
    delay(2000);
  }
  else
  {
    BMP_flag = 1;
    lcd.setCursor(0, 0);
    lcd.print("Pa(Grnd):");
    lcd.print(myBMP.getPressure());
    lcd.setCursor(0, 1);
    lcd.print("Pa(sea) :");
    lcd.print(myBMP.getSeaLevelPressure(115));
  }
  delay(2000);
}

void ReadAir(void)
{
  int airqlty = 0;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("AIR QUALITY:");
  airqlty = analogRead(mq135_pin);
  lcd.print(map(analogRead(mq135_pin), 0, 1024, 99, 0));
  lcd.print("%");
  lcd.setCursor(0, 1);
  if (airqlty <= 180)
    lcd.print("GOOD!");
  else if (airqlty > 180 && airqlty <= 225)
    lcd.print("POOR");
  else if (airqlty > 225 && airqlty <= 300)
    lcd.print("VERY BAD");
  else
    lcd.print("TOXIC");
  delay(2000);
}

void Readlight(void)
{
  lcd.clear();
  lcd.setCursor(3, 0);
  lcd.print("LIGHT :");
  lcd.print(map(analogRead(LDR), 0, 1024, 0, 99));
  lcd.print("%");
  lcd.setCursor(0, 1);
  lcd.print("****************");
  delay(2000);
}

void send_data()
{
  mySerial.print('*'); // Starting char
  if (DHT_flag == 1)
  {
    mySerial.print(DHT.temperature, 0); //2 digit data
    mySerial.print(DHT.humidity, 0); //2 digit data    
  }
  else
  {    
    mySerial.print("0000"); // Send dummy data
  }
  if (BMP_flag == 1)
  {
    mySerial.print(myBMP.getPressure()); //5 digit data
  }
  else
  {
    mySerial.print("00000");// Send dummy data
  }
  mySerial.print(map(analogRead(LDR), 0, 1024, 0, 99)); //2 digit data
  mySerial.print(map(analogRead(mq135_pin), 0, 1024, 99, 0)); //2 digit data
  mySerial.println('#'); // Ending char
}

Credits

RAJESH SINHA

RAJESH SINHA

12 projects • 8 followers
Hey there! I'm Rajesh. I'm passionate about building innovative projects that solve real-world problems and make people's lives easier.

Comments