Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino Nano LPG Gas Leak Detector with LED and Buzzer Alerts

Image of Arduino Nano LPG Gas Leak Detector with LED and Buzzer Alerts

Circuit Documentation

Summary

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.

Component List

  1. Arduino Nano

    • Description: A small, complete, and breadboard-friendly board based on the ATmega328P.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
  2. LED: Two Pin (red)

    • Description: A standard red LED with two pins.
    • Pins: cathode, anode
  3. LED: Two Pin (green)

    • Description: A standard green LED with two pins.
    • Pins: cathode, anode
  4. Buzzer

    • Description: A simple piezoelectric buzzer.
    • Pins: PIN, GND
  5. MQ-2 Gas Sensor

    • Description: A gas sensor that can detect LPG, i-butane, propane, methane, alcohol, Hydrogen, and smoke.
    • Pins: GND, VCC, ANALOG, Digital

Wiring Details

Arduino Nano

  • GND is connected to:

    • LED (red) cathode
    • LED (green) cathode
    • Buzzer GND
    • MQ-2 GND
  • D2 is connected to:

    • Buzzer PIN
  • D3 is connected to:

    • LED (red) anode
  • D4 is connected to:

    • LED (green) anode
  • 5V is connected to:

    • MQ-2 VCC
  • A0 is connected to:

    • MQ-2 ANALOG

LED: Two Pin (red)

  • cathode is connected to:

    • Arduino Nano GND
  • anode is connected to:

    • Arduino Nano D3

LED: Two Pin (green)

  • cathode is connected to:

    • Arduino Nano GND
  • anode is connected to:

    • Arduino Nano D4

Buzzer

  • PIN is connected to:

    • Arduino Nano D2
  • GND is connected to:

    • Arduino Nano GND

MQ-2 Gas Sensor

  • GND is connected to:

    • Arduino Nano GND
  • VCC is connected to:

    • Arduino Nano 5V
  • ANALOG is connected to:

    • Arduino Nano A0

Code Documentation

/*
 * 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.