Lost + Found RCWL-0516 radar motion sensor driver library for Raspberry Pi Pico C SDK
- C 70.5%
- CMake 19.2%
- Python 10.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| include | ||
| src | ||
| .gitignore | ||
| CMakeLists.txt | ||
| conanfile.py | ||
| example.c | ||
| pico_sdk_import.cmake | ||
| README.md | ||
🔌 Lost + Found RCWL-0516 Radar Motion Sensor Driver
This driver provides a simple, interrupt-driven interface for the RCWL-0516 microwave Doppler radar motion sensor module on the Raspberry Pi Pico 2 (RP2350).
🎛️ Hardware Description & Specifications
The RCWL-0516 uses Doppler radar to detect moving objects. Unlike PIR (passive infrared) sensors, it is highly sensitive to motion and can detect movements through thin walls, plastic, wood, and glass.
📐 Sensor Characteristics & Tentative Specifications
- Default Output Trigger Timeout: ~2 seconds. The sensor output goes HIGH for 2s upon detecting motion, then drops LOW (enters idle state).
- Detection Distance/Range: Typically 5 to 7 meters (up to 9m maximum depending on mounting and environment).
- Detection Angle: 360 degrees (omnidirectional sensing). Sensitivity is slightly higher facing the front component side of the PCB, but it detects motion in all directions.
- RF Penetration: Can penetrate non-metallic barriers. Avoid metal enclosures, which block microwave radar signals completely.
🔌 Wiring Diagram (Pico 2)
| Sensor Pin | Pico 2 GPIO Pin | Pico 2 Physical Pin | Notes |
|---|---|---|---|
| VIN | VBUS | Pin 40 | Power input (5V). |
| GND | GND | Pin 38 (or any GND) | Common ground reference. |
| OUT | GP15 | Pin 20 | Digital output (3.3V logic level, active-HIGH). |
| 3V3 | Disconnected | — | Unused 3.3V output from onboard regulator. |
🚀 Usage Example
Configure your application to route GPIO interrupts to the driver handler.
#include "pico/stdlib.h"
#include "lf_rcwl0516.h"
#include <stdio.h>
#define SENSOR_PIN 15
static lf_rcwl0516_t radar;
void gpio_callback(uint gpio, uint32_t events) {
if (gpio == SENSOR_PIN) {
lf_rcwl0516_irq_handler(&radar);
}
}
int main() {
stdio_init_all();
lf_rcwl0516_init(&radar, SENSOR_PIN);
gpio_set_irq_enabled_with_callback(
SENSOR_PIN,
GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL,
true,
&gpio_callback
);
while (true) {
bool motion = false;
if (lf_rcwl0516_check_and_clear_changed(&radar, &motion)) {
printf("[EVENT] Sensor state: %s\n", motion ? "MOTION DETECTED" : "CLEAR/IDLE");
}
__wfi();
}
}