By KISHOR G
I built a Smart Auto-Assist Home Safety System that simulates a real smart home using an ESP32 and an ESP32-S3-BOX3. The system automatically controls lighting and appliances based on ambient light and human motion, continuously monitors electrical energy usage, detects abnormal current faults, and predicts electricity consumption and billing using lightweight on-device analytics.
Why I made it
The goal was to address real-world problems in homes—energy wastage, lack of visibility into power consumption, and electrical safety risks—using a practical, hardware-centric IoT solution. Instead of relying on cloud-heavy AI, the project demonstrates how intelligent decision-making, safety logic, and energy awareness can be implemented directly on embedded systems powered by microcontrollers from Espressif Systems.
This makes the solution:
- Cost-effective
- Energy-efficient
- Reliable even without internet
- Suitable for real homes, hostels, and small buildings
In short, I built this project to show how embedded intelligence + automation + energy analytics can make homes safer, smarter, and more power-efficient—a strong fit for real-world deployment and hackathon innovation.
Components Required
| Component Name | Quantity | Datasheet/Link |
| esp32 s3 box3 | 1 | - |
| esp32 dev module | 1 | - |
| acs 712 current sensor | 1 | - |
| pzem-004t | 1 | - |
| 5v relay module | 4 | - |
| switches | 4 | - |
| 5A fuse | 1 | - |
| incandescent bulb | 4 | - |
| led bulb | 1 | - |
| pir motion sensor | 1 | - |
| ldr module | 1 | - |
| Buck converter | 1 | - |
| 3.7v Li ion battery cell | 2 | - |
Circuit Diagram

