ESPHome Presence detection with a microwave radar sensor
Based on the RCWL-0516 sensor
Introduction
The RCWL-0516 microwave sensor is a cheap motion and presence detection sensor based on radar technology.
The advantage above a traditional PIR motion sensor is that you can hide it out of sight by placing it, for example, inside a closet.
The advantage is also that this sensor is a cheap one (~€0,45/p)
No extra hub needed, the protocol is over Wifi.
My solution
I used this sensor in combination with a compact D1 mini ESP chip to create multiple, low-priced, motion and occupancy detection sensors which also works in Home Assistant.
Click on the photos to see them in fullscreen.
Table of Contents
- My solution
- Required hardware
- Connect the hardware
- Required software
- Test if it works
- Home Assistant
Required hardware
These hardware components do I use for this project: The sensor, an ESP, wires, usb cable and a power adapter.
No extra hub needed, the protocol is over Wifi.
Affiliate links are used here. Same price as normal, but now you also sponsor this blog with a few cents.
RCWL-0516 microwave sensor
This radar sensor detect human motion and presence via doppler radar signals.
The range of this sensor is 2-5 meter.
Detailed information about this sensor.
You can buy a single sensor for around € 0,45 or buy 5 or 10 in bulk, which is cheaper per piece if you plan to create multiple sensors to use around the house.
link 2, per 5 pieces (AliExpress)
link 3, per 10 pieces (AliExpress)
ESP board
You can use any ESP board, but on this page I use the tiny ESP8266 D1 mini.
- The pins are not soldered on the board yet (with some practice even you can do it for sure!)
link 1 (AliExpress)
link 2 (AliExpress)
Dupont cables
Dupont are cables to connect the ESP pins with sensors pins. The dupont cables are in different variants: male-to-male, female-to-male and male-to-female. You can also cut one end to just solder it direct to the connector.
I used for this project female-to-female because I soldered the pin heads on the ESP and sensor.
link 1 (AliExpress)
link 2 (AliExpress)
- I advise: If you order these, you can better order all three types at ones, also for any further projects.
Case
Any case with a minimum length of 7 cm, width of 3 cm, and a height of 3 cm can be used.\
It can also be a plastic box from a local shop.
Also, a decorative small statuette can be used.
On AliExpress they also sell
Plastic DIY Cases (AliExpress)
USB power cable
A cable to power the ESP.
Micro USB cable to USB A to power the ESP (AliExpress)
5V USB power adapter
A power adapter to power the ESP and sensor.
5V USB power adapter (AliExpress)
Soldering tools
This project require some soldering, If you don’t have an soldering iron and tin wire yet check this link where to buy it.
soldering hardware
Found a dead link? Please inform me or look at ESPHome DIY sensors - Best Buy Tips for alternative links.
Connect the hardware
This table shows how the ESP D1 mini is connected with the RCWL-0516.
Connected pins | ESP8266 Wemos D1 mini pins |
RCWL-0516 pins |
---|---|---|
Click on the photos/image to open it fullscreen.
ESP D1 pin | GPIO pin | RCWL-0516 pin | cable color | description |
---|---|---|---|---|
D2 | GPIO4 | VOUT | blue | RCWL sends HIGH signal when motion detected |
GND | GND | GND | green | ground |
5V | 5V | VIN | yellow | power |
* The GPIO pin
is the port which is used in the ESPHome yaml.
I’ve made a small hole in the case for the power USB cable.
The sensor detects through the case, no holes are needed in the case.
Required software
ESPHome
The only software you need is ESPHome.\
This software is used to flash the config file to the ESP board.
Their website contains a lot of information about how to config all kinds of sensors. Also, the one we used here, a binary sensor:
Flash the script
There are a lot of ways to flash the config file with ESPHome to the board.
Read here how to upload it.
Connect the ESP via USB to the computer.
One possible way is to run python in command line:
esphome “microwave sensor RCWL-0516.yaml” run
The “microwave sensor RCWL-0516.yaml” YAML file
# Sourcecode by vdbrink.github.io
esphome:
name: esp_microwave_1
comment: Occupancy sensor
platform: ESP8266
board: d1_mini
wifi:
ssid: "XXX"
password: "XXX"
fast_connect: true # only needed for hidden SSID
# Push the data also to MQTT topics:
# * esp_microwave_1/binary_sensor/microwave_sensor_1/state
mqtt:
broker: 192.168.XXX.XXX
port: 1883
username: "XXXX"
password: "XXXX"
# Enable logging to the console
logger:
# Home Assistant integration
api:
# Sensors definitions
# See https://esphome.io/components/binary_sensor/ for all config parameters
binary_sensor:
- platform: gpio
pin: D2
name: "Microwave Sensor 1"
id: microwave_sensor_1
device_class: motion
filters:
- delayed_off: 10s # wait for 10 seconds without motion to send OFF.
# Play with this value, to find the right balance. For bed/bathroom or office it can be much higher compare to a walk through hallway.
Test if it works
Now the data is flashed, check if the sensor pushes the data correctly.
Via console
If you flash the ESP via the console and enabled logging, you see the readings in the console direct after the ESP is flashed.
Via Home Assistant
Ones the ESP is online it automatically registers itself by Home Assistant if you installed ESPHome.
You will see a new device with one entity.
Via MQTT
One way is to test, if the ESP works now, check for incoming MQTT messages (if you enabled it in the config).
On Windows you can use the application MQTT Explorer.
The sensor sends it data to the topics /esp_microwave_1/binary_sensor/microwave_sensor_1/state
Home Assistant
In Home Assistant you now have a new boolean sensor if presence is detected.
Enjoy!
Top | Homepage | Best Buy Tips