by Floris Wouterlood – The Netherlands – October 6, 2020
In this project a Doppler radar motion sensor (type RCWL-0516) is applied to trigger an Arduino to light a LED. The LED stays on until a button is pressed. Normally this would be simple to achieve. The challenge here is that the motion detector has an OUT pin that, when the detector senses something, carries a signal for two full seconds. As the RCWL-0516 acts autonomously we need an Arduino to control the LED’s performance in software. A touch switch whose state is continuously monitored by the Arduino is used to turn the LED off. An 128*64 OLED presents visual information about the state of various parameters. Through this we have an Arduino version at hand of a stairway – basement – cupboard proximity lighting system.
Motion detection typically is the domain of security systems, car protection, lighting applications and wildlife photography. This type of detection can be accomplished in several ways, for instance with a passive infrared detector (PIR) that senses temperature changes in the body heat range. A completely different way to detect movement or displacement is through Doppler radar sensing. This can be helpful in situations where moving objects do not project a significant amount of heat (imagine a big cold blooded lizard, say a T-Rex, peeking around the corner or an electric car driving up your driveway).
Figure 1. RCWL-0516 breakout board. Shown is the upper surface with the electronic components, the ‘active’ face that must preferably be directed towards the area to be monitored. In the current project we need only pins VIN, OUT and GND. CDS is for day-night operation selection while the pin marked 3V3 is an auxiliary pin that continuously provides 3.3V power.
The frequency disturbance that a moving object produces in a radiowave field (so-called Doppler shift) can be detected. A sensor available for the Arduino based on Doppler technology is the RCWL-0516, an inexpensive mini (breakout) board with five pins. An on board antenna produces a microwave field. Once a movement has been detected a signal is fired by the device: the data pin (marked ‘OUT’) is set HIGH during 2 seconds. This event can easily be detected by an Arduino and can be used to record events and trigger appropriate action. The aim here was basically very simple: activate a LED through movement detection. Once the LED burns it should stay on until a button is pressed. The practical realization of this appeared somewhat more complex than initially thought.
The RCWL-0516 is a mini radar motion detector module (dimensions (35×15 mm) that carries a transmitter that emits 3.182 MHz frequency radio waves at 20-30 mW. The frequency of radio waves bounced back to the sensor by moving objects is different from that of waves bouncing from walls and static objects (the Doppler effect). Detection distance is 5 to 9 meters which makes this sensor attractive as a component in an intruder alarm device or a light switch. Default trigger time is two seconds. The board supports night-day detection if a 0-20 kΩ light dependent resistor (LDR; photoresistor) has been attached to the CDS header on the board and day-night operation has been enabled in software. Input voltage is between 4V and 28V DC. Continuously available is 100 mA at the 3.3 V pin.
Electronic components needed
1x RCWL-0516 breakout miniboard, 1x Arduino Nano microcontroller board, 1x 128*64 OLED (here a I2C type with SSD1306 controller), prototyping breadboard, 1x 220 Ω resistor, 1x 1kΩ resistor, 1x led, 1x TTP 223 single channel capacitive touch switch (a simple button will do was well), jumper wires.
Figure 2. Wiring diagram: Arduino Nano and RCWL-0516, OLED and switch. The LED is connected to pin pin D5 of the Nano. It starts to light up when motion is detected; the switch produces a LOW on pin D3 that informs the microprocessor to ‘stop’ the LED. Note the 1 kΩ pull down resistor on this switch.
Wiring the RCWL-0516 miniboard to an Arduino
The wiring of the RCWL-0516 is straightforward (Figure 2). The miniboard is equipped with five pins, labeled 3V3, GND, OUT, VIN and CDS. Note that the 3V3 pin is an output pin that continuously carries 3.3V at a rated 100 mA. This pin is therefore NOT a pin supplying power to the miniboard. Regular 5V operating power to the miniboard is in this example supplied from the Arduino’s 5V pin connected to the pin marked VIN of the RCWL-0516.
The pin ‘OUT’ will carry a voltage for approximately two seconds when the detector monitors some disturbance of its radio frequency field. This pin is connected to an input pin of the Arduino (in this example pin D2).
Switch: Here, a normal pushbutton can be used. In the physical design I used a ‘luxury’ single channel capacitive touch switch (visible in figure 3) connected to pin D3 of the Arduino. This type of switch needs 5V power and GND wires in addition to the Arduino datapin connectivity. Touching the switch causes pin D3 of the Arduino to become LOW. The issue here is that an RCWL-0516 is an autonomous device that keeps its OUT pin HIGH for two long seconds irrespective what instruction the Arduino issues towards the sensor. This is the unresponsive period of the sensor.
Figure 3. Working prototype of a motion detection system that reports ‘events’ and acts in response. Upon activation of the sensor by moving a hand in front the ‘event LED’ is activated. The sensor returns to LOW autonomously while the event LED is turned off by touching the switch.
Sketch design considerations
The assembled detector, Arduino Nano, LED, switch and OLED monitor are presented in figure 3. One complicating condition is the unresponsive period of two seconds HIGH state of the OUT pin of the LCWR-0516 board when its sensor detects a disturbance of the radio wave field.
The sketch design keeps the following considerations in mind.
Because we want to keep the LED burning after the sensor’s OUT has returned to LOW state we need to control the ons and offs of the LED through the Arduino. Remember, the configuration is the following:
In order to keep the LED burning after the sensor signal has returned to LOW an extra parameter is introduced: sensorFlag. This flag is set as soon as the Arduino detects change on its pin D2. The state of the flag (0 or 1) governs the state of pin D5 where the LED sits.
The state of the switch is checked and if a change here is detected, another flag is set (buttonFlag to 1) and the sensorFlag is set to 0.
After this the signal to the LED is set HIGH (if sensorFlag = 1) or LOW (if sensorFlag=0). these values are communicated with the OLED.
The OLED is included in the project because of the need to monitor the behavior of pin states and flags. To embellish the presentation an on-screen LED-simulation is running in sync with the illumination-or-not of the event LED.
Results and Discussion
The RCWL-0516 Doppler radar motion detector nicely does what it claims: a signal is generated at pin OUT when a moving object disturbs its radiofrequency field. Infrared motion detectors by contrast detect body heat not only emitted by a moving object but also of stationary objects. In Doppler radar motion detection the object does not necessarily have to be a living creature that emits body heat. However, the construction and firmware of a RCWL-0516 seems to be optimized for detecting objects the size and speed of moving humans.
What seemed at the start so easy appeared to be more complicated due to several conditions.
1. Most important is that the RCWL-0516 is an autonomous board. Once powered up it supports itself, builds up a radiofrequency field, monitors that and sets the pin OUT to HIGH during two seconds when it detects a Doppler disturbance of the radiofrequency field. This means that the LED will stay on during that entire period. If the switch is touched and consequently SensorFlag is set to 0, the fact that OUT is still active and pin D2 of the Arduino therefore still HIGH will force the Arduino to promptly set pin D5 to the LED HIGH. The outcome is that in this 2-second period the LED immeditely reawakens after one has touched the switch. This can be very annoying. One can say it differenty: a RCWL-0516 reacts lazy.
2. The next condition is that an OLED is included in the assembly that is controlled by a SSD1306 chip that needs the <u8glib.h> library created by Olikraus in order to work. This library sets its own conditions on the programming because its Draw () function does not like subroutines. All ‘action’ needs to be programmed within Draw().
3. The data wire of the switch needs to be pulled LOW such that a state change of this pin can be properly detected by the Arduino. Pulling down is achieved on the prototype board in figure 3 by a 1 kΩ resistor connecting pin D3 to GND. In a soldered-together assembly this pull down resistor had to be of considerable higher resistance (10 kΩ) to have effect.
A sensor such as the RCWL-0516 invites to continue with experiments to automatically switch illumination on and off in spaces such as cupboards, basements and stairways. The successful conclusion of the current project certainly invites such experiments.
Arduino Doppler radar motion detector – sketch
The sketch presented here does the following:
The library <u8glib.h> is only included to run the SSD1306 OLED. It is not required for running the RCWL-0516 miniboard.