Hardware Assembly
1. Prepare the Workspace
- Place all components on a non-conductive surface.
- Keep breadboard, jumper wires, and power supply ready.
- Ensure AC wiring area is separate and handled carefully.
- Make sure power is OFF before starting connections.
2. Power Distribution Setup
- Use a regulated 5V power supply.
- Power ESP32 using USB cable or 5V pin.
Provide 5V supply to:
- Relay module
- PIR sensor
- ACS712
- PZEM module
- Ensure common ground connection between all modules and ESP32.
This is essential for proper sensor readings.
3. ESP32 Controller Placement
- Place ESP32 Dev Module on breadboard.
- Ensure enough space for jumper connections.
- Identify GPIO pins before wiring.
4. LDR Sensor Connection (Adaptive Lighting Control)
The LDR controls the number of bulbs based on room brightness.
Steps:
- Connect one terminal of LDR to 3.3V.
- Connect other terminal to GPIO 34.
- Add a 10k resistor between GPIO 34 and GND.
- This forms a voltage divider for analog reading.
Used for:
- Detecting day/night
- Adjusting number of bulbs automatically
5. PIR Motion Sensor Connection
Used to detect human movement.
Connections:
- VCC → 5V
- GND → GND
- OUT → GPIO 27
Mount PIR facing room area for proper detection.
6. Relay Module Connection (Bulb/Appliance Control)
Relays control bulbs to simulate home appliances.
Relay connections:
- VCC → 5V
- GND → GND
Signal pins:
- Relay 1 IN → GPIO 18
- Relay 2 IN → GPIO 19
- Relay 3 IN → GPIO 21
- Relay 4 IN → GPIO 22
Bulb Wiring
For each bulb:
- Phase wire → Relay COM
- Relay NO → Bulb phase
- Neutral → Direct to bulb
This allows ESP32 to control bulbs.
7. ACS712 Current Sensor Connection
Used for appliance current monitoring and fault detection.
Connections:
- VCC → 5V
- GND → GND
- OUT → GPIO 35 (analog)
Load wiring:
- Pass appliance phase wire through the ACS712 terminals.
- It will measure current drawn by load.
8. PZEM-004T Energy Meter Connection
Used for voltage, current, power, and energy measurement.
UART Connections to ESP32
- PZEM TX → GPIO 16
- PZEM RX → GPIO 17
- VCC → 5V
- GND → GND
AC Wiring
- Connect phase line through PZEM input.
- Connect load output from PZEM.
- Attach current transformer clamp to phase wire.
- Ensure proper insulation and safety.
9. ESP32-S3-BOX3 Setup
- Power ESP32-S3-BOX3 using USB or battery.
- Connect to same WiFi network as ESP32.
Used to display:
- Energy usage
- Fault alerts
- Predicted bill
- System status
Place it near the setup for visualization.
10. Final Wiring Check
Before powering ON:
- Verify all VCC connections
- Verify all GND common
- Check relay wiring carefully
- Ensure no loose wires
- Confirm correct GPIO connections
11. Power ON and Testing
After completing connections:
Power ON ESP32
Upload program
Open serial monitor
Test each module:
Lighting Test
Shine light on LDR → bulbs OFF
Cover LDR → bulbs ON
Motion Test
Move near PIR → appliances ON
Energy Monitoring Test
Turn ON load → energy reading increases
Fault Test
Increase load suddenly → fault detected and relay OFF
12. Safety Precautions
- Do not touch live AC wires
- Use insulated connectors
- Keep dry hands while testing
- Use low load initially
- Ensure proper earthing if using real AC
Assembly Complete
The smart home hardware system is now ready for:
- Adaptive lighting control
- Motion-based automation
- Real-time energy monitoring
- Fault detection
- Predictive energy analytics
Code Explanation
SMART AUTO-ASSIST HOME SAFETY SYSTEM
Platform: ESP32 + ESP32-S3-BOX3 Framework: ESP-IDF, FreeRTOS, LVGL Connectivity: Wi-Fi (HTTP based communication)
FOR ESP32-S3BOX:
INTRODUCTION
This project implements a Smart Auto-Assist Home Safety System using ESP32 and ESP32-S3-BOX3. The code is designed to simulate a real smart home environment with intelligent automation, electrical safety monitoring, energy analytics, and user interaction through a touch display. Unlike cloud-dependent smart home systems, all decision-making, analytics, and safety logic are executed locally on the embedded device, making the system reliable, low-latency, and energy-efficient.
SYSTEM SOFTWARE ARCHITECTURE
The software is organized into five logical layers: Networking Layer – Wi-Fi + HTTP server, Data Processing Layer – Sensor parsing & state tracking, Automation Layer – Smart presence, adaptive lighting, peak guard, Analytics Layer – Energy usage, billing, peak cost estimation, User Interface Layer – Touch-based LVGL graphical interface. Each layer operates independently but shares real-time data using global variables.
NETWORKING & COMMUNICATION
Wi-Fi Configuration: ESP32-S3-BOX3 operates in Station (STA) mode, automatically reconnects if Wi-Fi is lost, IP address is logged for debugging. HTTP Server: A lightweight HTTP server listens on /data, receives sensor data via HTTP POST in JSON format, responds with control commands (relay ON/OFF). JSON Parameters Received: Motion status (PIR), Current (ACS712), Power and Energy (PZEM-004T), Light intensity (LDR). This design allows wireless decoupling between sensor hardware and control logic.
SENSOR DATA HANDLING
Incoming JSON data is parsed using cJSON and stored in global variables: g_motion – Human presence detection, g_current – Load current, g_power – Instantaneous power, g_energy – Accumulated energy, g_ldr – Ambient light level. These values are continuously updated and used across automation, analytics, and UI modules.
SMART PRESENCE AUTOMATION (PIR-BASED)
Logic: If motion is detected, devices remain ON. If no motion is detected for 5 consecutive seconds, a confirmation popup appears on the display where user can approve or cancel shutting down devices. Features: Prevents accidental power wastage, ensures human-in-loop safety, avoids blind automatic shutdowns. This approach balances automation and user control, which is essential for real homes.
ADAPTIVE LIGHTING SYSTEM (LDR-BASED)
Core Principle: Lower LDR value indicates darker environment, higher LDR value indicates brighter environment. Automation Behavior: Very dark environment triggers all lights ON, medium light enables partial lighting, bright environment keeps only essential lighting ON. Benefits: Reduces unnecessary lighting load, adjusts dynamically to environmental conditions, improves comfort and energy efficiency.
DEVICE CONTROL SYSTEM
Three appliances are controlled via software states. Each device can be toggled manually from the UI. Commands are sent wirelessly back to the ESP32. This enables manual override of automation and safe coexistence of automatic and user-controlled modes.
ELECTRICAL FAULT DETECTION & SAFETY
The system continuously monitors current values to detect anomalies. Fault Conditions: Overcurrent (sudden current spike greater than 2× previous value), Undercurrent (abnormally low current), Unexpected current draw when device is OFF. Response: Fault message displayed in red, fault retained until condition normalizes, protects appliances and wiring. This transforms the project into a home safety system, not just automation.
ENERGY MONITORING & BILL ESTIMATION
Data Used: Real-time power (W), Accumulated energy (kWh). Calculations: Daily energy usage, daily electricity cost, estimated monthly bill. Tariff Model: Normal rate ₹8 per kWh, Peak rate ₹12 per kWh. All calculations run locally on the ESP32-S3-BOX3 without cloud or external servers.
PEAK GUARD – TIME-AWARE ENERGY INTELLIGENCE
Peak Hours: Morning 6:00 AM – 10:00 AM, Evening 6:00 PM – 10:00 PM. Features: Detects peak hours automatically, calculates extra cost per hour during peak, displays warnings and energy-saving tips, shows time remaining to next peak period. This encourages behavioral energy optimization, which is often missing in basic smart home systems.
GRAPHICAL USER INTERFACE (LVGL)
The user interface is built using LVGL, optimized for the ESP32-S3-BOX3 touch display. Screens Implemented: Home Dashboard, Live Sensor Dashboard, Energy Analytics, Peak Guard Monitor, Device Control, Automation Settings, Fault Monitoring. UI Features: Touch-friendly layout, color-coded alerts, swipe-based navigation, real-time refresh every second.
MULTITASKING & REAL-TIME OPERATION
A dedicated FreeRTOS UI task updates system clock, refreshes analytics, updates fault status, displays automation states. This ensures smooth UI performance while networking and automation run in parallel.
SCALABILITY & REAL-WORLD APPLICATIONS
The software architecture supports adding more devices, integrating mobile apps, cloud dashboards, solar and battery monitoring, AI-based predictions. The design is scalable for homes, hostels, offices, and smart buildings.
CONCLUSION
This code demonstrates a complete embedded smart home intelligence system combining automation, safety, energy analytics, peak-hour awareness, and human-centric control. By leveraging microcontrollers from Espressif Systems, the project proves that advanced smart infrastructure can be achieved using low-power, cost-effective embedded systems without cloud dependency.
FOR ESP32-DEVKIT:
The ESP32 Dev Module functions as a sensor and device control unit within the smart home system, while the ESP32-S3 Box acts as the main controller and interface.
After power-up, the ESP32 initializes all sensors and relays and ensures that all connected appliances start in a safe OFF state.
It performs calibration of the current sensor to obtain an accurate zero-current reference for precise current measurement.
The ESP32 then connects to the configured WiFi network and establishes communication with the ESP32-S3 Box, which acts as the central dashboard and decision-making unit.
The device continuously collects real-time data from sensors including motion detection from the PIR sensor, ambient light intensity from the LDR, and current consumption from the ACS712 sensor.
Using the measured current and a standard voltage value, it calculates real-time power consumption and estimates total energy usage over time.
All collected sensor and energy data are packaged and transmitted periodically to the ESP32-S3 Box via WiFi in structured format.
The ESP32-S3 Box processes this data, displays system status, performs analytics, and sends control commands back to the ESP32.
The ESP32 receives these commands and accordingly switches relays to control appliances such as lights or other loads.
This allows centralized monitoring and intelligent control, where the ESP32 acts as the field device and the ESP32-S3 Box acts as the main smart controller.
The entire process runs continuously, enabling real-time monitoring, automation, and remote control within the simulated smart home environment.