Hardware Setup & Wiring
Relevant source files
The following files were used as context for generating this wiki page:This document provides a comprehensive overview of the hardware components and their specific wiring configurations for the HomeSecurity project. The system is built around an ESP32 DOIT DevKit V1 microcontroller, which serves as the central processing unit, interfacing with various sensors for intrusion detection and actuators for alerts.
Correctly wiring these components to the specified GPIO pins is critical for the system's functionality. The software is hard-coded to read from and write to these specific pins. Any deviation from this setup will require corresponding changes in the source code.
ESP32 GPIO Mapping
The following diagram illustrates the connections between the ESP32 microcontroller and the peripheral hardware components.
This diagram shows the GPIO pins on the ESP32 dedicated to each sensor and indicator.
Sources: README.md:112-126, pir_sensor.h:6, hall_sensor.h:5, microwave_sensor.h:6, alarm.h:6, led.h:6-10
Detailed Pin Table
The following table provides a detailed breakdown of each component, its corresponding GPIO pin, the pin type, and its function within the system.
| Pin | Component | Type | Description | Source File |
|---|---|---|---|---|
| GPIO 33 | Hall Sensor | INPUT_PULLUP | Magnetic door/window sensor | hall_sensor.h |
| GPIO 21 | PIR Sensor | INPUT | Passive infrared motion detection | pir_sensor.h |
| GPIO 22 | Radar Sensor | INPUT | Doppler microwave motion detection | microwave_sensor.h |
| GPIO 25 | Buzzer | OUTPUT | Audible alarm actuator | alarm.h |
| GPIO 19 | Yellow LED | OUTPUT | Hall sensor triggered indicator | led.h |
| GPIO 18 | Blue LED | OUTPUT | PIR motion detected indicator | led.h |
| GPIO 23 | Red LED | OUTPUT | Intrusion confirmed by radar indicator | led.h |
| GPIO 4 | Green LED | OUTPUT | System calibrated and ready indicator | led.h |
| GPIO 13 | White LED | OUTPUT | WiFi connected indicator | led.h |
Sources: README.md:131-141, hall_sensor.cpp:4
Component Details
Sensors
The system uses a multi-layered sensor approach to detect intrusions and reduce false alarms.
Hall Effect Sensor (KY-003)
- Purpose: Perimeter detection. Senses when a door or window is opened.
- Wiring: Connected to
GPIO 33. The pin is configured asINPUT_PULLUP. - Code Definition:
// HomeSecurity/include/hall_sensor.h:5 #define HALL_SENSOR 33
Sources: README.md:83-85, hall_sensor.h:5, hall_sensor.cpp:4
PIR Sensor (HC-SR505)
- Purpose: General motion detection. Detects infrared radiation from warm bodies.
- Wiring: Connected to
GPIO 21. The pin is configured asINPUT. - Code Definition:
// HomeSecurity/include/pir_sensor.h:6 #define PIR_SENSOR 21 - Note: This sensor requires a 30-second calibration period upon system boot, during which the green LED is off. After calibration, the green LED turns on to indicate the system is ready.
Sources: README.md:87-91, pir_sensor.h:6, pir_sensor.cpp:12-15
Microwave Radar Sensor (RCWL-0516)
- Purpose: Presence confirmation. Uses the Doppler effect to detect sustained movement, helping to validate alerts from the PIR or Hall sensor.
- Wiring: Connected to
GPIO 22. The pin is configured asINPUT. - Code Definition:
// HomeSecurity/include/microwave_sensor.h:6 #define MICROWAVE_SENSOR 22
Sources: README.md:93-97, microwave_sensor.h:6
Actuators and Indicators
Visual and audible feedback is provided by a set of LEDs and a buzzer.
Buzzer (KY-012)
- Purpose: Provides an immediate, audible alarm when a potential intrusion is detected by the PIR or Hall sensor.
- Wiring: Connected to
GPIO 25. The pin is configured asOUTPUT. - Behavior: The alarm sounds for a duration defined by
ALARM_DURATION(3000ms) and is managed by a non-blocking handler. - Code Definition:
// HomeSecurity/include/alarm.h:6-7 #define BUZZER_PIN 25 #define ALARM_DURATION 3000
Sources: README.md:75, alarm.h:6-7, alarm.cpp:15-19
LED Status Indicators
A set of five LEDs provides visual feedback on the system's status and events. All LED pins are configured as OUTPUT.
| LED Color | GPIO Pin | Status Meaning |
|---|---|---|
| 🟢 Green | GPIO 4 | System is calibrated and ready. |
| ⚪ White | GPIO 13 | Successfully connected to WiFi. |
| 🟡 Yellow | GPIO 19 | Hall sensor is triggered (door/window open). |
| 🔵 Blue | GPIO 18 | PIR sensor has detected motion. |
| 🔴 Red | GPIO 23 | Intrusion confirmed by the radar sensor. |
Sources: README.md:145-154, led.h:6-10, led.cpp
The pin assignments are defined in led.h:
// HomeSecurity/include/led.h:6-10
#define yellowLED 19
#define blueLED 18
#define redLED 23
#define greenLED 4
#define whiteLED 13
Summary
The hardware configuration of the HomeSecurity project is a well-defined system of sensors and indicators connected to an ESP32. The GPIO pin assignments are explicitly defined in the project's header files and serve as the foundation for the software logic that reads sensor data and controls feedback mechanisms. Adhering to this wiring scheme is essential for the correct operation of the security system.