{"id":133828,"date":"2023-09-06T16:37:33","date_gmt":"2023-09-06T16:37:33","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=133828"},"modified":"2023-09-08T08:47:22","modified_gmt":"2023-09-08T08:47:22","slug":"arduino-rcwl-0516","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-rcwl-0516\/","title":{"rendered":"Arduino with RCWL-0516 Microwave Radar Proximity Sensor (Detect Motion)"},"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 Arduino. We&#8217;ll show you how to wire the sensor and we&#8217;ll write a sample sketch for you to get started with the 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-Arduino-Tutorial.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino with RCWL-0516 Microwave Radar Proximity Sensor Detect Motion\" class=\"wp-image-133829\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-Arduino-Tutorial.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-Arduino-Tutorial.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-Arduino-Tutorial.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-Arduino-Tutorial.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><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-arduino-wiring\" title=\"\">Wiring the RCWL-0516 Sensor to the Arduino<\/a><\/li>\n\n\n\n<li><a href=\"#RCWL-0516-Arduino-sketch\" title=\"\">Arduino 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>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 pins\" 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><strong>RCWL-0516 Microwave Radar<\/strong><\/td><td><strong>PIR Motion Sensor<\/strong><\/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-arduino-wiring\">Connecting the RCWL-0516 Microwave Radar Proximity Sensor to the Arduino<\/h2>\n\n\n\n<p>In this section, we&#8217;ll wire the RCWL-0516 sensor to the Arduino board. We&#8217;ll also connect an LED to Pin13 that will light up when motion is detected. If you don&#8217;t have an LED, you can experiment with our example using the Arduino built-in LED.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>Here\u2019s a list of the parts required for this project:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noreferrer noopener\">Arduino UNO<\/a>&nbsp;(read&nbsp;<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Arduino starter kits<\/a>)<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener\" title=\"\">RCWL-0516 Microwave radar sensor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/photoresistor-light-dependent-resistor-ldr\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Light-dependent resistor<\/a> (optional)<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener\" title=\"\">LED<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noreferrer noopener\">220 Ohm Resistor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noreferrer noopener\">Breadboard<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper Wires<\/a><\/li>\n<\/ul>\n\n\n\n<p>Follow the next table or schematic diagram to wire the RCWL-0516 microwave radar proximity sensor to the Arduino:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>RCWL-0516 Sensor<\/strong><\/td><td><strong>Arduino<\/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\">Pin12<\/span> (or any other digital pin of your choice)<\/td><\/tr><tr><td>VIN<\/td><td><span class=\"rnthl rntcred\">5V<\/span> (or any voltage between 4V and 28V)<\/td><\/tr><tr><td>CDS<\/td><td>don&#8217;t connect (or connect an external LDR)<\/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=\"850\" height=\"564\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-Arduino_bb.jpg?resize=850%2C564&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Connecting wiring RCWL-0516 Microwave Radar Proximity Sensor to the Arduino\" class=\"wp-image-133831\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-Arduino_bb.jpg?w=850&amp;quality=100&amp;strip=all&amp;ssl=1 850w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-Arduino_bb.jpg?resize=300%2C199&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-Arduino_bb.jpg?resize=768%2C510&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"RCWL-0516-Arduino-sketch\">Arduino 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 Arduino accordingly (the LED is on when motion is detected).<\/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\/arduino-rcwl-0516\/\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\n\/\/If you're using the built-in LED for testing, remember that it works with inverted logic\n\/\/(HIGH=LOW, and LOW=HIGH)\nint led = 13;                \/\/ the pin that the LED is attached to\nint sensor = 12;              \/\/ 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(9600);        \/\/ 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\/Arduino\/Arduino_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. We&#8217;re connecting the LED to Pin 13. If you don&#8217;t have an LED, you can look at the Arduino built-in LED that is connected to Pin13.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int led = 13;                \/\/ the pin that the LED is attached to<\/code><\/pre>\n\n\n\n<p>We&#8217;re connecting the output of the sensor to Pin 12, but you can use any other pin.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>int sensor = 12;              \/\/ the pin that the sensor is attached 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 9600.<\/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(9600);        \/\/ 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 has 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 Arduino board and open the Serial Monitor at a baud rate of 9600. 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\/Arduino-RCWL-0516-circuit-breadboard.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino with RCWL-0516 breadboard circuit\" class=\"wp-image-133838\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/Arduino-RCWL-0516-circuit-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\/Arduino-RCWL-0516-circuit-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>When motion is detected. 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=\"624\" height=\"376\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-microwave-radar-arduino-serial-monitor.png?resize=624%2C376&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Testing Microwave Radar Sensor with Arduino\" class=\"wp-image-133832\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-microwave-radar-arduino-serial-monitor.png?w=624&amp;quality=100&amp;strip=all&amp;ssl=1 624w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-microwave-radar-arduino-serial-monitor.png?resize=300%2C181&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/figure><\/div>\n\n\n<p>If you have an LDR attached, you may 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-LDR-Arduino-detect-motion.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino RCWL with LDR\" class=\"wp-image-133839\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-LDR-Arduino-detect-motion.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-LDR-Arduino-detect-motion.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\/arduino-with-pir-motion-sensor\/\" title=\"\">Arduino with PIR Motion Sensor<\/a>.<\/p>\n\n\n\n<p>We have tutorials for more than 35 different sensors and modules with the Arduino. Check out the following link:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/20-free-guides-for-arduino-modules-and-sensors\/\" title=\"\">Free Guides for Arduino Sensors and Modules<\/a><\/li>\n<\/ul>\n\n\n\n<p>Learn more about the Arduino with our resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-step-by-step-projects\/\">Arduino Step by step Projects<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/projects-arduino\/\">Free Arduino projects and tutorials<\/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 Arduino. We&#8217;ll show you how to wire the sensor and we&#8217;ll &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Arduino with RCWL-0516 Microwave Radar Proximity Sensor (Detect Motion)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/arduino-rcwl-0516\/#more-133828\" aria-label=\"Read more about Arduino with RCWL-0516 Microwave Radar Proximity Sensor (Detect Motion)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":133829,"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":[303,267,2,302,245,264],"tags":[],"class_list":["post-133828","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino-project","category-arduino","category-0-guide","category-arduino-ide","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/07\/RCWL-0516-Arduino-Tutorial.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\/133828","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=133828"}],"version-history":[{"count":11,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/133828\/revisions"}],"predecessor-version":[{"id":135358,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/133828\/revisions\/135358"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/133829"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=133828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=133828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=133828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}