ESP32 with RCWL-0516 Microwave Radar Proximity Sensor (Arduino IDE).

Table of Contents:

ESP32 with RCWL-0516 Microwave Radar Proximity Sensor Arduino IDE

Throughout this tutorial, we’ll cover the following materials:

The RCWL-0516 is a tiny, low-cost sensor that utilizes microwave radar to detect the existence of relocating items.

Here’s a recap of some of the key attributes of the RCWL-0516 sensor:

Introducing the RCWL-0516 Microwave Radar Proximity Sensor

Introducing the RCWL-0516 Microwave Radar Proximity Sensor

RCWL-0516 sensor specifications:

You can get more details regarding the sensing unit on the adhering to GitHub web page:

RCWL-0516 Microwave Radar Proximity Sensors

Where to Buy?

The sensor comes with the choice to solder a light-depend resistor (light sensing unit) if you desire your sensor to run just in dark problems.

The RCWL-0516 microwave radar distance sensor has 5 pins:

The complying with table reveals the pinout of the RCWL-0516 microwave radar distance sensor:

How does it work?

The microwave radar distance sensing unit is many times utilized as an alternative to the PIR activity sensing unit, depending on the job application.

Table of Contents:

Throughout this tutorial, we’ll cover the following components:

RCWL-0516 Sensor Features

The RCWL-0516 is a little, affordable sensing unit that utilizes microwave radar to identify the visibility of moving objects.

RCWL-0516 Sensor Features

Here’s a summary of some of the key functions of the RCWL-0516 sensing unit:

RCWL-0516 sensor specs:

  • Uses microwave radar to detect moving objects
  • Detection range of up to 7 meters
  • Can detect objects moving at speeds of up to 2 meters per second
  • Built-in adjustable delay time
  • Low power consumption
  • Inexpensive

You can get even more information concerning the sensor on the adhering to GitHub page:

  • Supply voltage: 4–28 VDC
  • Operating frequency: 3.18 GHz
  • Sensing distance: 5–7 m
  • Output level: 3.4V High <0.7 Low
  • Output drive: 100mA
  • Output timing: 2 second retrigger with motion

The sensing unit comes with the choice to solder a light-depend resistor (light sensing unit) if you desire your sensing unit to run simply in dark problems.

Optional Light Depend Resistor (LDR) Sensor

At the back of the sensing unit, there are three pads for added SMD parts (0805 dimensions):

RCWL-0516 Sensor and Optional LDR

The following info was taken from this.

RCWL-0516 Microwave radar sensor with LDR

The RCWL-0516 microwave radar distance sensing unit has five pins:

The following table shows the pinout of the RCWL-0516 microwave radar distance sensor:

Adjustment components

RCWL-0516 Microwave radar sensor with LDR back

The microwave radar proximity sensor is many times utilized as a choice to the PIR activity sensor, depending on the job application. The following table compares both sensors:

Follow the following table or schematic layout to wire the RCWL-0516 microwave radar proximity sensor to the ESP32:

  • C-TM: Regulate the repeat trigger time. The default (unpopulated) time is 2s. An SMD capacitor to extend the repeat trigger time. Pin 3 of the IC emits a frequency (f), and the trigger time in seconds is given by (1/f) * 32678.
  • R-GN: The default detection range is 7m, adding a 1M resistor reduces it to 5m.
  • R-CDS: Resistor in parallel with the 1M pullup. Without R-CDS, the lowest resistance of the LDR (i.e. highest light level) where the output is enabled is ~269kΩ (=0.7V). Adding resistance here decreases the LDR resistance of the enable/disable threshold. If the LDR resistance at the desired light level threshold is <269k then you could add an external resistor in series with the LDR.

RCWL-0516 Microwave Radar Proximity Sensor Pinout

RCWL-0516 Microwave Radar Proximity Sensor Pinout

Copy the following code to your Arduino IDE.

  • 3V3: this is the output from the voltage regulator (not the power pin)
  • VIN: this is the power input pin. The sensor can be powered by a voltage range of 4-28V.
  • GND: this is the ground pin.
  • OUT: this is the output pin. The output pin goes HIGH when the sensor detects movement and remains LOW when it doesn’t.
  • CDS: this pin is used to connect a light-dependent resistor (LDR). The LDR can be used to disable the sensor in bright light conditions.

The following table shows the pinout of the RCWL-0516 microwave radar proximity sensor:

3V3 3.3V power output (not to power the sensor)
GND ground pin
OUT output pin (goes HIGH when motion is detected)
VIN input voltage to power the sensor (4V to 28V)
CDS light-dependent resistor output

Microwave Radar Proximity Sensor vs PIR Motion Sensor

Microwave Radar Proximity Sensor vs PIR Motion Sensor

The microwave radar proximity sensor is many times used as an alternative to the PIR motion sensor, depending on the project application. The following table compares both sensors:

RCWL-0516 Microwave Radar PIR Motion Sensor
How it works? Active Sensor (emits microwave signals and detects reflections). Passive Sensor (detects infrared radiation emitted by objects).
Detection Range Longer range, typically up to 7+ meters. Shorter range, typically a few meters, depending on the model.
Sensing Through Obstacles Can sense through non-metallic materials. Obstructed by certain materials (e.g., glass)
Sensitivity to Motion Highly sensitive, may give false positives. Not so sensitive, may miss subtle movements. Only detects living things that emit heat.
Coverage Area Broad coverage with wide radar pattern. Narrow field of view.

