Microwave Radar Sensor Module
Relevant source files
The following files were used as context for generating this wiki page:The Microwave Radar Sensor (RCWL-0516) is a key component of the HomeSecurity system's two-stage alert logic. Its primary purpose is to provide presence confirmation after an initial alert is triggered by the PIR or Hall sensor. By detecting sustained motion using the Doppler effect, it helps reduce false alarms and escalates the alert level only when continuous movement is confirmed. This module is immune to temperature and light variations, making it a reliable secondary check.
The sensor's logic runs in a dedicated FreeRTOS task, handleRadarMovementTask, ensuring it operates concurrently without blocking other system functions.
Sources: HomeSecurity/README.md, HomeSecurity/src/motion_logic.cpp:113-141
Configuration and Setup
The microwave radar sensor is connected to a specific GPIO pin on the ESP32, and its pin mode is configured during system initialization.
Pin Configuration
| Parameter | Pin | Description |
|---|---|---|
MICROWAVE_SENSOR | GPIO 22 | Digital input for the radar sensor signal. |
Sources: HomeSecurity/include/microwave_sensor.h:6, HomeSecurity/README.md
Initialization
The sensor is initialized by the setupMicrowaveSensor() function, which is called within the main setupSensors() routine. This function sets the GPIO pin MICROWAVE_SENSOR to INPUT mode.
// HomeSecurity/src/microwave_sensor.cpp:4-6
void setupMicrowaveSensor() {
pinMode(MICROWAVE_SENSOR, INPUT);
}
Sources: HomeSecurity/src/microwave_sensor.cpp:4-6, HomeSecurity/src/motion_logic.cpp:10
Core Functionality
The module's core logic is encapsulated in the isRadarActive() function, which provides a simple boolean status of the sensor's state.
isRadarActive()
This function performs a digital read on the sensor's GPIO pin. It returns true if the pin state is HIGH, indicating motion has been detected, and false otherwise. When motion is detected, a message is printed to the serial console.
// HomeSecurity/src/microwave_sensor.cpp:8-18
bool isRadarActive() {
bool retVal = false;
bool radarRead = digitalRead(MICROWAVE_SENSOR);
if (radarRead == HIGH) {
retVal = true;
Serial.println("[ALERT] Radarul detectează mișcare!");
}
return retVal;
}
Sources: HomeSecurity/src/microwave_sensor.cpp:8-18
Presence Confirmation Logic
The microwave sensor's primary role is to confirm a potential intrusion. This logic is managed by the handleRadarMovementTask, a dedicated FreeRTOS task that runs with medium priority.
Sources: HomeSecurity/src/main.cpp:13, HomeSecurity/src/motion_logic.cpp:113-141
FreeRTOS Task
The task is created in main.cpp with a stack size of 6144 bytes and a priority of 3.
| Task | Priority | Stack Size |
|---|---|---|
handleRadarMovementTask | 3 | 6144 bytes |
Sources: HomeSecurity/src/main.cpp:13, HomeSecurity/README.md
Confirmation Flow
The task implements a timer-based logic to confirm sustained motion. An alert is only escalated if the radar sensor remains active for a continuous period of 2 seconds.
The following diagram illustrates the logic within the handleRadarMovementTask.
Actions on Confirmation
When sustained motion is confirmed, the following actions are triggered:
- Visual Indicator: The red LED is turned on via
turnRedLedOn(). - Push Notification: A high-priority notification with the title "Mișcare confirmată" is sent to the mobile client using the
FirebaseNotifierclass.
This sequence is shown in the diagram below.
Summary
The Microwave Radar Sensor module serves as the second stage in the HomeSecurity alert system. It provides robust presence confirmation by filtering out brief, transient movements. By running in an independent FreeRTOS task and triggering a confirmation alert only after 2 seconds of continuous activity, it significantly enhances the system's reliability and reduces the likelihood of false alarms, ensuring that the user is only notified of a confirmed, ongoing presence.
Sources: HomeSecurity/README.md, HomeSecurity/src/motion_logic.cpp:113-141