ESP8266 based Air Pollution Detector

Published  February 24, 2022   0
V Vighnesh Nauso…
Author
Air Pollution Detector using ESP8266

India has the distinction of releasing the largest volumes of pollutants into the air after China. The majority of the cities with the most polluted air are in India. Air pollution is the fifth largest killer in the country, according to Global Burden of Disease. Many areas in the Indian States, and the world, are faced with serious air quality problems. It is the most important environmental health risk of our times. Air in our cities is becoming hazardous to breathe but it is not immediately reported to the controlling authorities. Currently, Air in our cities is becoming hazardous to breathe but it is not immediately reported to the controlling authorities and therefore result in a delay in action. Because of this the polluting agencies like the factories are getting escaped, resulting in hazardous health issues. So to cater this problem, I have developed an Air pollution detector using ESP8266. This system detects and reports pollution on the mobile app developed by me. It also gives warnings to the nearby public when the pollution crosses the defined limit by turning on the siren. 

Air Pollution Detector

Previously, we built some projects on Air Quality Monitoring, 

Component Required for Air Pollution Detector

Project Used Hardware

  • Wemos D1 (esp8266),
  • MQ3 Sensor,
  • Battery \ solar panel \ 5-12v adapter for power supply,
  • Buzzer

Project Used Software

  • Kodular Creator (clone of MIT app inventor), 
  • Arduino IDE,
  • Firebase Realtime Database,
  • Firebase Authentication

Project Hardware/Software Selection

On the Hardware side, I used Wemos D1 which is an esp8266 based board because it is a low-cost microcontroller that has Wi-Fi connectivity for sending data to the internet. I have also used an MQ3 sensor for measuring the amount of smoke present in the air, Buzzer as a siren, and a power supply for the device. On the Software side, I have used Arduino IDE to program the microcontroller. As a database and IoT server, I have used Google Firebase's Realtime Database. To build the android app I have used Kodular Creator which is a clone of MIT app inventor. For Authentication, I have used Firebase Authentication.

Air Pollution Detector Circuit Diagram

 

Circuit Diagram for Air Pollution Detector

The GND and VCC of the MQ3 sensor are connected to GND and 5v of the Wemos D1 Respectively. The Analog output is connected to the A0 pin of the Wemos D1. The Buzzer is connected to the D2 pin of the Wemos D1 controller.

Code
#include <WiFiManager.h>
#include "FirebaseESP8266.h"
#include <ESP8266WiFi.h>

#define nameofdevice "Device 1"

FirebaseData firedb;
int status;

void setup()
{
  status = 1;
  pinMode(D2, OUTPUT);
  pinMode(A0, INPUT);
  WiFi.mode(WIFI_STA);
  Serial.begin(115200);
  WiFiManager wm;

  bool res;

  res = wm.autoConnect("Air Pollution Detector", "pollution");
  if (!res) {
    Serial.println("Failed to connect");
  }
  else {
    Serial.println("connected...yeey :)");
    Firebase.begin( "smart-9b2ba-default-rtdb.firebaseio.com", "0CgaJ1CmWwsiNqAymhQnLHgqwXEbwkDvL9zXuFG6");
    Serial.println("Firebase Connected");
  }

}

void loop()
{

  int value = analogRead(A0);
  Serial.println(value);

    if (status == 1)    {
        if (value > 700)
        {
          Firebase.setString(firedb, "/database/Device 1/Pollution Level", "Device1" );
          Firebase.setString(firedb, "/database/alerts", "Device1" );
          digitalWrite(D2,HIGH);
          status = 0;
        }
    }
else{
    if (value < 700 )
    {

        status = 1;
                  digitalWrite(D2,LOW);

     }
}
delay(1000);
}

Video

Have any question realated to this Article?

Ask Our Community Members