Arduino UNO Based Gas Detection System with MQ Sensors and DHT11
View and Edit Project In Cirkit Designer
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
- Pins: VCC, GND, A0, D0
- Description: Sensor for detecting a wide range of gases, including NH3, NOx, alcohol, benzene, smoke, and CO2.
MQ-4 Methane Gas Sensor
- Pins: VCC, GND, A0, D0
- Description: Sensor for detecting methane (CH4) gas concentrations in the air.
DHT11 Temperature and Humidity Sensor V2
- Pins: GND, DAT, VCC
- Description: Sensor for measuring ambient temperature and humidity.
LED: Two Pin (Red)
- Pins: Cathode, Anode
- Description: Red indicator LED.
LED: Two Pin (Green)
- Pins: Cathode, Anode
- Description: Green indicator LED.
Arduino UNO
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13
- Description: Microcontroller board based on the ATmega328P, used for controlling the sensors, LEDs, and buzzer.
Resistor (220 Ohms)
- Pins: Pin1, Pin2
- Description: Current-limiting resistor for the green LED.
Resistor (200 Ohms)
- Pins: Pin1, Pin2
- Description: Current-limiting resistors for the red LED and other components.
Buzzer
- Pins: PIN, GND
- Description: Audible alert device.
Wiring Details
MQ135 Gas Sensor
- VCC: Connected to 5V on Arduino UNO
- GND: Connected to GND on Arduino UNO
- A0: Not connected
- D0: Connected to D3 on Arduino UNO
MQ-4 Methane Gas Sensor
- VCC: Connected to 5V on Arduino UNO
- GND: Connected to GND on Arduino UNO
- A0: Connected to A1 on Arduino UNO
- D0: Connected to D4 on Arduino UNO
DHT11 Temperature and Humidity Sensor V2
- VCC: Connected to 5V on Arduino UNO
- DAT: Connected to D2 on Arduino UNO
- GND: Connected to GND on Arduino UNO
LED: Two Pin (Red)
- Anode: Connected to D6 on Arduino UNO through a 200 Ohm resistor
- Cathode: Connected to GND on Arduino UNO
LED: Two Pin (Green)
- Anode: Connected to D5 on Arduino UNO through a 220 Ohm resistor
- Cathode: Connected to GND on Arduino UNO
Buzzer
- PIN: Connected to D7 on Arduino UNO
- GND: Connected to GND on Arduino UNO
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.