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

I agree with the original poster: the HC-SR501 gave falls positives even under a cup.

I’m soon trying the AM-312.

Found a good fix. Soldered a small 220nF ceramic capacitor from Pin 12 to Pin 13 of the BISS0001. Running 5 HC-SR501 for 1 month with this mod and no more false-triggers so far.

16 Likes

Interesting mod space_r… never seen that one before. I do have lots of spare 501’s in my box, and plenty of caps. I might have to give that a shot myself. Thanks for sharing!

Where did you find that anyways? Did you engineer that yourself? I’m curious to see the work done to derive that mod. I love reading stories of curiosity, oscopes, and blue wires.

I found this tip in an electronics forum. Unfortunately I can’t find the page anymore.

I have tried many things before. Backing capacitors, shielding, short cables. Nothing worked. Especially the small unshielded ESP01 caused a lot of problems.

Must admit, I live in the country. Not many WiFi networks in the neighbourhood. My access point is a ubiquiti and runs on channel 6 or 11.

I run some HC-SR501’s with 3.3V, others with 5V. They work reliably so far.

2 Likes

I’ve also tried running at 3v3 and 5v… for the life of me those 501’s just never worked reliably. It also could be because the small form factor of the devices they were used in. The PIR’s in these devices have to be within 1cm of the esp modules.

The 312’s have just been way more reliable for me, but like I said I am still interested in salvaging my 501’s using that cap trick you showed us. I’ve got plenty of 220nF’s 0603’s laying around to try it.

On an unrelated side note, if the form factor doesn’t have to be very small and you have room to mount a sensor about 6" from the esp, the rcwl-0516 sensors are very good! I just got a batch of 5 sensors for $9 delivered on amazon. I’ve got them running on a test esphome board and so far so good. I’m running it along side a known reliable am312 device for comparison, and so far they are in agreement (ie no false triggers). These sensors have many advantages, especially that they can be used outdoors and still work reliably.

Hi truglodite

Run my 501’s with cable lengths of 5 - 20cm on breadboards. After successful test operation the connections are then shortened and soldered.

I am interested if the 220nF mod works for you. Let me know.

I’m gonna order some of those 312 motion detectors to test as well.

Also experimented with the rcwl-0516. Combined with the PIR, they make a perfect pair for reliable presence detection.

I built a test circuit with addressable LEDs as status indicator for each sensor. The LEDs give immediate feedback and help to fine tune the system.

ESPHome makes everything so easy. Awesome!

3 Likes

So far my rcwl testing is going great. I can see the use of combining both pir and radar… I think Bosch makes some motion sensors that have both as well.

1 Like

Hi Space_r,

can you please share more details? Sounds very reliable if pir and body sensors work in synergy.
Did you finish your project?

br

Hello xeac

I use the PIR to turn the light on and the radar sensor (rcwl-0516) to turn it off.

The PIR is pointed at the door, the radar sensor points towards the room. Because the radar sensor is so sensitive it works very reliably

1 Like

hi Space_r,

thanks for your feedback.
i am not familiar with the body sensor features, so i am wondering if i can combine it with outdoor pir and camera for kind of security system. May be not a good idea as it will detect every single move of an object… will try

I tried the rcwl-0516 (microwave sensor) a couple of years ago, with lots of false positives much like I experienced with the HC-SR501 which I presume is interference from the WiFi Signals when used with an ESP8266. I tried some of the possible solutions mentioned in the comments in Scargills Tech Blog, without much success: https://tech.scargill.net/microwave-radar/

I have been using the AM-312 for the last couple of years with much more success, although it doesn’t have the detection range or adjustment like the HC-SR501.

@space_r I would be interested to see your ESP-Home and home assistant config. I’ve seen commercial alarm movement sensors that combine PIR and Microwave and would like to improve reliability by replicating these.

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?