0% found this document useful (0 votes)
9 views10 pages

SM Home

The document outlines a smart home monitoring system that integrates various sensors, including temperature, humidity, light, motion, and door sensors, all managed by an ESP32 microcontroller. It describes the functionality of each sensor, the communication with a mobile app or cloud platform for real-time monitoring, and the logic for processing sensor data to trigger alerts and control devices. The provided code illustrates the setup and loop for reading sensor data and executing actions based on the readings.

Uploaded by

Prasanth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

SM Home

The document outlines a smart home monitoring system that integrates various sensors, including temperature, humidity, light, motion, and door sensors, all managed by an ESP32 microcontroller. It describes the functionality of each sensor, the communication with a mobile app or cloud platform for real-time monitoring, and the logic for processing sensor data to trigger alerts and control devices. The provided code illustrates the setup and loop for reading sensor data and executing actions based on the readings.

Uploaded by

Prasanth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 10

Block diagram

+-------------------+

| Temperature & |

| Humidity Sensor |

| (DHT22 / DHT11) |

+---------+---------+

+-------------------+

| Light Sensor |

| (LDR / BH1750) |

+---------+---------+

+-------------------+

| Motion Sensor |

| (PIR HC-SR501) |

+---------+---------+

|
v

+-------------------+

| Door Sensor |

| (Magnetic Switch) |

+---------+---------+

+-------------------+

| ESP32 Micro- |

| controller |

| (Wi-Fi, GPIO) |

+---------+---------+

---------------------------

| |

v v

+------------------+ +------------------+

| Mobile App / | | Cloud Platform / |

| Web Interface | | Remote Server |

| (Blynk, ThingSpeak)| | (MQTT, HTTP) |

+------------------+ +------------------+
Architecture Explanation
Sensors:

Temperature & Humidity Sensor (DHT22/DHT11) monitors the room temperature


and humidity.

Light Sensor (LDR/BH1750) measures ambient light levels.

Motion Sensor (PIR HC-SR501) detects motion in the area.

Door Sensor (Magnetic Reed Switch) detects whether a door or window is open or
closed.

ESP32 Microcontroller:

The ESP32 microcontroller reads data from the sensors through GPIO pins.

It processes the sensor data locally and communicates with a cloud platform or a
mobile app using Wi-Fi.

Mobile App / Web Interface:

You can use a mobile app (e.g., Blynk) or a web interface (e.g., ThingSpeak) to
display the sensor data (temperature, light, motion, door).

The user can monitor the data in real-time, control devices (e.g., turn on lights,
control fans), and set up automation rules.

Cloud Platform / Remote Server:


Sensor data can be sent to a cloud platform or server (e.g., ThingSpeak, MQTT, or
Firebase) for remote storage, processing, and control.

The system can be monitored from anywhere in the world via the cloud platform.

Notifications and alerts (via Pushbullet, IFTTT) can be triggered based on sensor
data (e.g., motion detection, high temperature, open door).

User Interface:

The user can interact with the system through the mobile app or web interface to
control devices, check real-time data, and receive alerts or notifications.

code

#include <DHT.h>

#include <Wire.h>

#include <BH1750.h>

#define DHTPIN 4 // Pin connected to DHT22 (Temperature & Humidity


Sensor)

#define DHTTYPE DHT22 // DHT22 sensor type

#define LDRPIN 34 // Pin connected to LDR sensor (Light)

#define PIRPIN 15 // Pin connected to PIR sensor (Motion)

#define DOORPIN 12 // Pin connected to Door Sensor (Magnetic Reed Switch)


// Create sensor objects

DHT dht(DHTPIN, DHTTYPE);

BH1750 lightMeter;

void setup() {

// Start Serial Communication

Serial.begin(115200);

// Initialize the DHT sensor

dht.begin();

// Initialize the BH1750 light sensor

Wire.begin();

lightMeter.begin();

// Initialize the sensor pins

pinMode(PIRPIN, INPUT);

pinMode(DOORPIN, INPUT);

Serial.println("Smart Home Monitoring System Initialized");

}
void loop() {

// Read Temperature and Humidity

float temp = dht.readTemperature(); // Temperature in Celsius

float humidity = dht.readHumidity(); // Humidity in percentage

// Read Light Level (LDR Sensor) - Analog Read

int lightLevel = analogRead(LDRPIN); // Range: 0-1023

// Read PIR Motion Sensor (HIGH means motion detected)

int motionDetected = digitalRead(PIRPIN);

// Read Door Sensor (Magnetic Reed Switch) (LOW means door is open)

int doorStatus = digitalRead(DOORPIN);

// If any sensor reading failed, print error

if (isnan(temp) || isnan(humidity)) {

Serial.println("Failed to read from DHT sensor!");

} else {

// Print Temperature and Humidity

Serial.print("Temperature: ");

Serial.print(temp);

Serial.print(" °C ");
Serial.print("Humidity: ");

Serial.print(humidity);

Serial.println(" %");

// Print Light Level (LDR)

Serial.print("Light Level (LDR): ");

Serial.println(lightLevel);

// Print Motion Detection Status

if (motionDetected == HIGH) {

Serial.println("Motion Detected!");

} else {

Serial.println("No Motion.");

// Print Door Status

if (doorStatus == LOW) {

Serial.println("Door Opened!");

} else {

Serial.println("Door Closed.");

}
// Wait for 2 seconds before next reading

delay(2000);

Overall System Logic

Initialize System:

Initialize all the sensors (DHT, LDR, PIR, and door sensor).

Set up communication protocols (Serial Monitor for debugging or Mobile/Web


App for real-time control).

Read Sensor Data:

Continuously read the data from the sensors (every 2 seconds in this case).

Temperature and Humidity (DHT22/DHT11).

Light level (LDR).

Motion status (PIR).

Door status (Reed switch).

Process Sensor Data:

Temperature & Humidity:

Read the temperature and humidity values.


If temperature > 30°C, trigger an alert (could turn on fan or send a notification).

If humidity > 70%, trigger an alert (could turn on dehumidifier or send a


notification).

Light Level (LDR):

If light level is below a certain threshold (e.g., light < 200), turn on lights.

If the light level is above the threshold, keep lights off.

Motion Sensor (PIR):

If motion is detected, turn on lights (or trigger an alarm).

If no motion is detected, turn off the lights after a certain timeout.

Door Sensor (Magnetic Reed Switch):

If the door is open, send a notification (to alert that the door is open).

If the door is closed, display the status.

Display Data & Actions:

Display real-time data from sensors (Temperature, Humidity, Light, Motion, Door)
in the Serial Monitor or on a Mobile/Web Interface.

Control lights/fans/other devices based on sensor input:

Example: Turn on lights when motion is detected or when it's too dark.

Example: Turn off lights when no motion is detected for a period of time.

Send Notifications (Optional):

Send a notification if:


The door is left open.

Temperature exceeds a certain threshold (e.g., > 30°C).

Motion is detected in areas where no motion should be.

Loop:

The logic repeats every 2 seconds (or another set period).

After every reading, decisions are made and the system is updated accordingly.

You might also like