This circuit is an LPG Gas Leak Detector using an Arduino Nano. It reads the analog value from an MQ-2 gas sensor and activates a red LED and a buzzer if the gas concentration exceeds a certain threshold. When no gas leak is detected, a green LED will flash every 5 seconds.
Arduino Nano
LED: Two Pin (red)
LED: Two Pin (green)
Buzzer
MQ-2 Gas Sensor
GND is connected to:
D2 is connected to:
D3 is connected to:
D4 is connected to:
5V is connected to:
A0 is connected to:
cathode is connected to:
anode is connected to:
cathode is connected to:
anode is connected to:
PIN is connected to:
GND is connected to:
GND is connected to:
VCC is connected to:
ANALOG is connected to:
/*
* LPG Gas Leak Detector using Arduino Nano
* This code reads the analog value from the MQ2 gas sensor and turns on a red LED
* and a buzzer if the gas concentration exceeds a certain threshold. When no gas
* leak is detected, a green LED will flash every 5 seconds.
*/
const int gasSensorPin = A0; // MQ2 sensor analog output connected to A0
const int buzzerPin = 2; // Buzzer connected to digital pin 2
const int redLedPin = 3; // Red LED connected to digital pin 3
const int greenLedPin = 4; // Green LED connected to digital pin 4
const int threshold = 300; // Threshold value for gas concentration
void setup() {
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
pinMode(redLedPin, OUTPUT); // Set red LED pin as output
pinMode(greenLedPin, OUTPUT); // Set green LED pin as output
pinMode(gasSensorPin, INPUT); // Set gas sensor pin as input
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int gasLevel = analogRead(gasSensorPin); // Read gas sensor value
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
digitalWrite(redLedPin, HIGH); // Turn on red LED
delay(15000); // Wait for 15 seconds
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 1 second
digitalWrite(greenLedPin, LOW); // Turn off green LED
delay(4000); // Wait for 4 seconds before next flash
}
}
This code initializes the pins for the gas sensor, buzzer, and LEDs. It continuously reads the gas level from the MQ-2 sensor and checks if it exceeds a predefined threshold. If the gas level is above the threshold, the buzzer and red LED are activated for 15 seconds. If the gas level is below the threshold, the green LED flashes every 5 seconds.