{"id":133440,"date":"2023-08-15T13:52:21","date_gmt":"2023-08-15T13:52:21","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=133440"},"modified":"2023-08-17T13:07:10","modified_gmt":"2023-08-17T13:07:10","slug":"esp32-rcwl-0516-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-rcwl-0516-arduino\/","title":{"rendered":"ESP32 with RCWL-0516 Microwave Radar Proximity Sensor (Arduino IDE)"},"content":{"rendered":"\n<p>In this guide, you&#8217;ll learn how to use the RCWL-0516 Microwave Radar Proximity sensor to detect motion with the ESP32. We&#8217;ll show you how to wire the sensor to the ESP32 board and we&#8217;ll write an Arduino sketch to detect when motion is detected. The RCWL-0516 is a great alternative to the popular PIR motion sensor.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32-Tutorial-arduino.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 with RCWL-0516 Microwave Radar Proximity Sensor Arduino IDE\" class=\"wp-image-133651\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32-Tutorial-arduino.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32-Tutorial-arduino.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32-Tutorial-arduino.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32-Tutorial-arduino.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclblue\">We have a similar tutorial for the ESP8266 board: <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-nodemcu-rcwl-0516-arduino\/\" title=\"\">ESP8266 NodeMCU with RCWL-0516 Microwave Radar Proximity Sensor (Arduino IDE)<\/a>.<\/p>\n\n\n\n<p><strong>Table of Contents:<\/strong><\/p>\n\n\n\n<p>Throughout this tutorial, we&#8217;ll cover the following contents:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#RCWL-0516-Microwave-Radar-Intro\" title=\"\">Introducing the RCWL-0516 Microwave Radar Proximity Sensor<\/a><\/li>\n\n\n\n<li><a href=\"#RCWL-0516-Microwave-Radar-pinout\" title=\"\">RCWL-0516 Sensor Pinout<\/a><\/li>\n\n\n\n<li><a href=\"#Microwave-Radar-Proximity-Sensor-vs-PIR-Motion-Sensor\" title=\"\">Microwave Radar Proximity Sensor vs PIR Motion Sensor<\/a><\/li>\n\n\n\n<li><a href=\"#RCWL-0516-ESP32-wiring\" title=\"\">Wiring the RCWL-0516 Sensor to the ESP32<\/a><\/li>\n\n\n\n<li><a href=\"#ESP32-RCWL-0516-Arduino-sketch\" title=\"\">ESP32 with the RCWL-0516 Sensor &#8211; Arduino Sketch<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"RCWL-0516-Microwave-Radar-Intro\">Introducing the RCWL-0516 Microwave Radar Proximity Sensor<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Introducing the RCWL-0516 Microwave Radar Proximity Sensor\" class=\"wp-image-133633\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>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.<\/p>\n\n\n\n<p>Usually, these sensors are sold as a pack of five and don&#8217;t come with header pins. So, you may need to get header pins separately and then solder them yourself.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensors.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"RCWL-0516 Microwave Radar Proximity Sensors\" class=\"wp-image-133634\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensors.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensors.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Where to Buy?<\/h3>\n\n\n\n<p>You can check the following link on Maker Advisor and compare the price in different stores.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/rcwl-0516-microwave-radar\/\" target=\"_blank\" rel=\"noopener\" title=\"\">RCWL-0516 Microwave Radar Proximity Sensor<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How does it work?<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>When an object moves within the sensor&#8217;s range, the reflected waves are picked up by the sensor&#8217;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.<\/p>\n\n\n\n<p>The RCWL-0516 sensor has a single output pin that goes HIGH when it detects movement. It outputs LOW when no motion is detected.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">RCWL-0516 Sensor Features<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor-breadboard.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"RCWL-0516 Sensor Features\" class=\"wp-image-133632\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor-breadboard.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor-breadboard.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Note: even though it mentions a detection range of up to 7 meters, I couldn&#8217;t get those results with my setup. However, I got very good feedback from some of our readers about this sensor.<\/p>\n\n\n\n<p>Here&#8217;s a summary of some of the key features of the RCWL-0516 sensor:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Uses microwave radar to detect moving objects<\/li>\n\n\n\n<li>Detection range of up to 7 meters<\/li>\n\n\n\n<li>Can detect objects moving at speeds of up to 2 meters per second<\/li>\n\n\n\n<li>Built-in adjustable delay time<\/li>\n\n\n\n<li>Low power consumption<\/li>\n\n\n\n<li>Inexpensive<\/li>\n<\/ul>\n\n\n\n<p><strong>RCWL-0516 sensor specifications<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Supply voltage<\/strong>: 4\u201328 VDC<\/li>\n\n\n\n<li><strong>Operating frequency<\/strong>: 3.18 GHz<\/li>\n\n\n\n<li><strong>Sensing distance<\/strong>: 5\u20137 m<\/li>\n\n\n\n<li><strong>Output level<\/strong>: 3.4V High &lt;0.7 Low<\/li>\n\n\n\n<li><strong>Output drive<\/strong>: 100mA<\/li>\n\n\n\n<li><strong>Output timing<\/strong>: 2 second retrigger with motion<\/li>\n<\/ul>\n\n\n\n<p>You can get more information about the sensor on the following GitHub page:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/jdesbonnet\/RCWL-0516\" target=\"_blank\" rel=\"noopener\" title=\"\">RCWL-0516 Github page<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Optional Light Depend Resistor (LDR) Sensor<\/h3>\n\n\n\n<p>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.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor-LDR-sensor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"RCWL-0516 Sensor and Optional LDR\" class=\"wp-image-133654\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor-LDR-sensor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor-LDR-sensor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>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&#8217;s dark.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-microwave-radar-with-LDR.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"RCWL-0516 Microwave radar sensor with LDR\" class=\"wp-image-133690\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-microwave-radar-with-LDR.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-microwave-radar-with-LDR.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>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.<\/p>\n\n\n\n<p>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 with different resistance values to see which one works best for your scenario.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adjustment components<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-optional-components.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"RCWL-0516 Microwave radar sensor with LDR back\" class=\"wp-image-133655\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-optional-components.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-optional-components.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>At the back of the sensor, there are three pads for additional SMD components (0805 dimensions):<\/p>\n\n\n\n<p>The following information was taken from this <a href=\"https:\/\/github.com\/jdesbonnet\/RCWL-0516\" target=\"_blank\" rel=\"noopener\" title=\"\">GitHub page<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>C-TM<\/strong>: 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.<\/li>\n\n\n\n<li><strong>R-GN<\/strong>: The default detection range is 7m, adding a 1M resistor reduces it to 5m.<\/li>\n\n\n\n<li><strong>R-CDS<\/strong>: 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\u03a9 (=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 &lt;269k then you could add an external resistor in series with the LDR.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"RCWL-0516-Microwave-Radar-pinout\">RCWL-0516 Microwave Radar Proximity Sensor Pinout<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"RCWL-0516 Microwave Radar Proximity Sensor Pinout\" class=\"wp-image-133633\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><br>The RCWL-0516 microwave radar proximity sensor has five pins:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>3V3<\/strong>: this is the output from the voltage regulator (not the power pin)<\/li>\n\n\n\n<li><strong>VIN:<\/strong>&nbsp;this is the power input pin. The sensor can be powered by a voltage range of 4-28V.<\/li>\n\n\n\n<li><strong>GND:<\/strong>&nbsp;this is the ground pin.<\/li>\n\n\n\n<li><strong>OUT:<\/strong>&nbsp;this is the output pin. The output pin goes HIGH when the sensor detects movement and remains LOW when it doesn&#8217;t.<\/li>\n\n\n\n<li><strong>CDS:<\/strong>&nbsp;this pin is used to connect a light-dependent resistor (LDR). The LDR can be used to disable the sensor in bright light conditions.<\/li>\n<\/ul>\n\n\n\n<p>The following table shows the pinout of the RCWL-0516 microwave radar proximity sensor:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>3V3<\/strong><\/td><td>3.3V power output (not to power the sensor)<\/td><\/tr><tr><td><strong>GND<\/strong><\/td><td>ground pin<\/td><\/tr><tr><td><strong>OUT<\/strong><\/td><td>output pin (goes HIGH when motion is detected)<\/td><\/tr><tr><td><strong>VIN<\/strong><\/td><td>input voltage to power the sensor (4V to 28V)<\/td><\/tr><tr><td><strong>CDS<\/strong><\/td><td>light-dependent resistor output<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Microwave-Radar-Proximity-Sensor-vs-PIR-Motion-Sensor\">Microwave Radar Proximity Sensor vs PIR Motion Sensor<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-microwave-radar-vs-PIR-motion-sensor.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Microwave Radar Proximity Sensor vs PIR Motion Sensor\" class=\"wp-image-133691\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-microwave-radar-vs-PIR-motion-sensor.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-microwave-radar-vs-PIR-motion-sensor.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>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:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><\/td><td>RCWL-0516 Microwave Radar<\/td><td>PIR Motion Sensor<\/td><\/tr><tr><td><strong>How it works?<\/strong><\/td><td>Active Sensor (emits microwave signals and detects reflections).<\/td><td>Passive Sensor (detects infrared radiation emitted by objects).<\/td><\/tr><tr><td><strong>Detection Range<\/strong><\/td><td>Longer range, typically up to 7+ meters.<\/td><td>Shorter range, typically a few meters, depending on the model.<\/td><\/tr><tr><td><strong>Sensing Through Obstacles<\/strong><\/td><td>Can sense through non-metallic materials.<\/td><td>Obstructed by certain materials (e.g., glass)<\/td><\/tr><tr><td><strong>Sensitivity to Motion<\/strong><\/td><td>Highly sensitive, may give false positives.<\/td><td>Not so sensitive, may miss subtle movements. Only detects living things that emit heat.<\/td><\/tr><tr><td><strong>Coverage Area<\/strong><\/td><td>Broad coverage with wide radar pattern.<\/td><td>Narrow field of view.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"RCWL-0516-ESP32-wiring\">Connecting the RCWL-0516 Microwave Radar Proximity Sensor to the ESP32<\/h2>\n\n\n\n<p>Follow the next table or schematic diagram to wire the RCWL-0516 microwave radar proximity sensor to the ESP32:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>RCWL-0516 Sensor<\/strong><\/td><td><strong>ESP32<\/strong><\/td><\/tr><tr><td>3V3<\/td><td>don&#8217;t connect<\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><tr><td>OUT<\/td><td><span class=\"rnthl rntcblue\">GPIO15<\/span> (or any other GPIO of your choice)<\/td><\/tr><tr><td>VIN<\/td><td><span class=\"rnthl rntcred\">VIN<\/span> (or a voltage between 4 and 28V)<\/td><\/tr><tr><td>CDS<\/td><td>don&#8217;t connect<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"891\" height=\"696\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32_bb.png?resize=891%2C696&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Connecting the the RCWL-0516 Microwave Radar Proximity Sensor to the ESP32\" class=\"wp-image-133648\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32_bb.png?w=891&amp;quality=100&amp;strip=all&amp;ssl=1 891w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32_bb.png?resize=300%2C234&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32_bb.png?resize=768%2C600&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 891px) 100vw, 891px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"ESP32-RCWL-0516-Arduino-sketch\">ESP32 with the RCWL-0516 Sensor &#8211; Arduino Sketch<\/h2>\n\n\n\n<p>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).<\/p>\n\n\n\n<p>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): <a href=\"https:\/\/randomnerdtutorials.com\/esp32-pir-motion-sensor-interrupts-timers\/\" title=\"\">ESP32 with PIR Motion Sensor using Interrupts and Timers<\/a>.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Rui Santos\n  Complete project details at https:\/\/RandomNerdTutorials.com\/esp32-rcwl-0516-arduino\/\n  \n  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.\n  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n*\/\n\nint led = 2;                \/\/ the pin that the LED is attached to\nint sensor = 15;            \/\/ the pin that the sensor is attached to\nint state = LOW;            \/\/ by default, no motion detected\nint val = 0;                \/\/ variable to store the sensor status (value)\n\nvoid setup() {\n  pinMode(led, OUTPUT);      \/\/ initalize LED as an output\n  pinMode(sensor, INPUT);    \/\/ initialize sensor as an input\n  Serial.begin(115200);      \/\/ initialize serial\n}\n\nvoid loop(){\n  val = digitalRead(sensor);   \/\/ read sensor value\n  if (val == HIGH) {           \/\/ check if the sensor is HIGH\n    digitalWrite(led, HIGH);   \/\/ turn LED ON\n    \n    if (state == LOW) {\n      Serial.println(&quot;Motion detected!&quot;); \n      state = HIGH;       \/\/ update variable state to HIGH\n    }\n  } \n  else {\n      digitalWrite(led, LOW); \/\/ turn LED OFF\n      \n      if (state == HIGH){\n        Serial.println(&quot;Motion stopped!&quot;);\n        state = LOW;       \/\/ update variable state to LOW\n    }\n  }\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP32\/ESP32_RCWL_0516_Basic.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the code works<\/h2>\n\n\n\n<p>Start by defining the pins for the LED and for the output pin of the sensor. To simplify we&#8217;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.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int led = 2;                \/\/ the pin that the LED is atteched to<\/code><\/pre>\n\n\n\n<p>We&#8217;re connecting the output of the sensor to GPIO 15, but you can use any other pin.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int sensor = 15;              \/\/ the pin that the sensor is atteched to<\/code><\/pre>\n\n\n\n<p>Then, initialize some variables. The <span class=\"rnthl rntliteral\">state<\/span> variable stores the current state of the output pin of the sensor and it is initially set to <span class=\"rnthl rntliteral\">LOW<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int state = LOW;             \/\/ by default, no motion detected<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">val<\/span> variable will store the status (value) of the sensor&#8217;s digital output, either <span class=\"rnthl rntliteral\">HIGH<\/span> or <span class=\"rnthl rntliteral\">LOW<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int val = 0;                 \/\/ variable to store the sensor status (value)<\/code><\/pre>\n\n\n\n<p>Basically, <span class=\"rnthl rntliteral\">val<\/span> is used to temporarily store the real-time output value of the sensor, while <span class=\"rnthl rntliteral\">state<\/span> is used to keep track of whether motion has been detected or not over time.<\/p>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, set the LED as an output and the sensor as an input. Also initialize the Serial Monitor at a baud rate of 115200.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>void setup() {\n  pinMode(led, OUTPUT);      \/\/ initalize LED as an output\n  pinMode(sensor, INPUT);    \/\/ initialize sensor as an input\n  Serial.begin(115200);        \/\/ initialize serial\n}<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, we start by reading the sensor&#8217;s digital output (<span class=\"rnthl rntliteral\">HIGH<\/span> or <span class=\"rnthl rntliteral\">LOW<\/span>) and store it in the <span class=\"rnthl rntliteral\">val<\/span> variable.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>val = digitalRead(sensor);   \/\/ read sensor value<\/code><\/pre>\n\n\n\n<p>If the sensor&#8217;s output is <span class=\"rnthl rntliteral\">HIGH<\/span> (motion detected), the LED turns on. <\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (val == HIGH) {               \/\/ check if the sensor is HIGH\n  digitalWrite(led, HIGH);   \/\/ turn LED ON<\/code><\/pre>\n\n\n\n<p>Then, we check if the previous status was <span class=\"rnthl rntliteral\">LOW<\/span>. If so, it means the <span class=\"rnthl rntliteral\">state<\/span> has changed and that motion have been detected. We print a message in the Serial Monitor and change the <span class=\"rnthl rntliteral\">state<\/span> variable to <span class=\"rnthl rntliteral\">HIGH<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (state == LOW) {\n  Serial.println(\"Motion detected!\"); \n  state = HIGH;       \/\/ update variable state to HIGH\n}<\/code><\/pre>\n\n\n\n<p>If the sensor&#8217;s output is <span class=\"rnthl rntliteral\">LOW<\/span> (no motion detected), we turn the LED off.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>else {\n  digitalWrite(led, LOW); \/\/ turn LED OFF<\/code><\/pre>\n\n\n\n<p>If the previous state was <span class=\"rnthl rntliteral\">HIGH<\/span> and, if now the state is <span class=\"rnthl rntliteral\">LOW<\/span>, it means motion has stopped, and we can set the state variable to <span class=\"rnthl rntliteral\">LOW<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>if (state == HIGH){\n  Serial.println(\"Motion stopped!\");\n  state = LOW;       \/\/ update variable state to LOW\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>Upload the code to your ESP32 board and open the Serial Monitor. Reset your board.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/ESP32-RCWL-0516.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 with RCWL-0516 Microwave Radar Proximity Sensor Arduino IDE Demonstration\" class=\"wp-image-133692\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/ESP32-RCWL-0516.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/ESP32-RCWL-0516.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Wave your hand in front of the motion sensor. You should get a &#8220;Motion detected&#8221; message followed by a &#8220;Motion stopped&#8221; message after two seconds. Additionally, the on-board LED will light up when motion is detected.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"604\" height=\"368\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/testing-microwave-radar-sensor-rcwl-0516-serial-monitor.png?resize=604%2C368&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Testing RCWL-0516 microwave radar sensor Serial Monitor Arduino IDE\" class=\"wp-image-133686\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/testing-microwave-radar-sensor-rcwl-0516-serial-monitor.png?w=604&amp;quality=100&amp;strip=all&amp;ssl=1 604w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/testing-microwave-radar-sensor-rcwl-0516-serial-monitor.png?resize=300%2C183&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><\/figure><\/div>\n\n\n<p>If you have an LDR attached, you&#8217;ll need to decrease the luminosity to get positive results.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor-triggered-ESP32.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"RCWL-0516 Microwave radar sensor with LDR Testing Demonstration\" class=\"wp-image-133693\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor-triggered-ESP32.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-sensor-triggered-ESP32.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>We hope you found this tutorial useful. If you want to try a PIR motion sensor instead, read this tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-pir-motion-sensor-interrupts-timers\/\" title=\"\">ESP32 with PIR Motion Sensor<\/a>.<\/p>\n\n\n\n<p>We have tutorials for more than different 25 sensors and modules with the ESP32. Check out the following link:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-guides-sensors-modules\/\">ESP32: 26 Free Guides for Sensors and Modules<\/a><\/li>\n<\/ul>\n\n\n\n<p>Do you want to learn more about the ESP32? Check out all our Resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE (eBook)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266 (eBook)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/firebase-esp32-esp8266-ebook\/\">Firebase Web App with ESP32 and ESP8266 (eBook)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/smart-home-ebook\/\" title=\"\">SMART HOME with Raspberry Pi, ESP32, and ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-esp32\/\">Free ESP32 Projects and Tutorials\u2026<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;ll learn how to use the RCWL-0516 Microwave Radar Proximity sensor to detect motion with the ESP32. We&#8217;ll show you how to wire the sensor to the &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32 with RCWL-0516 Microwave Radar Proximity Sensor (Arduino IDE)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-rcwl-0516-arduino\/#more-133440\" aria-label=\"Read more about ESP32 with RCWL-0516 Microwave Radar Proximity Sensor (Arduino IDE)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":133651,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[281,276,277,299,264],"tags":[],"class_list":["post-133440","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32","category-esp32-arduino-ide","category-0-esp32","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-ESP32-Tutorial-arduino.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/133440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=133440"}],"version-history":[{"count":30,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/133440\/revisions"}],"predecessor-version":[{"id":134603,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/133440\/revisions\/134603"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/133651"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=133440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=133440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=133440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}