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

Arduino UNO Based Environmental Monitoring System with Gas Detection and Alert

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Environmental Monitoring System with Gas Detection and Alert

Circuit Documentation

Summary

This circuit is designed around an Arduino UNO microcontroller and includes various sensors and output devices. The primary sensor is a DHT11, which measures temperature and humidity. An MQ-5 gas sensor is used to detect the presence of gases such as LPG, natural gas, and coal gas. Output devices include a piezo buzzer and two LEDs (red and green). The circuit is powered by the Arduino UNO's 5V output, and ground connections are shared among components. The Arduino UNO reads sensor data and controls the LEDs and buzzer based on the sensor inputs.

Component List

Wiring Details

Arduino UNO

DHT11

MQ-5 Gas Sensor

Piezo Buzzer

Resistor (200 Ohms)

LED (Green)

LED (Red)

Documented Code

#include <DHT.h>
#define DHTPIN 2          // Define the pin connected to the DHT11 sensor
#define DHTTYPE DHT11     // Specify the type of DHT sensor
DHT dht(DHTPIN, DHTTYPE);
#define MQ5_PIN A0        // Define the pin connected to the MQ-5 sensor
#define RED_LED_PIN 8     // Define the pin connected to the red LED
#define GREEN_LED_PIN 9   // Define the pin connected to the green LED
#define BUZZER_PIN 10     // Define the pin connected to the buzzer
#define MOTION_PIN 3      // Define the pin connected to the motion sensor (not included in the wiring details)

void setup() {
  Serial.begin(9600);    // Start serial communication at 9600 baud
  dht.begin();           // Initialize the DHT sensor
  pinMode(MOTION_PIN, INPUT);       // Set the motion sensor pin as input
  pinMode(RED_LED_PIN, OUTPUT);     // Set the red LED pin as output
  pinMode(GREEN_LED_PIN, OUTPUT);   // Set the green LED pin as output
  pinMode(BUZZER_PIN, OUTPUT);      // Set the buzzer pin as output
}

void loop() {
  float h = dht.readHumidity();          // Read humidity value
  float t = dht.readTemperature();       // Read temperature value
  int mq5Value = analogRead(MQ5_PIN);    // Read the value from the MQ-5 sensor
  int motion_Detected = digitalRead(MOTION_PIN);  // Read the motion sensor value

  // Print the sensor values to the serial monitor
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print("%  Temperature: ");
  Serial.print(t);
  Serial.print("°C  MQ-5 Value: ");
  Serial.println(mq5Value);
  Serial.print("\tMotion Detected:");
  Serial.println(motion_Detected);

  // Control the LEDs and buzzer based on the MQ-5 sensor value
  if (mq5Value > 150) {
    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(GREEN_LED_PIN, LOW);
    tone(BUZZER_PIN, 1000);  // Sound the buzzer
  } else {
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(GREEN_LED_PIN, HIGH);
    noTone(BUZZER_PIN);       // Stop the buzzer
  }

  // If motion is detected, turn on both LEDs briefly
  if (motion_Detected) {
    digitalWrite(GREEN_LED_PIN, HIGH);
    digitalWrite(RED_LED_PIN, HIGH);
    delay(50);
  }

  delay(2000);  // Wait for 2 seconds before reading the sensors again
}

This code is designed to read temperature and humidity from the DHT11 sensor, detect gas levels with the MQ-5 sensor, and detect motion (although the motion sensor is not included in the wiring details). The red and green LEDs, as well as the buzzer, are controlled based on the readings from the MQ-5 sensor. If the gas level is above a certain threshold, the red LED is turned on, the green LED is turned off, and the buzzer is sounded. If the gas level is below the threshold, the green LED is turned on, and the red LED and buzzer are turned off. If motion is detected, both LEDs are turned on for a brief moment.