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

Arduino UNO Based Methane Gas Detector with LCD Alert and UV Sanitization Control

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Methane Gas Detector with LCD Alert and UV Sanitization Control

Circuit Documentation

Summary

This circuit is designed to monitor methane gas levels using MQ-4 and MQ-9 sensors. It features an Arduino UNO microcontroller, a piezo buzzer for alarms, a blue LED for indication, two pushbuttons for user interaction, and a 16x2 LCD for displaying messages. The circuit is powered by a 9V battery and includes a resistor for current limiting to the LED. The purpose of the circuit is to detect spoiled food by sensing gas levels and to provide a user interface for activating a UV LED and displaying gas levels.

Component List

Piezo Buzzer

LED: Two Pin (blue)

Pushbutton

MQ-4 Gas Sensor

MQ-9 Gas Sensor

Arduino UNO

16X2 LCD

9V Battery

Resistor

Wiring Details

Piezo Buzzer

LED: Two Pin (blue)

Pushbutton (Button1)

Pushbutton (Button2)

MQ-4 Gas Sensor

MQ-9 Gas Sensor

Arduino UNO

16X2 LCD

9V Battery

Resistor (220 Ohms)

Documented Code

Arduino UNO Code (sketch.ino)

#include <LiquidCrystal.h>

/*
 * This Arduino sketch monitors methane gas levels using MQ-4 and MQ-9 sensors.
 * If gas levels exceed a threshold, a buzzer alarms and the LCD displays
 * "Spoiled Food". Two buttons are used: one to activate a UV LED for 10
 * seconds to sanitize the food, and another to display gas levels on the LCD.
 * The LCD initially displays "SAFE" when either button is pressed.
 */

// Pin definitions
const int MQ4_Pin = A0;
const int MQ9_Pin = A1;
const int Buzzer_Pin = 8;
const int UVLED_Pin = 9;
const int Button1_Pin = 10;
const int Button2_Pin = 11;
const int threshold = 300; // Example threshold value

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  // Initialize the LCD and print "SAFE"
  lcd.begin(16, 2);
  lcd.print("SAFE");

  // Set pin modes
  pinMode(MQ4_Pin, INPUT);
  pinMode(MQ9_Pin, INPUT);
  pinMode(Buzzer_Pin, OUTPUT);
  pinMode(UVLED_Pin, OUTPUT);
  pinMode(Button1_Pin, INPUT_PULLUP);
  pinMode(Button2_Pin, INPUT_PULLUP);
}

void loop() {
  // Read gas levels
  int gasLevel_MQ4 = analogRead(MQ4_Pin);
  int gasLevel_MQ9 = analogRead(MQ9_Pin);

  // Check for spoiled food
  if (gasLevel_MQ4 > threshold || gasLevel_MQ9 > threshold) {
    digitalWrite(Buzzer_Pin, HIGH);
    lcd.clear();
    lcd.print("Spoiled Food");
  } else {
    digitalWrite(Buzzer_Pin, LOW);
  }

  // Check if Button1 is pressed for UV LED
  if (digitalRead(Button1_Pin) == LOW) {
    lcd.clear();
    lcd.print("SAFE");
    delay(2000);
    lcd.clear();
    lcd.print("Sanitizing...");
    digitalWrite(UVLED_Pin, HIGH);
    delay(10000);  // UV LED on for 10 seconds
    digitalWrite(UVLED_Pin, LOW);
    lcd.clear();
  }

  // Check if Button2 is pressed for gas level display
  if (digitalRead(Button2_Pin) == LOW) {
    lcd.clear();
    lcd.print("SAFE");
    delay(2000);
    lcd.clear();
    lcd.print("Gas Level:");
    lcd.setCursor(0, 1);
    lcd.print("MQ4: ");
    lcd.print(gasLevel_MQ4);
    lcd.print(" MQ9: ");
    lcd.print(gasLevel_MQ9);

    if (gasLevel_MQ4 <= threshold && gasLevel_MQ9 <= threshold) {
      lcd.setCursor(0, 1);
      lcd.print("Food appears to be fresh");
    }
    delay(5000);  // Display the gas levels for 5 seconds
    lcd.clear();
  }
}

16X2 LCD Code (sketch.ino)

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Note: The code for the 16X2 LCD is minimal and does not include any specific functionality. It is likely that the LCD is controlled entirely by the Arduino UNO.

Additional Documentation (documentation.txt)

No additional documentation provided.