SM Home
SM Home
+-------------------+
| 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
+------------------+ +------------------+
+------------------+ +------------------+
Architecture Explanation
Sensors:
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.
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.
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>
BH1750 lightMeter;
void setup() {
Serial.begin(115200);
dht.begin();
Wire.begin();
lightMeter.begin();
pinMode(PIRPIN, INPUT);
pinMode(DOORPIN, INPUT);
}
void loop() {
// Read Door Sensor (Magnetic Reed Switch) (LOW means door is open)
if (isnan(temp) || isnan(humidity)) {
} else {
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print(" °C ");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.println(lightLevel);
if (motionDetected == HIGH) {
Serial.println("Motion Detected!");
} else {
Serial.println("No Motion.");
if (doorStatus == LOW) {
Serial.println("Door Opened!");
} else {
Serial.println("Door Closed.");
}
// Wait for 2 seconds before next reading
delay(2000);
Initialize System:
Initialize all the sensors (DHT, LDR, PIR, and door sensor).
Continuously read the data from the sensors (every 2 seconds in this case).
If light level is below a certain threshold (e.g., light < 200), turn on lights.
If the door is open, send a notification (to alert that the door is open).
Display real-time data from sensors (Temperature, Humidity, Light, Motion, Door)
in the Serial Monitor or on a Mobile/Web Interface.
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.
Loop:
After every reading, decisions are made and the system is updated accordingly.