This document describes a circuit built using an Arduino Nano, a green LED, a red LED, a buzzer module, an MQ-2 gas sensor, and a WiFi module (ESP8266-01). The circuit is designed to monitor gas levels using the MQ-2 sensor and provide visual and auditory alerts when gas levels exceed a certain threshold. The green LED indicates normal operation, while the red LED and buzzer are activated when gas levels are high. The WiFi module is used for potential remote monitoring and control.
Arduino Nano
LED: Two Pin (red)
LED: Two Pin (green)
Buzzer Module
MQ-2 Gas Sensor
WiFi Module ESP8266-01
/*
* Circuit Description:
* This Arduino Nano circuit has a green LED connected to pin D4 and its cathode
* connected to GND. The code ensures that the green LED is always on.
* Additionally, a red LED is connected to pin D5 and its cathode connected to
* GND. The code ensures that the red LED is always on.
* A buzzer is connected to pin D2 and is always on.
* An MQ-2 gas sensor is connected to analog pin A0 to read gas levels every 1 second.
*/
const int redLedPin = 5; // Red LED connected to digital pin 5
const int greenLedPin = 4; // Green LED connected to digital pin 4
const int buzzerPin = 2; // Buzzer connected to digital pin 2
const int mq2AnalogPin = A0; // MQ-2 sensor connected to analog pin A0
const int threshold = 300; // Threshold value for gas concentration
void setup() {
pinMode(redLedPin, OUTPUT); // Set red LED pin as output
pinMode(greenLedPin, OUTPUT); // Set green LED pin as output
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int gasLevel = analogRead(mq2AnalogPin); // Read gas level from MQ-2 sensor
Serial.print("Gas Level: ");
Serial.println(gasLevel); // Print gas level to serial monitor
if (gasLevel > threshold) { // If gas level exceeds threshold
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
tone(buzzerPin, 1000, 1000);
digitalWrite(redLedPin, HIGH); // Turn on red LED
delay(1000); // Wait for 1 seconds
noTone(buzzerPin); // Stop the buzzer tone
digitalWrite(buzzerPin, LOW); // Turn off buzzer
digitalWrite(redLedPin, LOW); // Turn off red LED
} else {
digitalWrite(greenLedPin, HIGH); // Turn on green LED
delay(1000); // Green LED on for 2 second
digitalWrite(greenLedPin, LOW); // Turn off green LED
delay(3000); // Wait for 3 seconds before next flash
}
}
This code initializes the pins for the red LED, green LED, and buzzer as outputs. It reads the gas level from the MQ-2 sensor every second and prints the value to the serial monitor. If the gas level exceeds the threshold, the buzzer and red LED are activated. If the gas level is below the threshold, the green LED is flashed.