ANTT Robotics LTDMd. Toriqul IslamJahidul Islam Rahat
Published

Air Pollution Monitoring with AirIoT

Create a low power tool which will monitor the quality of air. Identify different gases present in air and save data to server.

BeginnerFull instructions provided1 hour236
Air Pollution Monitoring with AirIoT

Things used in this project

Hardware components

ESP32S
Espressif ESP32S
×1
SparkFun Atmospheric Sensor Breakout - BME280
SparkFun Atmospheric Sensor Breakout - BME280
×1
Grove - Gas Sensor(MQ2)
Seeed Studio Grove - Gas Sensor(MQ2)
×1
Gravity: Analog CH4 Gas Sensor (MQ4) For Arduino
DFRobot Gravity: Analog CH4 Gas Sensor (MQ4) For Arduino
×1
Gravity: Analog LPG Gas Sensor (MQ5) For Arduino
DFRobot Gravity: Analog LPG Gas Sensor (MQ5) For Arduino
×1
Gravity: Analog Carbon Monoxide Sensor (MQ7) For Arduino
DFRobot Gravity: Analog Carbon Monoxide Sensor (MQ7) For Arduino
×1

Software apps and online services

iotsnacksbox

Hand tools and fabrication machines

Soldering Station, 110 V
Soldering Station, 110 V
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Soldering
Solder Flux, Soldering

Story

Read more

Custom parts and enclosures

Schematic for AirIoT Dev Board

it's custom design board using esp32s2 as the MCU and in-built BME280 sensor.

Schematics

Schematic

Code

The Code

C/C++
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#include <HTTPClient.h>

const char* ssid = "your ssid";
const char* password = "your password";

const char* serverName1 = "https://api.iotsnacksbox.io/trigger/temperature?snacksboxtoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxx" ; // Replace the xxx with your token
const char* serverName2 = "https://api.iotsnacksbox.io/trigger/humidity?snacksboxtoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ; // Replace the xxx with your token
const char* serverName3 = "https://api.iotsnacksbox.io/trigger/pressure?snacksboxtoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ; // Replace the xxx with your token
const char* serverName4 = "https://api.iotsnacksbox.io/trigger/altitude?snacksboxtoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ; // Replace the xxx with your token



#define SEALEVELPRESSURE_HPA (1009)

float Temperature;
float Pressure;
float Altitude;
float Humidity;

Adafruit_BME280 bme;



void setup() {
  Serial.begin(115200);

  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());

}


void Post_Temperature() {
  Serial.print("Temperature = ");
  Serial.print(bme.readTemperature());
  Serial.println("*C");
  Temperature = bme.readTemperature();

  HTTPClient http;
  http.begin(serverName1);

  // Specify content-type header
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  http.addHeader("Content-Type", "application/json");

  const size_t capacity = 2 * JSON_OBJECT_SIZE(1);
  char buffer[capacity];
  DynamicJsonDocument doc(capacity);
  JsonObject data = doc.createNestedObject("data");
  data["Temperature"] = Temperature;
  serializeJson(doc, buffer);
  Serial.println(buffer);


  String httpRequestData = buffer;
  int httpResponseCode = http.POST(httpRequestData);

  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
  http.end();
}

void Post_Humidity() {
  Serial.print("Humidity = ");
  Serial.print(bme.readHumidity());
  Serial.println("%");
  Humidity = bme.readHumidity();

  HTTPClient http;
  http.begin(serverName2);

  // Specify content-type header
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  http.addHeader("Content-Type", "application/json");

  const size_t capacity = 2 * JSON_OBJECT_SIZE(1);
  char buffer[capacity];
  DynamicJsonDocument doc(capacity);
  JsonObject data = doc.createNestedObject("data");
  data["Humidity"] = Humidity;
  serializeJson(doc, buffer);
  Serial.println(buffer);


  String httpRequestData = buffer;
  int httpResponseCode = http.POST(httpRequestData);

  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
  http.end();

}

void Post_Pressure() {
  Serial.print("Pressure = ");
  Serial.print(bme.readPressure() / 100.0F);
  Serial.println("hPa");
  Pressure = (bme.readPressure() / 100.0F);

  HTTPClient http;
  http.begin(serverName3);

  // Specify content-type header
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  http.addHeader("Content-Type", "application/json");

  const size_t capacity = 2 * JSON_OBJECT_SIZE(1);
  char buffer[capacity];
  DynamicJsonDocument doc(capacity);
  JsonObject data = doc.createNestedObject("data");
  data["Pressure"] = Pressure;
  serializeJson(doc, buffer);
  Serial.println(buffer);


  String httpRequestData = buffer;
  int httpResponseCode = http.POST(httpRequestData);

  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
  http.end();


}

void Post_Altitude() {
  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println("m");
  Altitude = (bme.readAltitude(SEALEVELPRESSURE_HPA));

   HTTPClient http;
  http.begin(serverName4);

  // Specify content-type header
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  http.addHeader("Content-Type", "application/json");

  const size_t capacity = 2 * JSON_OBJECT_SIZE(1);
  char buffer[capacity];
  DynamicJsonDocument doc(capacity);
  JsonObject data = doc.createNestedObject("data");
  data["Altitude"] = Altitude;
  serializeJson(doc, buffer);
  Serial.println(buffer);


  String httpRequestData = buffer;
  int httpResponseCode = http.POST(httpRequestData);

  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
  http.end();

  
}



void loop() {

  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    Post_Temperature();
    Post_Humidity();
    Post_Pressure();
    Post_Altitude();
    delay(5000);
  }
  else {
    Serial.println("WiFi Disconnected");
  }


}

Credits

ANTT Robotics LTD
1 project • 0 followers
Contact
Md. Toriqul Islam
1 project • 0 followers
Contact
Jahidul Islam Rahat
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.