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.
GND
connected to the ground net, which includes the Servo (gnd), MQ135 (GND), Piezo Buzzer (pin 2), LED (cathode), LCD Display (GND), and TP4056 (OUT-).D4
connected to the anode of the LED and pin 1 of the Piezo Buzzer.D9
connected to the pulse pin of the Servo.5V
connected to the power net, which includes the VCC of the Servo, MQ135 (VCC), and LCD Display (VCC).A5
connected to the SCL pin of the LCD Display.A4
connected to the SDA pin of the LCD Display.A0
connected to the A0 pin of the MQ135 Gas Sensor.gnd
connected to the ground net.vcc
connected to the power net.pulse
connected to D9
on the Arduino Nano.GND
connected to the ground net.VCC
connected to the power net.A0
connected to A0
on the Arduino Nano.pin 1
connected to D4
on the Arduino Nano.pin 2
connected to the ground net.cathode
connected to the ground net.anode
connected to D4
on the Arduino Nano.GND
connected to the ground net.VCC
connected to the power net.SCL
connected to A5
on the Arduino Nano.SDA
connected to A4
on the Arduino Nano.OUT-
connected to the ground net.OUT+
connected to the power net.B-
connected to the negative pin of the 5v Battery.B+
connected to the positive pin of the 5v Battery.negative
connected to B-
on the TP4056.positive
connected to B+
on the TP4056.#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.