The RCWL-0516 Microwave Motion Sensor: It Sees Through Walls, but Don't Trust It Blindly
A 3.2 GHz Doppler radar for the price of a PIR sensor: it reacts to motion through plastic and thin walls and does not care about temperature. But to it a fan or a curtain is also a person. We build a light that switches on only when the radar and a PIR agree.
About the project
A PIR sensor reacts to heat, so sunlight blinds it and on a hot day it barely sees a person. The RCWL-0516 works differently: it emits a faint signal at about 3.2 GHz and picks up the Doppler shift from moving objects. It sees through a plastic enclosure, doors and plasterboard at 5–7 m. The flip side is that it reacts to any motion: a fan, a curtain in a draught, even a person behind the wall in the next room.
What you need
- ESP32 DevKit
- An RCWL-0516 module
- An HC-SR501 PIR sensor (for a cross-check)
- An LED and a 220 Ω resistor, or a relay module
Wiring
| Module | Pin | ESP32 |
|---|---|---|
| RCWL-0516 | VIN | 5V (4–28 V) |
| GND | GND | |
| OUT | GPIO16 | |
| HC-SR501 | VCC | 5V |
| OUT | GPIO17 | |
| GND | GND | |
| LED | GPIO26 → 220 Ω → GND |
The 3V3 pin on the RCWL-0516 is the output of its on-board regulator (up to 100 mA), not a supply input. Power the module through VIN. OUT gives 3.3 V even on a 12 V supply, so it connects straight to the ESP32. The CDS pin is for a photoresistor: pulling it to GND switches the sensor off (for a "night only" mode).
Adjustments on the board
- C-TM is the capacitor that sets the output time (about 2 s by default). More capacitance gives a longer pulse.
- R-GN is the range resistor. Soldering in 1 MΩ shrinks the range from about 7 m to about 5 m.
Mind the area behind the antenna: the sensor sees from the component side too, just less well. Metal nearby (an enclosure, a heatsink) distorts the pattern.
Two sensors, one truth
A reliable trick is to switch the light on only when both sensors see motion: the radar filters out PIR false triggers from sunlight and radiators, and the PIR filters out radar false triggers from a fan or motion behind a wall. In the simulator the radar has "A fan runs nearby" switched on: it triggers by itself every 6–16 seconds, and the Serial Monitor shows those signals being ignored.
Code
// Motion light: RCWL-0516 radar + PIR — switch on only when both agree
const int RADAR_PIN = 16;
const int PIR_PIN = 17;
const int LAMP_PIN = 26;
const unsigned long HOLD_MS = 10000; // how long to stay on after the last motion
unsigned long lastMotion = 0;
bool lampOn = false;
bool lastRadar = false;
void setup() {
Serial.begin(115200);
pinMode(RADAR_PIN, INPUT);
pinMode(PIR_PIN, INPUT);
pinMode(LAMP_PIN, OUTPUT);
}
void loop() {
bool radar = digitalRead(RADAR_PIN) == HIGH;
bool pir = digitalRead(PIR_PIN) == HIGH;
if (radar && !lastRadar) {
Serial.println(pir ? "Radar + PIR: motion" : "Radar only: ignored (a fan? a curtain?)");
}
lastRadar = radar;
if (radar && pir) lastMotion = millis();
bool on = lastMotion != 0 && millis() - lastMotion < HOLD_MS;
if (on != lampOn) {
lampOn = on;
digitalWrite(LAMP_PIN, on ? HIGH : LOW);
Serial.println(on ? "Light ON" : "Light OFF");
}
delay(50);
}
In the simulator click the PIR sensor and then the radar — the light switches on. The radar's own "fan" triggers do not switch it on.
Good to know
- Supply. From 3.3 V the module is unreliable; connect VIN to 5V.
- Two radars side by side interfere with each other (beat frequencies). Keep them 1 m or more apart.
- Wi-Fi. The radar itself does not disturb Wi-Fi (a different band), but an ESP32 antenna right next to the module can cause false triggers. A few centimetres of distance is usually enough.