Arduino UNO Based Multi-Sensor Safety System with Servo Control and LCD Feedback
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
The circuit is designed to monitor environmental conditions and detect events such as fire, gas leaks, water levels, and motion. It utilizes an Arduino UNO as the central microcontroller to process inputs from various sensors and actuates a servo and buzzer based on specific conditions. The circuit includes a flame sensor, gas sensor, water level sensor, PIR motion sensor, an I2C LCD screen for display, a buzzer for audible alerts, and a servo motor for physical responses.
Component List
KY-026 Flame Sensor
- A sensor that detects fire or flame presence.
- Pins: A0, GND, VCC, D0
MQ-4 Gas Sensor
- A sensor that detects the presence of methane (CH4) gas.
- Pins: A0, D0, GND, VCC
Water Level Sensor
- A sensor that measures the level of water.
- Pins: SIG, VCC, GND
Arduino UNO
- A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13
PIR Motion Sensor (Wokwi Compatible)
- A sensor that detects motion via infrared signals.
- Pins: VCC, OUT, GND
I2C LCD 16x2 Screen
- A liquid crystal display that can show 16 characters on 2 lines.
- Pins: SCL, SDA, VCC (5V), GND, VDD, VO, RS, RW, E, D0-D7, BLA, BLK
Buzzer
- An electronic component that produces sound.
- Pins: PIN, GND
Servo
- A rotary actuator that allows for precise control of angular position.
- Pins: GND, VCC, PWM
Wiring Details
KY-026 Flame Sensor
- A0 connected to Arduino A0
- GND connected to common ground
- VCC connected to Arduino 5V
MQ-4 Gas Sensor
- A0 connected to Arduino A1
- GND connected to common ground
- VCC connected to Arduino 5V
Water Level Sensor
- SIG connected to Arduino A2
- GND connected to common ground
- VCC connected to Arduino 5V
PIR Motion Sensor (Wokwi Compatible)
- OUT connected to Arduino D2
- GND connected to common ground
- VCC connected to Arduino 5V
I2C LCD 16x2 Screen
- SDA connected to Arduino A4
- SCL connected to Arduino A5
- VCC (5V) connected to Arduino 5V
- GND connected to common ground
Buzzer
- PIN connected to Arduino D10
- GND connected to common ground
Servo
- PWM connected to Arduino D9
- GND connected to common ground
- VCC connected to Arduino 5V
Documented Code
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#define FIRE_SENSOR_PIN A0
#define GAS_SENSOR_PIN A1
#define PIR_SENSOR_PIN 2
#define WATER_LEVEL_PIN A2
#define BUZZER_PIN 10
#define SERVO_PIN 9
Servo myServo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(FIRE_SENSOR_PIN, INPUT);
pinMode(GAS_SENSOR_PIN, INPUT);
pinMode(PIR_SENSOR_PIN, INPUT);
pinMode(WATER_LEVEL_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
lcd.begin();
lcd.backlight();
myServo.attach(SERVO_PIN);
myServo.write(0); // Initial position
Serial.begin(9600);
}
void loop() {
int fireValue = analogRead(FIRE_SENSOR_PIN);
int gasValue = analogRead(GAS_SENSOR_PIN);
int pirValue = digitalRead(PIR_SENSOR_PIN);
int waterLevel = analogRead(WATER_LEVEL_PIN);
lcd.clear();
// Fire Detection
if (fireValue > 400) { // Adjust threshold as needed
lcd.setCursor(0, 0);
lcd.print("Fire Alert!");
digitalWrite(BUZZER_PIN, HIGH);
myServo.write(90); // Servo action, e.g., close door
} else {
digitalWrite(BUZZER_PIN, LOW);
myServo.write(0); // Default position
}
// Gas Detection
if (gasValue > 300) { // Adjust threshold as needed
lcd.setCursor(0, 1);
lcd.print("Gas Leak!");
digitalWrite(BUZZER_PIN, HIGH);
}
// Motion Detection
if (pirValue == HIGH) {
lcd.setCursor(0, 0);
lcd.print("Intruder Detected");
digitalWrite(BUZZER_PIN, HIGH);
}
// Water Level Detection
if (waterLevel < 200) { // Adjust threshold for water level
lcd.setCursor(0, 1);
lcd.print("Flood Risk!");
digitalWrite(BUZZER_PIN, HIGH);
}
delay(1000); // Adjust delay as per requirements
}
This code is designed to run on the Arduino UNO microcontroller. It initializes the sensors and the LCD screen in the setup() function and continuously monitors the sensors in the loop() function. When a sensor detects a condition above a predefined threshold, it triggers an alert on the LCD screen and activates the buzzer. The servo motor is also actuated in case of fire detection.