

This circuit is designed to monitor various environmental parameters including water level, gas presence, distance measurement, and vibration detection. It utilizes an Arduino UNO as the central microcontroller to process inputs from a water level sensor, an MQ-2 gas sensor, an HC-SR04 ultrasonic sensor, and an SW-420 vibration sensor. The circuit provides visual feedback through an LCD Display and audible alerts using a buzzer. The Arduino UNO is also responsible for controlling the power flow to the sensors and the buzzer based on the sensor readings.
5V and GND pins provide power to all sensors and the LCD displayA0 pin connected to the Water Level Sensor signal outputA1 pin connected to the MQ-2 Gas Sensor analog outputD8 pin controls the buzzerD9 pin connected to the HC-SR04 Ultrasonic Sensor trigger inputD10 pin connected to the HC-SR04 Ultrasonic Sensor echo outputD11 pin connected to the SW-420 Vibration Sensor digital outputA4 (SDA) and A5 (SCL) pins connected to the LCD Display I2C interfaceSIG pin connected to Arduino UNO A0VCC and GND pins connected to Arduino UNO 5V and GNDDigital output pin connected to Arduino UNO D11vcc and Ground pins connected to Arduino UNO 5V and GNDTRIG pin connected to Arduino UNO D9ECHO pin connected to Arduino UNO D10VCC and GND pins connected to Arduino UNO 5V and GNDA0 pin connected to Arduino UNO A1VCC and GND pins connected to Arduino UNO 5V and GNDPIN connected to Arduino UNO D8GND connected to Arduino UNO GNDSDA and SCL pins connected to Arduino UNO A4 and A5VCC and GND pins connected to Arduino UNO 5V and GND#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD (address 0x27, 16 columns, 2 rows)
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int waterLevelPin = A0; // Water level sensor
const int trigPin = 9; // HC-SR04 Trig pin
const int echoPin = 10; // HC-SR04 Echo pin
const int gasSensorPin = A1; // Gas sensor
const int vibrationSensorPin = 11; // Vibration sensor
const int buzzerPin = 8; // Buzzer
// Thresholds
const int waterLevelThreshold = 700; // Example threshold for water level
const long distanceThreshold = 20; // Example threshold for distance in cm
const int gasThreshold = 400; // Example threshold for gas level
void setup() {
Serial.begin(9600);
// Initialize the LCD
lcd.begin(16,2);
lcd.backlight();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(vibrationSensorPin, INPUT);
pinMode(buzzerPin, OUTPUT);
// Start buzzer off
digitalWrite(buzzerPin, LOW);
}
void loop() {
// Read water level
int waterLevelValue = analogRead(waterLevelPin);
// Read distance
long distance = getDistance();
// Read gas level
int gasLevelValue = analogRead(gasSensorPin);
// Read vibration sensor
int vibrationState = digitalRead(vibrationSensorPin);
// Clear the LCD
lcd.clear();
// Display readings
lcd.setCursor(0, 0);
lcd.print("WL:");
lcd.print(waterLevelValue);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("Dist:");
lcd.print(distance);
lcd.print("cm");
// Check water level
if (waterLevelValue > waterLevelThreshold) {
Serial.println("Water level too high!");
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
lcd.setCursor(10, 0);
lcd.print("!High WL");
}
// Check distance
if (distance < distanceThreshold) {
Serial.println("Object too close!");
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
lcd.setCursor(10, 1);
lcd.print("!Close");
}
// Check gas level
if (gasLevelValue > gasThreshold) {
Serial.println("Gas level too high!");
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
lcd.setCursor(10, 0);
lcd.print("!High Gas");
}
// Check vibration
if (vibrationState == HIGH) {
Serial.println("Vibration detected!");
digitalWrite(buzzerPin, HIGH); // Turn on buzzer
lcd.setCursor(10, 1);
lcd.print("!Vib Det");
}
// Delay for stability
delay(500);
// Turn off buzzer if no alerts
if (waterLevelValue <= waterLevelThreshold && distance >= distanceThreshold && gasLevelValue <= gasThreshold && vibrationState == LOW) {
digitalWrite(buzzerPin, LOW);
}
}
// Function to get distance from the ultrasonic sensor
long getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
return duration * 0.034 / 2; // Convert to cm
}
This code is responsible for initializing the sensors and the LCD display, reading sensor data, and providing feedback based on predefined thresholds. It includes functions for reading the water level, gas concentration, distance, and vibration state, and it activates the buzzer and updates the LCD display if any readings exceed the set thresholds.