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

Arduino UNO Based Gas Detection System with MQ Sensors and DHT11

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Gas Detection System with MQ Sensors and DHT11

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions using gas sensors (MQ135 and MQ-4) and a temperature and humidity sensor (DHT11). It provides visual indicators through LEDs and an audible alert using a buzzer. The Arduino UNO serves as the central processing unit, reading sensor data and controlling the LEDs and buzzer based on predefined gas level thresholds.

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

/*
 * This Arduino sketch reads data from MQ135 and MQ-4 gas sensors and a DHT11
 * temperature and humidity sensor. If the gas level is high, it glows the green
 * LED and turns off the red LED. If the gas level is low, it glows the red LED
 * and turns off the green LED. The buzzer buzzes when the gas level is high.
 */

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

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

// Threshold value for gas levels
int gasThreshold = 400; // Digital threshold for gas sensors (MQ135 and MQ-4)

// 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_D0, INPUT);
  pinMode(MQ4_D0, INPUT);
}

void loop() {
  // Read MQ135 and MQ-4 gas sensor digital values
  int mq135_digital = digitalRead(MQ135_D0);
  int mq4_digital = digitalRead(MQ4_D0);

  // Calculate combined gas levels
  int combinedGasLevel = mq135_digital || mq4_digital;

  // Print gas sensor readings
  Serial.print("MQ135 Digital: ");
  Serial.println(mq135_digital);
  Serial.print("MQ4 Digital: ");
  Serial.println(mq4_digital);

  // Determine and print food safety status based on gas
  if (combinedGasLevel >= gasThreshold) {
    Serial.println("Gas Level: High");
    digitalWrite(GREEN_LED, HIGH); // Turn on green LED (high gas level)
    digitalWrite(RED_LED, LOW);    // Turn off red LED (low gas level)
    digitalWrite(BUZZER, HIGH);    // Turn on buzzer (alert)
  } else {
    Serial.println("Gas Level: Low");
    digitalWrite(GREEN_LED, LOW);  // Turn off green LED (high gas level)
    digitalWrite(RED_LED, HIGH);   // Turn on red LED (low gas level)
    digitalWrite(BUZZER, LOW);     // Turn off buzzer
  }

  // Delay between readings
  delay(2000);
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the sensors and controls the LEDs and buzzer based on the sensor readings. The code includes comments explaining each section and the functionality of the circuit.