Connecting the RCWL-0516 Microwave Radar Proximity Sensor to the ESP32

Follow the next table or schematic diagram to wire the RCWL-0516 microwave radar proximity sensor to the ESP32:

RCWL-0516 Sensor ESP32
3V3 don’t connect
GND GND
OUT GPIO15 (or any other GPIO of your choice)
VIN VIN (or a voltage between 4 and 28V)
CDS don’t connect
Connecting the the RCWL-0516 Microwave Radar Proximity Sensor to the ESP32

ESP32 with the RCWL-0516 Sensor – Arduino Sketch

Copy the following code to your Arduino IDE. This example is very straightforward. It simply reads the output of the sensor and prints in the Serial Monitor when motion is detected and lights up the built-in LED of the ESP32 accordingly (the LED is on when motion is detected).

Alternatively, you may also use interrupts and timers to detect motion. You can use a similar code to the one we use in the following tutorial (you just need to adjust the GPIO numbers): .

/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp32-rcwl-0516-arduino/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/

int led = 2;                // the pin that the LED is attached to
int sensor = 15;            // the pin that the sensor is attached to
int state = LOW;            // by default, no motion detected
int val = 0;                // variable to store the sensor status (value)

void setup() {
  pinMode(led, OUTPUT);      // initalize LED as an output
  pinMode(sensor, INPUT);    // initialize sensor as an input
  Serial.begin(115200);      // initialize serial
}

void loop(){
  val = digitalRead(sensor);   // read sensor value
  if (val == HIGH) {           // check if the sensor is HIGH
    digitalWrite(led, HIGH);   // turn LED ON
    
    if (state == LOW) {
      Serial.println("Motion detected!"); 
      state = HIGH;       // update variable state to HIGH
    }
  } 
  else {
      digitalWrite(led, LOW); // turn LED OFF
      
      if (state == HIGH){
        Serial.println("Motion stopped!");
        state = LOW;       // update variable state to LOW
    }
  }
}

How the code works

Start by defining the pins for the LED and for the output pin of the sensor. To simplify we’re using the ESP32 built-in LED that is connected to GPIO2, but you can also connect a physical LED to any other GPIO, just change the code accordingly.

int led = 2;                // the pin that the LED is atteched to

We’re connecting the output of the sensor to GPIO 15, but you can use any other pin.

int sensor = 15;              // the pin that the sensor is atteched to

Then, initialize some variables. The state variable stores the current state of the output pin of the sensor and it is initially set to LOW.

int state = LOW;             // by default, no motion detected

The val variable will store the status (value) of the sensor’s digital output, either HIGH or LOW.

int val = 0;                 // variable to store the sensor status (value)

Basically, val is used to temporarily store the real-time output value of the sensor, while state is used to keep track of whether motion has been detected or not over time.

In the setup(), set the LED as an output and the sensor as an input. Also initialize the Serial Monitor at a baud rate of 115200.

void setup() {
  pinMode(led, OUTPUT);      // initalize LED as an output
  pinMode(sensor, INPUT);    // initialize sensor as an input
  Serial.begin(115200);        // initialize serial
}

In the loop(), we start by reading the sensor’s digital output (HIGH or LOW) and store it in the val variable.

val = digitalRead(sensor);   // read sensor value

If the sensor’s output is HIGH (motion detected), the LED turns on.

if (val == HIGH) {               // check if the sensor is HIGH
  digitalWrite(led, HIGH);   // turn LED ON

Then, we check if the previous status was LOW. If so, it means the state has changed and that motion have been detected. We print a message in the Serial Monitor and change the state variable to HIGH.

if (state == LOW) {
  Serial.println("Motion detected!"); 
  state = HIGH;       // update variable state to HIGH
}

If the sensor’s output is LOW (no motion detected), we turn the LED off.

else {
  digitalWrite(led, LOW); // turn LED OFF

If the previous state was HIGH and, if now the state is LOW, it means motion has stopped, and we can set the state variable to LOW.

if (state == HIGH){
  Serial.println("Motion stopped!");
  state = LOW;       // update variable state to LOW
}

Demonstration

Upload the code to your ESP32 board and open the Serial Monitor. Reset your board.

ESP32 with RCWL-0516 Microwave Radar Proximity Sensor Arduino IDE Demonstration

Wave your hand in front of the motion sensor. You should get a “Motion detected” message followed by a “Motion stopped” message after two seconds. Additionally, the on-board LED will light up when motion is detected.

Testing RCWL-0516 microwave radar sensor Serial Monitor Arduino IDE

If you have an LDR attached, you’ll need to decrease the luminosity to get positive results.

RCWL-0516 Microwave radar sensor with LDR Testing Demonstration

Wrapping Up

In this tutorial, you learned how to use the RCWL-0516 microwave radar proximity sensor to detect motion in your surroundings. The RCWL-0516 might be a good alternative to the PIR motion sensor depending on your project requirements.

We hope you found this tutorial useful. If you want to try a PIR motion sensor instead, read this tutorial: .

We have tutorials for more than different 25 sensors and modules with the ESP32. Check out the following link:

Do you want to learn more about the ESP32? Check out all our Resources:

Thanks for reading.