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

Arduino Uno R3 Based Gas Leak Detector with SMS Alert and Weight Monitoring

View and Edit Project In Cirkit DesignerImage of Arduino Uno R3 Based Gas Leak Detector with SMS Alert and Weight Monitoring

Circuit Documentation

Summary

The circuit is designed to monitor gas leakage and weight, providing visual and auditory alerts, and the ability to communicate alerts via SMS and phone calls. It includes sensors for gas detection and weight measurement, indicators in the form of LEDs and a buzzer, an LCD display for status messages, and a communication module for sending SMS and making calls. The Arduino Uno R3 serves as the central microcontroller, interfacing with the various components and executing the embedded code to control the circuit's behavior.

Component List

Wiring Details

LED (Green)

LED (Red)

MQ6 Gas Sensor

Elegoo Passive Buzzer

Resistor (200 Ohms)

LCD I2C Display

Adafruit FONA 3G Breakout

Arduino Uno R3

HX711 - Bridge Sensor Interface

DC Power Source

Documented Code

#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
#include "HX711.h"
#include <LiquidCrystal_I2C.h>
#include <AsyncDelay.h>

// fona pins
#define FONA_TX 2
#define FONA_RX 3
#define FONA_RST 4
#define FONA_POWER 8
// board pins
#define BUZZER_PIN 11
#define RED_LED_PIN 10
#define GREEN_LED_PIN A0 // act as a digital pin
#define GAS_THRESHOLD 30 // Threshold for gas level in percentage
#define MQ6_PIN 5 // gas sensor pin

AsyncDelay sendsmsdelay;
HX711 scale;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Address 0x27, 16 column and 2 rows
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);

bool gasLeakageDetected = false;
bool gasBelowThreshold = false;
bool lowWeight=false;

void setup() 
{  
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(MQ6_PIN, INPUT); // Set MQ6_PIN as input
  pinMode(FONA_POWER, OUTPUT);
  digitalWrite(FONA_POWER, HIGH);
  delay(180);
  digitalWrite(FONA_POWER, LOW);
  delay(3000);
  
  Serial.begin(4800);
  Serial.println(F("Initializing FONA..."));

  fonaSerial->begin(4800);
  if (!fona.begin(*fonaSerial))
  {
    Serial.println(F("Couldn't find FONA"));
    while(1);
  }
  Serial.println(F("FONA is OK"));
  
  scale.begin(6, 7); // DT, SCK pins for HX711
  // Wait for the scale to stabilize
  delay(1000);
  scale.set_scale(-211.23);  // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();               // reset the scale to 0
  
  lcd.init();
  lcd.backlight();
  lcd.setCursor(2, 0);

  sendsmsdelay.start(60000,AsyncDelay::MILLIS);

}

void loop() 
{
  // Your main code logic here
   // Read gas weight and detect gas leakage
  int gasWeight = scale.get_units(5); // Read load cell
  Serial.print("Weight: "); Serial.println(gasWeight);
  gasLeakageDetected = digitalRead(MQ6_PIN) == LOW; // Gas leakage detected if MQ6_PIN is LOW

  Serial.print("Gas leak: "); Serial.println(gasLeakageDetected);
  
  // Case 1: No gas leakage and weight above threshold
  if (!gasLeakageDetected && gasWeight > GAS_THRESHOLD) {
    lcd.clear();
    lcd.print("YOU ARE SAFE");
    digitalWrite(RED_LED_PIN, LOW);  // Turn off red LED
    digitalWrite(GREEN_LED_PIN, HIGH);  // Turn on green LED
    noTone(BUZZER_PIN);  // Stop buzzer
  }
  // Case 2: Weight above threshold and gas leakage detected
  else if (gasWeight > GAS_THRESHOLD && gasLeakageDetected) {
    lcd.clear();
    lcd.print(" GAS LEAKING!!! ");
    digitalWrite(RED_LED_PIN, HIGH);  // Turn on red LED
    digitalWrite(GREEN_LED_PIN, LOW);  // Turn off green LED
    tone(BUZZER_PIN, 1000);  // Ring buzzer
    sndSMS("ALERT! GAS LEAK DETECTED. PLEASE CLOSE THE GAS VALVE IMMEDIATELY.");
    makeCall();
  }

  // Case 3: Weight below threshold and gas leakage detected
  else if (gasWeight <= GAS_THRESHOLD && gasLeakageDetected) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" GAS LEAKING!!! ");
    lcd.setCursor(0, 1);
    lcd.print("GAS BELOW 30%");
    digitalWrite(RED_LED_PIN, HIGH);  // Turn on red LED
    digitalWrite(GREEN_LED_PIN, LOW);  // Turn off green LED
    tone(BUZZER_PIN, 1000);  // Ring buzzer
    sndSMS("CRITICAL ALERT! GAS LEAK DETECTED AND GAS LEVEL BELOW 30%. CLOSE THE GAS VALVE AND BUDGET FOR A REFILL.");
    // sndSMS("GAS BELOW 30%, REFILL GAS");
    makeCall();
  }

  // Case 4: No gas leakage but weight below threshold
  else if (!gasLeakageDetected && gasWeight <= GAS_THRESHOLD) {
    lcd.clear();