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

Arduino Nano Controlled Gas Detection System with Servo Actuator and LCD Alert Display

View and Edit Project In Cirkit DesignerImage of Arduino Nano Controlled Gas Detection System with Servo Actuator and LCD Alert Display

Circuit Documentation

Summary

The circuit is designed to monitor gas levels using an MQ135 gas sensor and display the readings on an LCD display. If the gas level exceeds a certain threshold, a piezo buzzer is activated, and a servo motor is moved to a specific position as an alert mechanism. The system is controlled by an Arduino Nano microcontroller, which also manages the I2C communication with the LCD display. A TP4056 module is used for battery management, and a 5V battery provides the power supply.

Component List

Arduino Nano

Servo

MQ135 Gas Sensor

Piezo Buzzer

LED: Two Pin (red)

LCD Display 16x4 I2C

TP4056

5v Battery

Wiring Details

Arduino Nano

Servo

MQ135 Gas Sensor

Piezo Buzzer

LED: Two Pin (red)

LCD Display 16x4 I2C

TP4056

5v Battery

Documented Code

#include <Servo.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);
const int gasSensorPin = A0;  // Analog pin connected to the MQ2 gas sensor
const int buzzer = 4;         // Digital pin connected to the buzzer
const int servoPin = 9;       // Digital pin connected to the servo
const int gasThreshold = 400; // Threshold value for gas detection (adjust based on your testing)

Servo myServo;  // Create servo object to control a servo
bool servoMoved = false; // Flag to check if the servo has already moved

void setup() {
  pinMode(gasSensorPin, INPUT);
  pinMode(buzzer, OUTPUT);
  myServo.attach(servoPin);
  myServo.write(0); // Initial position of the servo
  Serial.begin(9600); // Initialize serial communication for debugging
}

void loop() {
  int analogSensor = analogRead(gasSensorPin);
  int gasvalue = (analogSensor - 50) / 35;  // Gas module sensitivity
  
  lcd.setCursor(0,0);
  lcd.print("GAS Level:");
  lcd.setCursor(10,0);
  lcd.print(gasvalue);
  lcd.setCursor(12,0);
  lcd.print("%");
  
  // Checks if it has reached the threshold value
  if (gasvalue > gasThreshold && !servoMoved) { // Gas percentage alert
    digitalWrite(buzzer, HIGH); // Turn on the buzzer
    delay(2000); // Beep for 2 seconds
    digitalWrite(buzzer, LOW); // Turn off the buzzer

    myServo.write(75); // Rotate the servo to 90 degrees
    servoMoved = true; // Set the flag to indicate the servo has moved
    lcd.setCursor(0,1);
    lcd.print("DANGER");
    lcd.setCursor(1,1);
    lcd.print("auto reg off");
    tone(buzzer, 1000, 10000);
  } else {
    lcd.setCursor(0,1);
    lcd.print("NORMAL");
    noTone(buzzer);
  }
  delay(1000);
  lcd.clear(); 
}

This code is responsible for reading the gas level from the MQ135 sensor, displaying the value on the LCD, and triggering the buzzer and servo motor when the gas level exceeds the threshold. The LCD displays the current gas level percentage and shows a "DANGER" message along with turning off the regulator when the threshold is crossed. The servo moves to a 75-degree position as part of the alert mechanism.