Arduino UNO Based Multi-Sensor Monitoring System with LCD Feedback and Alert Buzzer
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
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.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- Provides digital and analog I/O pins
- Powers the sensors and reads their outputs
- Drives the LCD display and buzzer
Water Level Sensor
- Detects the level of water
- Outputs an analog signal corresponding to the water level
SW-420 Vibration Sensor
- Detects vibrations and movements
- Outputs a digital signal when vibration is detected
HC-SR04 Ultrasonic Sensor
- Measures distance by emitting ultrasonic waves
- Outputs a pulse width corresponding to the reflection time
MQ-2 Gas Sensor
- Detects various gases including LPG, smoke, and alcohol
- Outputs both analog and digital signals based on gas concentration
Buzzer
- Emits an audible alert when activated
- Controlled by a digital output from the Arduino UNO
LCD Display 16x4 I2C
- Displays text information
- Uses I2C communication for interfacing with the Arduino UNO
Wiring Details
Arduino UNO
5VandGNDpins provide power to all sensors and the LCD displayA0pin connected to the Water Level Sensor signal outputA1pin connected to the MQ-2 Gas Sensor analog outputD8pin controls the buzzerD9pin connected to the HC-SR04 Ultrasonic Sensor trigger inputD10pin connected to the HC-SR04 Ultrasonic Sensor echo outputD11pin connected to the SW-420 Vibration Sensor digital outputA4(SDA) andA5(SCL) pins connected to the LCD Display I2C interface
Water Level Sensor
SIGpin connected to Arduino UNOA0VCCandGNDpins connected to Arduino UNO5VandGND
SW-420 Vibration Sensor
Digital outputpin connected to Arduino UNOD11vccandGroundpins connected to Arduino UNO5VandGND
HC-SR04 Ultrasonic Sensor
TRIGpin connected to Arduino UNOD9ECHOpin connected to Arduino UNOD10VCCandGNDpins connected to Arduino UNO5VandGND
MQ-2 Gas Sensor
A0pin connected to Arduino UNOA1VCCandGNDpins connected to Arduino UNO5VandGND
Buzzer
PINconnected to Arduino UNOD8GNDconnected to Arduino UNOGND
LCD Display 16x4 I2C
SDAandSCLpins connected to Arduino UNOA4andA5VCCandGNDpins connected to Arduino UNO5VandGND
Documented Code
#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.