Smart Home with Arduino

 

Introduction

Automated Home Safety and Parking System Using Arduino – Smart Gas Leak Detection & Parking Automation

Enhance home safety and automation with an Arduino-based Automated Home Safety and Parking System that integrates gas leak detection, real-time temperature and humidity monitoring, and automatic parking assistance. This smart home automation project utilizes MQ gas sensors for instant gas leak detection, DHT11 sensors for environmental monitoring, and an RTC module for accurate time tracking. The system features an automatic parking gate, which operates via IR sensors, detecting vehicles and controlling servo motors for a seamless hands-free parking experience. Real-time updates, including gas alerts, temperature, humidity levels, and parking status, are displayed on an LCD screen. Ideal for IoT and smart home security, this Arduino safety system ensures home efficiency, real-time hazard prevention, and parking automation, with potential enhancements like buzzer alerts, Wi-Fi connectivity, and battery backup for uninterrupted operation.How This System Works

The project is designed to provide two major functionalities:

  1. Home Safety Automation – Detects gas leaks in different rooms and automatically triggers a water sprinkler system.
  2. Parking Assistance – Automatically detects vehicles and opens/closes the parking gate accordingly.

All actions are displayed on an LCD screen, ensuring that users can monitor system updates in real time.


Key Components and Their Roles


Pin connections of the Arduino


To achieve this automation, the system incorporates several key components. Below is an overview of their functionalities:

1. LCD Display (16x2)

  • Displays real-time environmental data (temperature, humidity, and time).
  • Provides parking status updates (whether a parking spot is occupied or free).
  • Shows alerts for gas leaks in Room 1 or Room 2.

2. Servo Motors

  • Gate Servo (A2): Controls the parking gate, opening it when a car is detected.
  • Gas Servo 1 (A3) & Gas Servo 2 (A1): Activate water sprinklers in case of a gas leak.

3. Gas Leak Detection (MQ Gas Sensors)

  • Room 1 (Interrupt-Based on PIN 3)
    • Uses an interrupt mechanism to detect gas leaks instantly.
    • Triggers an emergency response if a gas leak is detected.
  • Room 2 (Polled on PIN 4)
    • The sensor is continuously checked in the loop.
    • If a leak is detected, the system responds accordingly.
  • Response Mechanism
    • When gas is detected in any room, the system:
      • Displays a gas leak alert on the LCD screen.
      • Triggers the water sprinklers to minimize hazards.

4. IR Sensor for Parking Spot Detection

  • Pin 2: Detects if a car is present.
  • If a car is detected:
    • The gate servo opens the parking gate.
    • After a short delay, it closes automatically.

5. DHT11 Temperature and Humidity Sensor

  • Measures environmental temperature and humidity.
  • Displays data on the LCD screen.
  • If the humidity sensor malfunctions, it reports "Err" to notify the user.

6. RTC (Real-Time Clock - DS3231)

  • Keeps track of real-time updates.
  • If power is lost, it resets to the compilation time.

Automated Home Safety and Parking System Using Arduino



System Workflow

Setup Phase

During system initialization, the Arduino performs the following tasks:

  • Initializes the LCD, sensors, servos, RTC, and interrupt handlers.
  • Displays “RTC Error!” if the clock module is not detected.

Loop Phase (Continuous Monitoring & Response)

This phase consists of continuous monitoring and real-time responses:

1. Environmental Monitoring

  • Reads temperature and humidity from the DHT11 sensor.
  • Fetches the current time from the RTC module.

2. Gas Leak Detection

  • Room 1 (Interrupt-based detection) – Ensures instant response to gas leaks.
  • Room 2 (Polling-based detection) – Constantly checks for a gas leak within the loop.

When a gas leak is detected:

  • Displays "GasLeakRoomX" on the LCD.
  • Triggers and deactivates water sprinklers twice to reduce risks.

3. Parking Automation

  • The IR sensor (PIN 2) detects vehicles:
    • Opens the gate when a car is detected.
    • Closes automatically after a brief delay.

4. Real-Time Display Updates

The LCD provides real-time information, including:

  • Parking Status – "X" for occupied, "Y" for free.
  • Temperature (°C) and Humidity (%).
  • Time in HH:MM format.

