Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Gas Leak Detection System with LCD Display and SIM800L Alert

View and Edit Project In Cirkit DesignerImage of Arduino UNO Gas Leak Detection System with LCD Display and SIM800L Alert

Circuit Documentation

Summary

This circuit is designed to monitor gas levels using an MQ2 gas sensor and display the readings on a 16x2 I2C LCD screen. If the gas level exceeds a certain threshold, an alert is sent via the SIM800L module, and a buzzer is activated. The circuit is controlled by an Arduino UNO microcontroller.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. MQ2

    • Description: Gas sensor for detecting LPG, i-butane, propane, methane, alcohol, hydrogen, and smoke.
    • Pins: VCC, GND, AOUT, DOUT
  3. LCD screen 16x2 I2C

    • Description: 16x2 character LCD display with I2C interface.
    • Pins: SCL, SDA, VCC, GND
  4. SIM800L

    • Description: GSM/GPRS module for sending SMS and connecting to the internet.
    • Pins: NFT, RING, VCC, DTR, RST, MIC +, RXD, MIC-, TXD, SPK+, GND, SPK-
  5. 3.7V Battery

    • Description: Power source for the circuit.
    • Pins: +, -
  6. Buzzer

    • Description: Audio signaling device.
    • Pins: POSITIVE, NEGATIVE

Wiring Details

Arduino UNO

MQ2

LCD screen 16x2 I2C

SIM800L

3.7V Battery

Buzzer

Documented Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>

// Define the pins
const int gasSensorPin = A1; // MQ2 analog output connected to A1
const int buzzerPin = 6;     // Buzzer connected to D6
const int sim800lTx = 3;     // SIM800L TX connected to D3
const int sim800lRx = 2;     // SIM800L RX connected to D2

// Initialize the LCD
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address to 0x27 if needed

// Initialize the SIM800L
SoftwareSerial sim800l(sim800lRx, sim800lTx);

void setup() {
  // Initialize the LCD
  lcd.begin(16, 2); // Specify the number of columns and rows
  lcd.backlight();
  
  // Initialize the serial communication for debugging
  Serial.begin(9600);
  
  // Initialize the SIM800L
  sim800l.begin(9600);
  
  // Set the buzzer pin as output
  pinMode(buzzerPin, OUTPUT);
  
  // Print a message to the LCD
  lcd.setCursor(0, 0);
  lcd.print("Gas Sensor Init");
  delay(2000);
  lcd.clear();
}

void loop() {
  // Read the gas sensor value
  int gasValue = analogRead(gasSensorPin);
  
  // Print the gas value to the LCD
  lcd.setCursor(0, 0);
  lcd.print("Gas Value: ");
  lcd.print(gasValue);
  
  // Print the gas value to the serial monitor
  Serial.print("Gas Value: ");
  Serial.println(gasValue);
  
  // Check if the gas value exceeds the threshold
  if (gasValue > 300) { // Adjust the threshold as needed
    // Sound the buzzer
    digitalWrite(buzzerPin, HIGH);
    
    // Send an alert message using SIM800L
    sendAlertMessage(gasValue);
  } else {
    digitalWrite(buzzerPin, LOW);
  }
  
  // Wait for a second before the next reading
  delay(1000);
}

void sendAlertMessage(int gasValue) {
  // Send SMS alert
  sim800l.println("AT+CMGF=1"); // Set SMS mode to text
  delay(1000);
  sim800l.println("AT+CMGS=\"+1234567890\""); // Replace with the recipient's phone number
  delay(1000);
  sim800l.print("Gas Alert! Value: ");
  sim800l.print(gasValue);
  delay(1000);
  sim800l.write(26); // ASCII code for CTRL+Z to send the message
  delay(1000);
}

This code initializes the LCD and SIM800L modules, reads the gas sensor value, displays it on the LCD, and sends an alert message if the gas value exceeds a specified threshold. The buzzer is also activated when the threshold is exceeded.