HC-SR501 no good for ESPhome... change the docs?

The rcwl sensor works well with a step up converter at 11V or so (like the mt3608). See this thread for a good discussion on the subject of rcwl false positives in general:

A step up converter, and a few inches of separation works well for me.

I think implementing pir+radar logic on esphome would be easy. The hard part would be optimizing the logic for the location and all of it’s environmental quirks. Radar’s big downfall is the lack of controlling what areas are sensed. So motion through walls can cause problems. PIR sucks when it comes to outside work; sun, heat, and shadows can make them useless for some locations.

Using radar and pir can help to balance some of those shortcomings, but there are some use cases where even dual sensors won’t work (hot area with motion behind a nearby wall for example). There is always video motion detection, but that can be pricey.

What would great is a reasonable way to “aim” the rcwl sensor to ignore some vectors… make it directional, rather than omni. I’m no microwave engineer by a long shot. Every experiment I’ve tried (assorted metal reflectors at varying positions) results in false positives. I figured it works for wifi (like cantennas) so why not try it. These rcwl devices aren’t as easy to work with.

2 Likes

A friend found this simple fix for the HC-SR501. I’ve tested it and it seems to work well so far.

Connect PIR sensor to NodeMCU using 3.3V (HC-SR501)

4 Likes

I have done that to a few battery powered devices, and it works great. Besides allowing a 3v3 Vcc, it also gets rid of the quiescent current of the built in regulator. Not that it was much to begin with, but every drop counts with batteries.

I too suffered terrible false positives with sr501’s in small boxes with nodemcu’s. My solution: rotate the nodemcu so that the esp chip is pointed away from the motion sensor. Then, turn down wifi power to 10db in esphome. No more false positives for me. And I have seven of them here.

3 Likes

I have already successfully installed a couple of AM312s and are in use. In my current project, the distance to be recognized is too far for the AM312.
Now to my question:
Can I install a SR501 with a distance of 20cm to the ESP so that I have no problems?

Maybe good to inform you about the truth of PIR sensors that help to eliminate the problems that are commonly known with these small units.

To start, the PIR unit basically consist of two critical elements: the piezo electric sensor that senses infrared energy and second electronics circruitry that enables differential detection of infrared energy changes followed by either simple or advanced evaluation circuitry to judge detection or not.

The sensitivity of the sensor is such that only just microvolts of amplitude variation will be passed to the circuitry that is designed to judge “movement detection” or not. If you look at the module from pure technical point of view, it isn’t detecting movement but it detects “changes in the infrared light spectre”. Sudden changes are usually caused by persons that dissipate “heat” from body temperature which is noted when passing a sensor due to the fact that it causes a sudden change in this infrared energy in the detection area.

However, due to the technology, not only persons will be detected. In the case where sudden temperature changes (1 tot 2 degrees will do already) happen, a sensor circuitry may already give so named positives. The “intelligence” of the differential evaluation often is a prime selection criterium for the right sensor in your application. In all cases, it is advised to position the sensor such that no sudden temperature changes are to be expected such as a window or drafty position.

Another point to give serious attention is EM field sensitivity. As written above, the sensor element reports changes in the infrared spectrum with utmost small voltage variations that are in the microvolt range of which the evaluation circuitry needs to decide whether it is a detection or not. Many (cheap) PIR units are positioned close to RF radiating elements (such as wifi) or use long power / data leads that easily pickup electromagnetic energy that cause small voltage variations near the sensor element or circuitry as well. If sudden changes here are notified by the PIR unit (such as a wifi databurst), it may cause false detection. In PIR technology, often “noise” is named as cause for bad detection quality. This noise is not only caused by limited filtering of the evaluation circuit, but also EM disturbances. Actually, there are quite some aspects that influence the total behavior of a PIR unit of course. A further cause of noise is often a microcontroller, causing small switching voltages in IO lines that may already influence a PIR and last but not least the power supply noise may be of influence.

I have studied several PIR units and learned that almost none of them take care of EM filtering in an adequate manner. This is not a big problem when no EM field disturbances are to be expected. When the PIR units is meters away from the (in this case ESP) RF unit, it will work reasonably well. When this is not possible, measures have to be taken. For example, the HC-SR505 PIR unit is great due to small size, but it brings not only very simple evaluation circuitry, but lacks any kind of EM filtering. The 8-pin chip, for example, outputs the detection line via the output pin only via a 1kOhm resistor. There is no filtering whatever that eliminates EM radiation. In cicruitry that evaluates micovolt variations, this is killing.

A third thing to be aware of is light on/off switching. Since an artificial light also radiates infrared energy, the area will undergo a sudden change when light is switched. This is normal and cannot be prevented. Only very advanced PIR units with DSP / asic evaluation circuitry may “recognise” the pattern that light switching causes in the infrared field, which basically differs from a person moving. Simple circuits that we use can normally not differentiate between various types of changes in infrared energy, so don’t waste precious time in trying to eliminate that, you have to take that for granted.