#include <Wire.h>
#include <LiquidCrystal.h>
#include <Servo.h>
#include <DHT.h>
#include <RTClib.h> // RTC library
// LCD pins
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
// Servo motors
Servo gateServo; // Gate motor (A4)
Servo gasServo1; // Gas sensor motor for Room 1 (A3)
Servo gasServo2; // Gas sensor motor for Room 2 (A1)
// DHT11 setup (for humidity)
#define DHT_PIN A0
#define DHT_TYPE DHT11
DHT dht(DHT_PIN, DHT_TYPE);
// RTC setup
RTC_DS3231 rtc;
// Sensor pins
#define GAS_SENSOR_PIN1 3 // Pin for gas detection Room 1
#define GAS_SENSOR_PIN2 4 // Pin for gas detection Room 2
#define IR_SENSOR_PIN 2 // Pin for parking spot (IR sensor)
// Flags for interrupt handling
volatile bool gasDetectedRoom1 = false;
volatile bool gasDetectedRoom2 = false;
void setup() {
// LCD setup
lcd.begin(16, 2);
lcd.clear();
// Servo motors setup
gateServo.attach(A2);
gasServo1.attach(A3);
gasServo2.attach(A1);
gateServo.write(0); // Initialize gate servo closed
gasServo1.write(0); // Initialize gas servo idle for Room 1
gasServo2.write(0); // Initialize gas servo idle for Room 2
// DHT11 setup
dht.begin();
// RTC setup
if (!rtc.begin()) {
lcd.setCursor(0, 0);
lcd.print("RTC Error!");
while (1); // Halt if RTC initialization fails
}
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set RTC to compile time
}
// Interrupt setup
pinMode(GAS_SENSOR_PIN1, INPUT_PULLUP);
pinMode(GAS_SENSOR_PIN2, INPUT);
pinMode(IR_SENSOR_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(GAS_SENSOR_PIN1), handleGasDetectionRoom1, RISING);
Serial.begin(9600);
}
void loop() {
// Read temperature and humidity
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Get current time
DateTime now = rtc.now();
int hour = now.hour();
int minute = now.minute();
// Handle gas detection for Room 1
if (gasDetectedRoom1) {
gasDetectedRoom1 = false; // Reset flag
for (int i = 0; i < 2; i++) {
lcd.setCursor(0, 0);
lcd.print("GasLeakRoom1");
gasServo1.write(180); // Activate water sprinkler
delay(500);
gasServo1.write(0); // Deactivate water sprinkler
delay(500);
}
}
// Handle gas detection for Room 2
if (digitalRead(GAS_SENSOR_PIN2) == HIGH) {
for (int i = 0; i < 2; i++) {
lcd.setCursor(0, 0);
lcd.print("GasLeakRoom2");
gasServo2.write(180); // Activate water sprinkler
delay(500);
gasServo2.write(0); // Deactivate water sprinkler
delay(500);
}
}
// Handle car detection
if (digitalRead(IR_SENSOR_PIN) == HIGH) {
gateServo.write(90); // Open gate
delay(500); // Keep gate open for 5 seconds
gateServo.write(0); // Close gate
}
// Display parking and environmental data
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("P:");
lcd.print(digitalRead(IR_SENSOR_PIN) == HIGH ? "X" : "Y"); // Parking spot status
lcd.print(" T:");
lcd.print(temperature, 1); // Temperature
lcd.setCursor(0, 1);
lcd.print("H:");
lcd.print(isnan(humidity) ? "Err" : String(humidity, 1)); // Humidity
lcd.print("%");
// Display time on the right side of the first row
lcd.setCursor(11, 0);
lcd.print(hour < 10 ? "0" : ""); // Add leading zero if needed
lcd.print(hour);
lcd.print(":");
lcd.print(minute < 10 ? "0" : ""); // Add leading zero if needed
lcd.print(minute);
delay(1000); // Refresh display every second
}
// ISR for gas detection in Room 1
void handleGasDetectionRoom1() {
gasDetectedRoom1 = true;
}
Key Features & Benefits

✅ Automatic Gas Leak Detection & Response

  • Uses interrupts for instant gas detection.
  • Water sprinklers are activated automatically to control gas leaks.

✅ Automated Parking Gate

  • Uses an IR sensor to detect vehicle presence.
  • Servo motor automatically opens/closes the gate, ensuring a hands-free experience.

✅ Real-Time Environmental Monitoring

  • Monitors temperature and humidity levels.
  • Provides real-time data on the LCD display.

✅ Real-Time Clock (RTC) Integration

  • Tracks the current time accurately.
  • Resets automatically if power is lost.

✅ User-Friendly LCD Display

  • Provides instant updates about gas leaks, temperature, humidity, and parking status.

Possible Enhancements

While this project is already efficient, additional features can improve its performance:

  • 🔔 Buzzer Alarm for Gas Leaks – Adds an audio alert for better emergency response.
  • 📱 IoT Connectivity – Integrate Wi-Fi or Bluetooth for remote monitoring.
  • 🔋 Battery Backup – Ensures functionality during power outages.

Final Thoughts

The Automated Home Safety and Parking System is a perfect example of how technology can enhance home safety and convenience. By integrating gas leak detection, parking automation, and real-time monitoring, this system ensures a secure and efficient home environment.

With potential improvements like buzzer alerts and IoT connectivity, the project can be further enhanced for better usability. Whether you’re looking to prevent hazards or automate daily tasks, this system offers an intelligent and practical solution.


Frequently Asked Questions (FAQs)

1. How does the system detect gas leaks?

The system uses MQ gas sensors in two rooms. Room 1 uses an interrupt-based detection method, while Room 2 continuously checks for leaks through polling.

2. Can I manually control the parking gate?

No, the parking gate operates automatically using an IR sensor. However, manual override can be added as an additional feature.

3. What happens if the power goes out?

The system resets to the compilation time after a power loss. Adding a battery backup can help maintain real-time functionality.

4. Can the system be expanded with more sensors?

Yes! Additional sensors (e.g., smoke detectors, fire alarms, or motion sensors) can be integrated for enhanced security.

5. How accurate is the temperature and humidity monitoring?

The DHT11 sensor provides reasonably accurate readings. However, for high-precision applications, a DHT22 sensor can be used instead.

Recommended
Why Buy?
The ultimate Raspberry Pi 5 starter kit—perfect for advanced DIY projects, programming, and STEM education. Includes 8GB RAM, 128GB storage, and quality components. Ideal for makers, students, and educators!
Mega Power
Why Buy?
Best value Arduino Mega compatible board for complex robotics, 3D printing, and automation projects. Massive I/O, robust ATmega2560 microcontroller, and seamless compatibility with Arduino IDE.
Sensor Kit
Why Buy?
Explore 37 different sensors and modules—ideal for learning coding, IoT, robotics, and all levels of Arduino experimentation. Includes tutorials and code samples.
Must-Have
Why Buy?
Quality jumper wires for all breadboard and prototyping needs. Durable, flexible, and color-coded—essential for every electronics toolkit.
USB to Serial
Why Buy?
Connect your microcontrollers to your computer fast! CH340 USB to Serial modules are ideal for flashing, debugging, and uploading code to Arduino, ESP32, and more.

Post a Comment

0 Comments