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

Arduino UNO Based Gas Detection and GSM Alert System

Image of Arduino UNO Based Gas Detection and GSM Alert System

Circuit Documentation

Summary

This circuit is designed to monitor air quality using an MQ135 gas sensor and alert the user through visual indicators (LEDs), an audible alarm (Piezo Buzzer), and communication via the SIM800L GSM module. The Arduino UNO serves as the central microcontroller, interfacing with the MQ135 sensor, LEDs, buzzer, and SIM800L module. The circuit also includes an I2C module connected to a 16x2 LCD for displaying air quality information. The system is powered by a 3.7V battery.

Component List

Resistor

  • Description: A resistor with a resistance of 200 Ohms.
  • Pins: pin1, pin2

Piezo Buzzer

  • Description: A buzzer used to generate an audible alarm.
  • Pins: pin 1, pin 2

LED: Two Pin (red)

  • Description: A red LED used as a visual indicator for alerts.
  • Pins: cathode, anode

LED: Two Pin (green)

  • Description: A green LED used as a visual indicator for normal operation.
  • Pins: cathode, anode

SIM800L

  • Description: A GSM module used for sending SMS and making calls.
  • Pins: NFT, RING, VCC, DTR, RST, MIC +, RXD, MIC-, TXD, SPK+, GND, SPK-

3.7V Battery

  • Description: A battery providing power to the circuit.
  • Pins: +, -

MQ135

  • Description: A gas sensor for detecting hazardous gases in the air.
  • Pins: VCC, GND, A0, D0

16X2 LCD

  • Description: A liquid crystal display for showing air quality information.
  • Pins: VSS, VDD, V0, RS, RW, E, D1, D0, D2, D3, D4, D6, D5, D7, A, K

I2C Module

  • Description: An interface module for the LCD to communicate over I2C.
  • Pins: VSS, VO, RS, RW, E, DB0, DB1, DB2, DB3, DB4, DB5, DB6, DB7, LEDA, LEDK, GND, VCC, SDA, SCL, VDD

Arduino UNO

  • Description: The main microcontroller board that controls the circuit.
  • 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

MAX30100

  • Description: A pulse oximeter and heart-rate sensor.
  • Pins: VIN, SDA, SCL, GND, RD, IRD, INT

MAX30102

  • Description: An upgraded pulse oximeter and heart-rate sensor.
  • Pins: VIN, SDA, SCL, GND, RD, IRD, INT

Wiring Details

Resistor

  • Connected between the Arduino UNO 5V pin and various components for current limiting.

Piezo Buzzer

  • Pin 1 connected to Arduino UNO GND.
  • Pin 2 connected to Arduino UNO D2.

LED: Two Pin (red)

  • Cathode connected to Arduino UNO GND.
  • Anode connected to Arduino UNO D4 through a resistor.

LED: Two Pin (green)

  • Cathode connected to Arduino UNO GND.
  • Anode connected to Arduino UNO D5 through a resistor.

SIM800L

  • VCC connected to the 3.7V battery + pin.
  • GND connected to Arduino UNO GND.
  • RXD connected to Arduino UNO D1.
  • TXD connected to Arduino UNO D0.

MQ135

  • VCC connected to Arduino UNO 5V through a resistor.
  • GND connected to Arduino UNO GND.
  • A0 connected to Arduino UNO A0.

16X2 LCD and I2C Module

  • The I2C module is connected to the corresponding pins on the 16X2 LCD.
  • VCC of the I2C module connected to Arduino UNO 5V.
  • GND of the I2C module connected to Arduino UNO GND.
  • SDA of the I2C module connected to Arduino UNO A4.
  • SCL of the I2C module connected to Arduino UNO A5.

Arduino UNO

  • Powers the circuit and interfaces with all components.

MAX30100 and MAX30102

  • Not directly mentioned in the wiring details, but typically connected to the I2C bus (SDA, SCL) and powered by the Arduino UNO 3.3V or 5V pins.

Documented Code

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

#define MQ135_PIN A0
#define RED_LED_PIN 4
#define GREEN_LED_PIN 5
#define BUZZER_PIN 2
#define GSM_RX_PIN 1
#define GSM_TX_PIN 0

LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial gsm(GSM_RX_PIN, GSM_TX_PIN);

const int threshold = 310;
const unsigned long smsInterval = 60000;
const unsigned long callInterval = 180000;
unsigned long lastSmsTime = 0;
unsigned long lastCallTime = 0;

// Timer variables for LED blinking and buzzer activation
unsigned long ledBlinkTimer = 0;
unsigned long buzzerTimer = 0;

void setup() {
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  lcd.begin();
  lcd.backlight();
  gsm.begin(9600);
  digitalWrite(GREEN_LED_PIN, HIGH);
}

void loop() {
  int mq135Value = analogRead(MQ135_PIN);
  lcd.setCursor(0, 0);
  if (mq135Value > threshold) {
    lcd.print("Gas Detected");
    digitalWrite(GREEN_LED_PIN, LOW);
    startBlinkingRedLed();
    startBuzzer();
    sendAlert();
  } else {
    lcd.print("No Gas Detected");
    digitalWrite(GREEN_LED_PIN, HIGH);
    digitalWrite(RED_LED_PIN, LOW);
    noTone(BUZZER_PIN);
  }
  lcd.setCursor(0, 1);
  lcd.print("AQI: ");
  lcd.print(mq135Value);
  handleLedBlinking();
  handleBuzzer();
  delay(1000);
}

void startBlinkingRedLed() {
  ledBlinkTimer = millis();
}

void handleLedBlinking() {
  if (millis() - ledBlinkTimer >= 500) {
    digitalWrite(RED_LED_PIN, !digitalRead(RED_LED_PIN));
    ledBlinkTimer = millis();
  }
}

void startBuzzer() {
  buzzerTimer = millis();
  tone(BUZZER_PIN, 325);
}

void handleBuzzer() {
  if (millis() - buzzerTimer >= 5000) {
    noTone(BUZZER_PIN);
  }
}

void sendAlert() {
  sendSms();
  makeCall();
}

void sendSms() {
  unsigned long currentTime = millis();
  if (currentTime - lastSmsTime >= smsInterval) {
    gsm.print("AT+CMGF=1\r");
    delay(100);
    gsm.print("AT+CMGS=\"+918446656933\"\r");
    delay(100);
    gsm.print("Gas leakage detected");
    delay(100);
    gsm.write(26);
    lastSmsTime = currentTime;
  }
}

void makeCall() {
  unsigned long currentTime = millis();
  if (currentTime - lastCallTime >= callInterval) {
    gsm.print("ATD+918446656933;\r");
    delay(30000);
    gsm.print("ATH\r");
    lastCallTime = currentTime;
  }
}

This code is responsible for reading the MQ135 sensor data, controlling the LEDs and buzzer based on the gas levels, and using the SIM800L module to send SMS and make calls in case of high gas levels detected. The LCD displays the current air quality index (AQI) and alerts.