This circuit is designed to function as an LPG Gas Detector using an Arduino Nano as the central processing unit. It incorporates an MQ6 gas sensor to detect the presence of LPG gas, a red LED to provide a visual indication, and a buzzer for an audible alarm. The system operates by continuously monitoring the gas concentration in the air. If the detected gas level exceeds a predefined threshold, the circuit activates both the LED and the buzzer to alert the user.
/*
* LPG Gas Detector using Arduino Nano
* This code reads the analog value from the MQ6 gas sensor and turns on an LED
* and a buzzer if the gas concentration exceeds a certain threshold.
*/
const int gasSensorPin = A0; // MQ6 sensor analog output connected to A0
const int buzzerPin = 2; // Buzzer connected to digital pin 2
const int ledPin = 3; // LED connected to digital pin 3
const int threshold = 300; // Threshold value for gas concentration
void setup() {
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
pinMode(ledPin, OUTPUT); // Set 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(ledPin, HIGH); // Turn on LED
} else {
digitalWrite(buzzerPin, LOW); // Turn off buzzer
digitalWrite(ledPin, LOW); // Turn off LED
}
delay(1000); // Wait for 1 second before next reading
}
This code is designed to be uploaded to the Arduino Nano. It initializes the pins connected to the buzzer, LED, and MQ6 gas sensor. The loop
function reads the analog value from the gas sensor and compares it to the threshold. If the gas level is above the threshold, it activates the buzzer and LED to warn of high gas concentration. The gas level is also printed to the serial monitor for debugging purposes.