Designing an Air Quality Measurement System 3 - Measurement with MQ-135 and DHT-11
We included basic definitions in the previous two articles. We introduced the MQ-135 Gas sensor. We have examined the basic definitions of air quality.
In this article, we will read values from an environment with the MQ-135 gas sensor and the temperature-humidity sensor DHT-11 connected to a microcontroller. We will send these values to the HC-05 Bluetooth module at certain time intervals.
Links:
DHT-11 module "S" pin is connected to Arduino's digital pin 2,
MQ-135 module A0 pin is connected to Arduino's A0 Analog input,
HC-05 Bluetooth module TX- will be connected to digital pin 11 of Arduino, and RX will be connected to digital pin 10.
Arduino codes are below. The values read from DHT-11 and MQ-135 sensors are sent to the HC-05 module in JSON format. In the Andoid application to be designed later, the data in JSON format read from the Bluetooth module can be visualized graphically.
#include <dht.h> // Library for DHT-11 sensor
#include <SoftwareSerial.h> // Library for HC-05 Bluetooth module
#include <ArduinoJson.h> // Library for JSON processing
dht DHT;
#define DHT11_PIN 2 // Data pin of DHT-11 sensor
#define CO2_PIN A0 // Data pin of MQ-135 sensor
SoftwareSerial BTSerial(10, 11); // RX and TX pins of the Bluetooth module
void setup() {
BTSerial.begin(9600); // initialize the Bluetooth module
}
void loop() {
delay(5000); // 5 second cooldown
// Read temperature and humidity data
int16_t humidity = 0;
int16_t temperature = 0;
DHT.read11(DHT11_PIN, &temperature, &humidity);
// Read CO2 density
int CO2Value = analogRead(CO2_PIN);
// Create JSON object
StaticJsonDocument<128> jsonDoc;
jsonDoc["Temperature"] = temperature;
jsonDoc["Humidity"] = humidity;
jsonDoc["CO2_Density"] = CO2Value;
// Send JSON data over Bluetooth
serializeJson(jsonDoc, BTSerial);
BTSerial.println(); //Add new line to indicate end of data
}
This code adds the DHT-11 temperature and humidity sensor data, the MQ-135 CO2 sensor data to a JSON object, and then sends this JSON data over Bluetooth. JSON data is stored under the keys "Temperature", "Humidity" and "CO2_Density", and the values of the data are included with these keys.
Designing an Air Quality Measurement System 4 – Air Quality Monitoring Mobile Application