Raspberry Pi Pico: RCWL-0516 Microwave Radar Proximity Sensor (Arduino IDE)

In this guide, you’ll learn how to use the RCWL-0516 Microwave Radar Proximity sensor to detect motion with the Raspberry Pi Pico programmed using Arduino IDE. We’ll show you how to wire the sensor and write an Arduino sketch to detect when motion is detected. The RCWL-0516 is a great alternative to the popular PIR motion sensor.

Raspberry Pi Pico with RCWL-0516 Microwave Radar Proximity Sensor Arduino IDE

New to the Raspberry Pi Pico? Read the following guide: Getting Started with Raspberry Pi Pico (and Pico W).

Table of Contents:

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

We have a similar tutorial using Raspberry Pi Pico with MicroPython firmware: Raspberry Pi Pico: RCWL-0516 Microwave Radar Proximity Sensor (MicroPython).

Prerequisites

You need to install the Raspberry Pi Pico boards on Arduino IDE and you must know how to upload code to the board. Check out the following tutorial first if you haven’t already:

Introducing the RCWL-0516 Microwave Radar Proximity Sensor

Introducing the RCWL-0516 Microwave Radar Proximity Sensor

The RCWL-0516 is a small, inexpensive sensor that uses microwave radar to detect the presence of moving objects. The sensor works by emitting a beam of microwaves and then detecting the Doppler shift in the reflected waves as objects move past.

Usually, these sensors are sold as a pack of five and don’t come with header pins. So, you may need to get header pins separately and then solder them yourself.

RCWL-0516 Microwave Radar Proximity Sensors

Where to Buy?

You can check the following link on Maker Advisor and compare the price in different stores.

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

How does it work?

The RCWL-0516 sensor has a built-in oscillator that generates a microwave signal at a frequency of 3.18 GHz. The sensor then sends out this signal in a 360-degree pattern.

When an object moves within the sensor’s range, the reflected waves are picked up by the sensor’s receiver. The receiver then measures the frequency of the reflected waves and compares it to the frequency of the original signal. If the frequency of the reflected waves has changed, the sensor knows that an object has moved.

The RCWL-0516 sensor has a single output pin that goes HIGH when it detects movement. It outputs LOW when no motion is detected.

RCWL-0516 Sensor Features

The RCWL-0516 has a detection range of up to 7 meters and can detect objects moving at speeds of up to 2 meters per second. It also has a built-in adjustable delay time, which can be used to prevent the sensor from triggering repeatedly on the same object.

RCWL-0516 Sensor Features

Here’s a summary of some of the key features of the RCWL-0516 sensor:

  • 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

RCWL-0516 sensor specifications:

  • 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

You can get more information about the sensor on the following GitHub page:

Optional Light Depend Resistor (LDR) Sensor

The sensor comes with the option to solder a light-depend resistor (light sensor) if you want your sensor to operate just in dark conditions, for example. You can get the output of the LDR sensor on the LDR pin. Alternatively, you can also connect the LDR to the CDS pin.

RCWL-0516 Sensor and Optional LDR

When the output of the LDR is bigger than 0.7V, the OUT pin will output a HIGH signal when motion is detected. If motion is detected but the output of the LDR is smaller than 0.7V, the output will be LOW. This means that when attaching an LDR, the sensor will only sense motion when it’s dark.

RCWL-0516 Microwave radar sensor with LDR

You can adjust the sensitivity of the LDR, by connecting a resistor on the R-CDS pads (see the following section), or by adding a pull-up resistor externally in parallel with the CDS pin.

In my case, I added a pull-up 22KOhm resistor to the LDR pin so that it could detect motion when there is low light. Without the resistor, not even in very dark conditions I had a positive output. You might need to try different resistance values to see which one works best for your scenario.

Adjustment components

RCWL-0516 Microwave radar sensor with LDR back sensor

At the back of the sensor, there are three pads for additional SMD components (0805 dimensions):

The following information was taken from this GitHub page.

  • 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


The RCWL-0516 microwave radar proximity sensor has five pins:

  • 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:

3V33.3V power output (not to power the sensor)
GNDground pin
OUToutput pin (goes HIGH when motion is detected)
VINinput voltage to power the sensor (4V to 28V)
CDSLight-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 RadarPIR Motion Sensor
How it works?Active Sensor (emits microwave signals and detects reflections).Passive Sensor (detects infrared radiation emitted by objects).
Detection RangeLonger range, typically up to 7+ meters.Shorter range, typically a few meters, depending on the model.
Sensing Through ObstaclesCan sense through non-metallic materials.Obstructed by certain materials (e.g., glass)
Sensitivity to MotionHighly sensitive, may give false positives.Not so sensitive, may miss subtle movements. Only detects living things that emit heat.
Coverage AreaBroad coverage with wide radar pattern.Narrow field of view.