EM radiation can be eliminated very well, but knowledge of RF technology is of importance. Moreover, EM filtering potentially requires additional circuitry which is contrary to the desire to keep things small.

Usually the test setup in your ESPhome isn’t ideal as the unit is subject to all kinds of sudden events that cause false triggering. Main items to keep in mind will be temp variations (just blow to the circuit to test it) and EM susceptibility. Now, what to do to have a reasonably fair PIR element:

  1. Limit temp variations

As said before, position it in a place where sudden temperature variations (within a couple of seconds) are not to be expected. Slow variations are fine as the circuit measures differential voltages in a window comparator or digital equivalent of that.

  1. Minimize EM field sensitivity:
  • The easiest one is to position the PIR unit as far away from an ESP or other RF device as possible, duh.
  • position ferrites on the three wires to accomplish a basic RF filtering
  • You may create RF shielding arount the PIR unit by encapsulating it into a metal box. Most important here is that the grounding of the metal box with the ground of the PCB is handled adequate. If done wrong, the metal case may act as antenna rather than RF block.
  • You may further filter the power supply and detect output wires with a so calles Lowpass (Pi) filter as close to the circuit as possible, consisting of at least a capacitor of a couple of Pf’s between the power supply / detection output lead and GND as well as an inductor in series with it. I would start to use 100pF and 220nH as this has a cut-off frequency of about 80MHz, which should eliminate problems enough.
  1. minimize voltage ripple

Minimize voltage / data ripple on the leads. This can be done in its simplest form by eventually adding a ~100 of 220uF electrolytic capacitor over the voltage line and GND, again as close to the circuit as possible.

If handled well, the measures of above will significantly improve the performance. I suggest to test these suggestions one by one, starting with the first. Most of times, you don’t need to implement all to have a reasonable behavior.

Good luck!

5 Likes

20cm? A guess off the top of my head I’d say it will probably work. The only way to know for sure is to test. Usually folks who have issues with wifi and sr501’s are attempting to locate them much closer to the esp device… like within 1". The energy contained in a radiated beam of energy (wifi included) follows the inverse square law. So the noise at 8" distance is going to be ~1/64 what it would be at 1". If it still falses at 8" away, that is a lot less noise to have to filter out. So then things like ferrites, pi filters, etc will be that much more effective than they would be at 1" away.

In general, I’d say start with designing as much distance as possible with the application… then if there are problems either use a filter, or if the application allows use a pir that has better filtering (like am312). In your case, 312 is a no go, so start with as much distance as possible then add filtering if needed. For filtering, start simple then go up… ferrite first, then lowesr C, then add a C+L for a pi… in that order.

1 Like

this is the solution for me too, works great at the moment. thanks

1 Like

Hi, what’s the range for the rcwl-0516?
Could it cover a small room for presence detection or depends on the angle where you’re pointing the radar sensor?

No, it detects only motion :bulb:

1 Like

I just wanted to point out that the RCWL-0516 sensor is not really directional, and can even detect motion through walls or doors, so it may not be suitable for presence detection in a specific room.

This resource here may give you some ideas of the sensor’s capabilities, including how to tweak range and signal length: RCWL-0516 microwave radar motion detector • Wolles Elektronikkiste

Just went with a regular full size ceramic capacitor as I had no surface mounted, works great and saved my project. Thanks for sharing this valuable info. I also sent a mail to the guys from ESPHome so eventually they will add this info to Passive Infrared Sensor — ESPHome !

Saved the day !

2 Likes

You can click the Edit this page on GitHub llink at the bottom of any documentation page to make changes to submit a PR :smiley:

I have to retract my recommendation here. I had two sensors that I did all the mods (capacitor, distant from esp, ferrite cores on each line) on and they still were noisy. I switched to AM312 sensors and they have been flawless so far, and seem to work just as good.

1 Like

This is a really interesting discussion. I am < 24hrs into my first PIR build with a HC-SR501 and all the false positives brought me here.

Since I am using POE I had no wifi definition and the PIR was still flapping. Even after Dremeling off the PCB antenna. Disabling wifi on_boot has made the flapping completely stop.

1 Like

Great wording. :smiley:

My case was just a liiiiitle too short and who needs that pesky antenna anyways :wink:

Interesting development worth sharing.

I added a second mmWave sensor to my POE mmWave+hc-sr501 deployment and the PIR really didn’t like that. Probably because the PIR was right beside the mmwave sensor.

This video had an interesting solution by bypassing the voltage regulator and powering it from 3.3V.

This worked really well for me.

When using 5V the PIR would phantom trigger in sync with the second mmWave. Powered by 3.3V it no longer does that.

1 Like

Plus 1 for the idea of bypassing the voltage regulator and going straight to 3.3v. I have 3 of these sensors 2 running on 5v volt and 1 on 3.3v. The 5v sensors give false positives at least twice per day whereas the 3.3v has now gone days without a false positive.

2 Likes

AM612

seems to run pretty darn good