Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Air Quality and Temperature Monitoring System with Alert Indicators

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Air Quality and Temperature Monitoring System with Alert Indicators

Circuit Documentation

Summary

The circuit in question is designed to monitor environmental conditions such as gas levels and temperature, and to provide visual and auditory alerts based on the readings. It utilizes a set of sensors including the MQ135 and MQ-4 for gas detection, and the DHT11 for temperature and humidity measurement. The circuit employs an Arduino UNO as the central microcontroller to process sensor data and control outputs such as LEDs and a buzzer based on predefined threshold values.

Component List

MQ135 Gas Sensor

MQ-4 Methane Gas Sensor

DHT11 Temperature and Humidity Sensor V2

LED: Two Pin (Red)

LED: Two Pin (Green)

Arduino UNO

Resistor (220 Ohms)

Resistor (200 Ohms)

Buzzer

Wiring Details

MQ135 Gas Sensor

MQ-4 Methane Gas Sensor

DHT11 Temperature and Humidity Sensor V2

LED: Two Pin (Red)

LED: Two Pin (Green)

Buzzer

Documented Code

#include <UnoWiFiDevEd.h>
#include <DHT.h>

// Pin assignments
#define DHTPIN 2
#define DHTTYPE DHT11
#define MQ135_A0 A0
#define MQ135_D0 3
#define MQ4_A0 A1
#define MQ4_D0 4
#define RED_LED 5
#define GREEN_LED 6
#define BUZZER 7

// Threshold values for gas levels and temperature
int gasThreshold = 400; // Analog threshold for gas sensors (MQ135 and MQ-4)
float tempThreshold = 25.0; // Temperature threshold in Celsius

// DHT11 sensor
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize DHT11 sensor
  dht.begin();

  // Initialize LED and buzzer pins
  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(BUZZER, OUTPUT);

  // Initialize MQ sensor pins
  pinMode(MQ135_A0, INPUT);
  pinMode(MQ135_D0, INPUT);
  pinMode(MQ4_A0, INPUT);
  pinMode(MQ4_D0, INPUT);
}

void loop() {
  // Read temperature and humidity from DHT11
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  // Read MQ135 and MQ-4 gas sensor analog values
  int mq135_analog = analogRead(MQ135_A0);
  int mq4_analog = analogRead(MQ4_A0);

  // Calculate combined gas levels
  int combinedGasLevel = (mq135_analog + mq4_analog) / 2;

  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT11 sensor!");
  } else {
    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.print("%  Temperature: ");
    Serial.print(temperature);
    Serial.println("°C");
  }

  // Print pesticide level based on gas sensor readings
  if (combinedGasLevel >= gasThreshold) {
    Serial.println("Pesticide Level: High");
  } else {
    Serial.println("Pesticide Level: Low");
  }

  // Determine and print food safety status based on gas and temperature
  if (combinedGasLevel >= gasThreshold || temperature >= tempThreshold) {
    Serial.println("Food Status: Spoiled");
    digitalWrite(RED_LED, HIGH);   // Turn on red LED (spoiled)
    digitalWrite(GREEN_LED, LOW);  // Turn off green LED (safe)
    digitalWrite(BUZZER, HIGH);    // Turn on buzzer (alert)
  } else {
    Serial.println("Food Status: Safe");
    digitalWrite(RED_LED, LOW);    // Turn off red LED (spoiled)
    digitalWrite(GREEN_LED, HIGH); // Turn on green LED (safe)
    digitalWrite(BUZZER, LOW);     // Turn off buzzer
  }

  // Print gas sensor readings
  Serial.print("MQ135 Analog: ");
  Serial.println(mq135_analog);
  Serial.print("MQ4 Analog: ");
  Serial.println(mq4_analog);

  // Delay between readings
  delay(2000);
}

This code is designed to run on the Arduino UNO microcontroller. It initializes the sensors and output devices, reads sensor data, and controls the LEDs and buzzer based on the sensor readings. The code includes comments explaining the purpose of each section and the logic behind the alert conditions.