Connecting the RCWL-0516 Microwave Radar Proximity Sensor to the Raspberry Pi Pico

Raspberry Pi Pico Connecting RCWL-0516 Microwave Radar Sensor

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

RCWL-0516 SensorRaspberry Pi Pico
3V3don’t connect
GNDGND
OUTGPIO22 (or any other GPIO of your choice)
VINVBUS (or preferably an external power supply between 4V to 28V)
CDSdon’t connect

We’ll also connect an LED to GPIO 21 to give us a visual output when motion is detected. You can connect the LED to any other digital pin.

Parts Required:

Connecting the the RCWL-0516 Microwave Radar Proximity Sensor to the Raspberry Pi Pico

We’re using the VBUS pin to power the RCWL-0516 sensor, but for better results, we recommend using an external power source (4V to 28V).

Raspberry Pi Pico 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 an LED accordingly (the LED is on when motion is detected).

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/raspberry-pi-pico-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 = 21;                // the pin that the LED is attached to
int sensor = 22;              // 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
    }
  }
}

View raw code

How the code works

Start by defining the pins for the LED and for the output pin of the sensor. We’re connecting an LED to GPIO 21, but you can use any other GPIO.

int led = 21;                // the pin that the LED is attached to

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

int sensor = 15;              // the pin that the sensor is attached 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
}

Uploading the Code to the Raspberry Pi Pico

To upload code to the Raspberry Pi Pico, it needs to be in bootloader mode.

If the Raspberry Pi is currently running MicroPython firmware, you need to manually put it into bootloader mode. For that, connect the Raspberry Pi Pico to your computer while holding the BOOTSEL button at the same time.

Raspberry Pi Pico Bootloader mode

For future uploads using Arduino IDE, the board should go automatically into bootloader mode without the need to press the BOOTSEL button.

Now, select your COM port in Tools > Port. It may be the case that the COM port is grayed out. If that’s the case, don’t worry it will automatically find the port once you hit the upload button.

Raspberry Pi Pico - COM port not found Arduino IDE

Upload the code.

Arduino 2.0 Upload Button

You should get a success message.

Raspberry Pi Pico done uploading Arduino IDE

Demonstration

After uploading, open the Serial Monitor.

When motion is detected. You should get a “Motion detected” message followed by a “Motion stopped” message after two seconds.

Raspberry Pi Pico Testing RCWL-0516 Microwave Sensor Serial Monitor.

Additionally, the LED will light up when motion is detected.

Raspberry Pi Pico Testing RCWL-0516

If you have an LDR connected, you’ll need to decrease the luminosity for the sensor to detect motion.

Detect Motion RCWL-0516 Raspberry Pi Pico

Wrapping Up

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

Want to learn more about the Raspberry Pi Pico? Check out the following tutorials:

Check out all our Raspberry Pi Pico Guides »

If you prefer to program the Raspberry Pi Pico using MicroPython, you can get started with the following tutorial:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

6 thoughts on “Raspberry Pi Pico: RCWL-0516 Microwave Radar Proximity Sensor (Arduino IDE)”

  1. Isn’t using a Raspberry Pi a bit of an overkill for this kind of project? Is there a reason why not to use an Arduino Nano (same form factor) from the scrap box?

    Reply
    • Hi.
      This is just a basic tutorial to show how to interface this kind of sensor.
      The idea is to use it in more advanced projects. Not just use it like this…
      Regards,
      Sara

      Reply
      • Thank you for your answer. I was just curious about whether there might be a technical reason behind the choice. And even with Arduinos there are a lot of sophisticated projects possible, I did make some of them myself. Just because something is newer and “more modern” doesn’t neccessarily mean it’s better.
        And I see how this tutorial might be more about the sensor than the microcontroller used. So just let me remark this: the sensor can be used with Arduinos, too, and even the code is basically the same. So just pull one out of your box of odds and sods, and go for it 🙂

        Reply
  2. I was confused in two areas.

    Firstly, there is no LDR pin, in places where the LDR pin is referenced, it should read as CDS pin. The voltage across the LDR could be read at the CDS pin.

    Secondly, the C-TM description is unclear. I think the device outputs a 2 second high pulse on OUT when motion is detected. Adding a capacitor on the C-TM terminals would change that time, probably increase it.

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.