In this tutorial, I am going to show you how the RCWL-0516 module works and use it to develop a simple movement/proximity detection system with an Arduino Mega 2560.
Parts Required
- Arduino Mega 2560;
- USB 2.0 Cable Type A/B;
- RCWL-0516 Microwave Sensor;
- 1 LED;
- 1 220 Ω resistor;
- Male to male jumper wires;
- 1 Breadboard;
Note: Since only 2 digital pins are required for you to follow this tutorial, an Arduino Nano, ESP32 NodeMCU board or any similar board can be used instead. Just be sure to change the pins in the code if necessary.
The RCWL-0516 Microwave Sensor
The sensor we are working with today is an RCWL-0516 Microwave Sensor (Figure 1). As the name suggests, it is an active device that works with a very low level of microwave radiation – about 3.1GHz – which is perfectly safe to work with and will not harm you even if you get very close to the sensor. It can measure a maximum distance of 7 meters and it may not work properly for distances under 20-30 centimetres.
The interesting aspect about this sensor however is that it works on a completely different principle than other devices that can be used for the same purpose. It takes advantage of something called the Doppler effect, and this is why this device is also named the Doppler sensor. This effect is characterized by the change in frequency of a wave in relation to an observer who is moving relative to the wave source [1]. One good example for us to understand this is to imagine a scenario where an ambulance is on a road, as exemplified in Figure 2.
When the ambulance is approaching, the pitch sounds higher as it reaches you, meaning that the wave frequency increases. When it moves away from you, the pitch goes down, and so the frequency of the sound waves is decreasing. For the person driving the ambulance, the pitch and frequency of the sound waves remain constant due to the fact that, from the point of view of the observer, the source is at rest.
At this point, it is important to highlight the difference between a microwave sensor and other proximity sensors. First of all, we will talk about PIR sensors, which stand for Passive Infrared. The passive in there is important because it means that the device sits there waiting to be triggered. It basically consists of a grid of infrared light detecting sensors and when something moves from one sensor to another it sees that it is in motion and triggers the connected circuit, which could be a light or an alarm, for instance (for more detailed information about this sensor, take a look at our tutorial).
As for ultrasonic distance sensors, these are active devices that can be used as a form of proximity sensing as well. One can easily use these to measure the distance to an object so that, when something passes that object, the distance measurement would be different and therefore a reading would be obtained, enabling the sensor to take action on the connected circuit (for more detailed information about this sensor, check out this tutorial).
Now, what’s the difference in practical terms between these sensors and microwave sensors? Well, while microwave sensors tend to be a bit more sensitive, they have a tendency to sometimes see through walls which can trigger lighting when it isn’t required. However, this does also lend the technology another advantage because it can be mounted behind a diffuser of a light fitting (such as a wall or a window) and detect motion through it. This means that you don’t have to cut a hole in the wall, which is excellent for some applications.
Circuit
The RCWL-0516 sensor is relatively easy to use since it only has 5 pins, as shown in Figure 3.
- VIN: Power supply between 4-28 V;
- 3V3: Power supply output of 3.3 V;
- GND: Ground (0V);
- OUT: Digital output;
- CDS: CDS photocell output. It is possible to install a photocell sensor on this module.
Start by connecting the GND to ground and the VIN pin to 5V in the Arduino. Then, connect the OUT pin to the digital pin 2 of the Arduino. Finally, connect the cathode of the LED to ground, its anode to the 220 Ω resistor, and then the resistor to the digital pin 3 of the Arduino. In the end, your circuit should be set as shown in Figure 4.
Code
In this tutorial, the use of the RCWL-0516 module will be used to simply light an LED whenever it detects movement. To do so, we have to define the necessary pins required to read the sensor data and control the LED. Then, we need to set the sensor pin as input and the LED pin as output and finally turn the LED on and off whenever movement is detected or not.
int sensor = 2; int LED = 3; int aux = 0; void setup() { //Define sensor as input and LED as output pinMode (sensor, INPUT); pinMode (LED, OUTPUT); } void loop() { //Read Pin as input int detect = digitalRead(sensor); //Detects when something moves and turns LED on if((detect > 0) && (aux==0)){ digitalWrite(LED, HIGH); aux = 1; } //When it stops moving turns the LED off if(detect == 0){ digitalWrite(LED, LOW); aux = 0; } }
That’s it! If you enjoyed this tutorial, you can visit our YouTube channel and watch our many tutorials. Thanks for following us and be sure to rate, comment and share our content.
References
[1] https://en.wikipedia.org/wiki/Doppler_effect
[2] https://www.quora.com/What-is-the-relationship-between-the-Doppler-effect-and-the-Doppler-redshift
Towards the Future !!! 😉