#include <DHT.h>
#define DHTPIN 12
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define MQ_PIN 34 // Analog input pin for MQ sensor
void setup() {
Serial.begin(115200);
dht.begin();
delay(1000);
Serial.println("Time(ms),Gas,Temperature,Humidity");
}
void loop() {
int gasValue = analogRead(MQ_PIN); // Read gas sensor (0-4095)
float temp = dht.readTemperature(); // Temperature in °C
float hum = dht.readHumidity(); // Humidity in %
// If DHT fails, skip plotting
if (isnan(temp) || isnan(hum)) {
Serial.println("DHT22 read error");
} else {
// Print values in CSV format: useful for Serial Plotter
Serial.print(millis()); Serial.print(",");
Serial.print(gasValue); Serial.print(",");
Serial.print(temp); Serial.print(",");
Serial.println(hum);
}
delay(1000); // 1-second update
}