0% found this document useful (0 votes)
35 views5 pages

Air - Quality - Exp 1

This document describes a project to monitor air quality using an ESP32 or ESP8266 microcontroller along with DHT and MQT15 sensors. It reads temperature, humidity, and air quality measurements from the sensors and sends the data to the cloud database ThingSpeak. The ESP connects to WiFi and makes HTTP POST requests to the ThingSpeak API, transmitting the sensor readings as URL encoded parameters to update the channel fields on each loop iteration.

Uploaded by

Jeeshu Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views5 pages

Air - Quality - Exp 1

This document describes a project to monitor air quality using an ESP32 or ESP8266 microcontroller along with DHT and MQT15 sensors. It reads temperature, humidity, and air quality measurements from the sensors and sends the data to the cloud database ThingSpeak. The ESP connects to WiFi and makes HTTP POST requests to the ThingSpeak API, transmitting the sensor readings as URL encoded parameters to update the channel fields on each loop iteration.

Uploaded by

Jeeshu Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Air Quaity Montitoring using ESP32 8266 microcontroller and MQT15 & DHT sensors

#include <DHT12.h>

//Air Quality Monitoring

#include <DHT.h> // Including library for dht

#include "MQ135.h"

#include <ESP8266WiFi.h>
String apiKey = ""; // Enter your Write API key from ThingSpeak

const char *ssid =" "; // replace with your wifi ssid and wpa2 key

const char *pass ="";

const char* server = "api.thingspeak.com";

const int sensorPin= 0;

int air_quality;

#define DHTPIN D4 //Connect to GPIO 2 in NodeMCU Board

DHT dht(DHTPIN, DHT11);

WiFiClient client;

void setup()

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();

//int gasValue = analogRead(gas);

MQ135 gasSensor = MQ135(A0);

air_quality = gasSensor.getPPM();

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 +="&field3=";

postStr += String(air_quality);

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("Temperature: ");

Serial.print(t);

Serial.print(" degrees Celcius, Humidity: ");

Serial.print(h);

//Serial.print("%, Gas Value: ");

//Serial.print(h);

Serial.print("%, Air Quality: ");

Serial.print(air_quality);

Serial.println("PPM. Send to Thingspeak.");

client.stop();

Serial.println("Waiting...");

// thingspeak needs minimum 15 sec delay between updates

delay(1000);
}

You might also like