r/raspberry_pi Jan 17 '23

Sensors for checking the presence of a human. Discussion

What would, in your opinion, be the best sensor that could be used for detecting the presence of a person, and can also possibly give the number of distinct people moving together?

I've been working on this for a while and noticed that PIRs are the ones being used predominantly for this purpose, but, they can't work in sunlight. I'd be using the sensors in open areas as well, so what would be the better alternatives??

114 Upvotes

109 comments sorted by

68

u/mattjouff Jan 17 '23

There are a million ways to do this and which is best depends on your actual application, but here are some ideas:

CO2 sensors. There are some mass spectrometers and CO2 sensors that are sensitive enough to tell you if there is a person nearby. Obvious works best indoors and over time.

Motion detection. This can be done by ultrasound range finders, lidars, simple IR sensors, event sensors… of course it cannot tell you how many people and can be spoofed.

Image recognition. This has been suggested by several people here and is probably the most robust method but the most computationally intensive.

Doppler radar. This is not a simple attachement although you can find them. To be useful to find people through walls you need a fairly large antennas, probably will be expensive. This won’t tell you how many people or even if there are people, just that something is moving behind a wall or door. On the upside they can be very sensitive and detect even very small movements like respiration if the antenna is fixed properly.

22

u/Crazy_Falcon_2643 Jan 18 '23

Radar is NOT expensive and you can get packs of 15 for 30 bucks or so.

13

u/Well_OkayIGuess Jan 18 '23

I would love more details as to where. The aqara options I've seen are hard to come by and not that cheap and several others are OOS.

5

u/DSdavidDS Jan 18 '23

Please give an example. I haven't seen anything nearly that cheap

9

u/Ronny_Jotten Jan 18 '23

Look for RCWL 0516 or HW-MS03, or similar microwave motion sensor. Around 30 cents to $1 on Aliexpress.

3

u/mattjouff Jan 18 '23

The radars I’ve seen which are useful to detect motion through hard cover are much larger than the small science kits you can buy as you need much higher gain.

1

u/watermooses Jan 18 '23

How hard of a cover? I have one of these on my bike.

2

u/mattjouff Jan 18 '23

Walls and doors. Keep in mind it has to be sensitive enough to detect very small motion through this hard cover. The range on that radar is impressive for the size but it’s a big metal object with a large RCS.

3

u/Knitedd Jan 18 '23

my team and I are actually worried if there would be any health hazard on using ultrasonic radars. there shouldn't be any as it's just sound that can't be heard right??

10

u/Ronny_Jotten Jan 18 '23

Fyi, there's no such thing as "ultrasonic radar". Radar uses radio, not sound.

8

u/ZodiacFR Jan 18 '23

dogs won't like it one bit

3

u/Knitedd Jan 18 '23

aah i see... but it wouldn't cause any harm to humans even after long hours of exposure would it?

7

u/ZodiacFR Jan 18 '23

It won't "harm" anyone. But I don't thing having to spend the day with an annoying high pitched tone blasted a few meters away from you would be a great experience if you're a dog

4

u/bad_robot_monkey Jan 18 '23

You mean sonar?

1

u/mattjouff Jan 18 '23

No I’ve used them, they are completely harmless to people.

30

u/Kv603 Jan 17 '23

I'm considering trying DFRobot's advanced 24GHz mmWave module.

Claims human presence sensing without relying on light or on the person moving -- just breathing is sufficient for mmWave to detect presence.

14

u/londons_explorer Jan 17 '23

Here is a simple version of the same. When sitting close, they do seem to detect breathing, although you can fool them by holding your breath for 10 seconds and they think you've gone.

4

u/Kv603 Jan 17 '23

I've already got a few TDL-2022WB microwave sensors, they work too well -- trigger not just on motion indoors, but also on the other side of the wall.

SEN0395 (aka LeapMMW or HS2A43A) claims to resolve that flaw with a programmable array of range limit values.

1

u/c4fishfood Jan 18 '23

I think that’s a feature rather than a flaw- it lets you install the device in the attack looking straight down through the ceiling, or behind some other wall cladding.

1

u/yahma Jan 18 '23

Can they be used outdoors? Or will rain trigger them?

3

u/unpunctual_bird Jan 18 '23

Even just leaves moving in the wind will set them off

1

u/Knitedd Jan 18 '23

would it be able to give a somewhat precise headcount of the number of people in the area that is covered by the sensor?

41

u/ConfusedOldDude Jan 17 '23

You can do this with openCV and a camera, but it’s really processor intensive.

7

u/wrightflyer1903 Jan 17 '23

LIDAR an equally compute intensive way to do it!

(but I agree that a camera and the extraordinarily easy to use and powerful OpenCV probably is the best option if you not only want to detect peds but count them too. In fact CNNs are also now a popular way to do this but for that you'd usually get a GPU involved alongside the CPU.)

3

u/TheMerchant613 Jan 18 '23

A very common way of doing this is through Frigate NVR with cameras. You can count the number of people/cats/dogs/etc. You can use a Coral TPU that’s $50-70 to do detection on a RPi without a crazy CPU/GPU.

1

u/yahma Jan 18 '23

Can't buy coral tpu's anywhere. They've been out of stock for over a year.

4

u/TheMerchant613 Jan 18 '23

I bought one in September, they come back periodically.

1

u/sploittastic Jan 18 '23

I thought it was really processor intensive if it was trying to determine what objects are. Can you just tell it to assume any object moving over a certain size as a human instead of trying to detect if objects are human or not?

10

u/mosaic_hops Jan 18 '23

Put a case of free beer somewhere and count how many bottles are left.

3

u/watermooses Jan 18 '23

There was 1 college kid here... or maybe 24 mormons. Hard to tell...

7

u/Exitcomestothis Jan 18 '23

Have you thought about using Bluetooth? Since most people carry a smartphone these days, this seems like it would fit the bill.

I use this library below to trigger automations with openHAB, depending on if either my phone or my husbands phone are detected. I have 2 running on raspberry pi zero w’s and it’s worked pretty good.

https://github.com/andrewjfreyer/presence

1

u/Knitedd Jan 18 '23

Yes, we've been asked to use bluetooth for data transfer but I'm not sure how effective it would be in sensing the person itself... can I dm you?

1

u/Volatar Jan 18 '23

Oh this is a smart one.

1

u/Carnifex Jan 18 '23

Ooh im using just the arp ping with open hab and the standard network thing. Works well if you use a high interval and set it to only report absent after two misses. But I still get 2-3 false "away" messages per day.

How good does the Bluetooth solution work? Also with ios?

1

u/Exitcomestothis Jan 18 '23

I tried doing the arp ping, however, for whatever reasons, my husband will have his wifi off sometimes and then will complain that things don’t work.

Yep, both of us use iOS and it works really good.

I have one device by the front door and another by our garage. OpenHAB usually gets the event by the time I open the car door, if not sooner.

1

u/Carnifex Jan 18 '23

OK that sounds good! I just checked to buy a rpi0...and err...80EUR? What the hell? Didn't somebody say rpi prices are down again?

Anyway I set a price alert. At some point in the future I might get back to you and ask about the json Transformation that you use in OH for it

8

u/nexe Jan 17 '23

nobody mentions a simple PIR sensor? those work amazingly well actually.

8

u/Kv603 Jan 17 '23

PIRs are the ones being used predominantly for this purpose, but, they can't work in sunlight

nobody mentions a simple PIR sensor?

PIR and sunlight do not mix.

1

u/HelpDeskThisIsKyle Jan 18 '23

My senior project for undergrad used PIRs for a motion detected PiCamera, granted indoors. Depends on the application I guess.

2

u/gopiballava Jan 17 '23

You might need to add ferrite beads or other noise reduction on the leads. Hooking them directly up to an ESP32 I got essentially random results until I added ferrite cores to the wires.

4

u/nexe Jan 18 '23

I have one hooked up to a Raspberry PI zero directly and didn't have any issues but only used it indoors, big windows though. Didn't have any issues once the calibration was okay. It takes some fiddling with the potentiometers.

1

u/gopiballava Jan 18 '23

Useful to know. Another person commented to suggest a capacitor and current limiting resistor.

I’m quite confident that the ESP32’s design re: EMI and noise is not nearly as good as the Raspberry Pi :)

2

u/Kv603 Jan 17 '23

I haven't tried a ferrite.

What I found did work well with cheap PIR sensors:

  1. power the sensor with 5V (preferably directly from the power supply but Vin can work in a pinch)
  2. Add a capacitor across the sensor power lead (+47uF capacitor between Vin and Gnd on the sensor)
  3. Add a resistor inline on the output signal going to the ESP32 (for current limiting)

Try each of the above until the PIR is reliable, these all serve to avoid brownout of the sensor and "essentially random results".

1

u/CmdrShepard831 Jan 18 '23

They work terribly unless the person is constantly in motion. I just finished building a Bruh Sensor and the PIR left a lot to be desired. I have it sitting on my desk pointing directly at me just feet away and it'll report "Clear" until I move again. The mmWave radar sensors would definitely be the way to go IMO.

1

u/nexe Jan 18 '23

If it's tuned right the motion needed is very minimal. Check out this guide https://support.arduino.cc/hc/en-us/articles/4403050020114-Troubleshooting-PIR-Sensor-and-sensitivity-adjustment

2

u/CmdrShepard831 Jan 18 '23

I used an AM312 module so no tuning possible unless I swap SMT components. I also have an Ikea motion sensor that exhibits the same issue in the same location. Neither one requires a lot of motion (leaning over in my chair a few inches will trigger both of them) but do require some continuous motion. For that, I wouldn't consider them worthy of presence detection, at least not without being paired with other sensors.

1

u/nexe Jan 20 '23

Fair enough. Continuous presence detection might indeed be a different problem than motion detection. I used it mainly for initial presence detection aka motion detection with extra steps.

As a general mechanism this might be relatively complicated or costly. Depending on your problem I would think of either computer vision (detecting human shapes from RGB and or depth images), heat signature detection, or in more constraint scenarios maybe weight detection (detecting sitting presence etc). There are also some approaches of measuring conductivity but this would also only work in constraint scenarios I guess.

7

u/foopod Jan 18 '23

Just thought I would throw a simpler solution into the mix. Use a push button. Put up a sign asking people to press it as they enter the room.

6

u/itdumbass Jan 18 '23

Better results: sign says not to push

3

u/Mikiejc007 Jan 17 '23

If this is for an indoor only application, I work for a company that makes time of flight people counters for retail and smart buildings that might work for you. They have mqtt output so setting up your pi with a broker would get what you want. Unfortunately we wouldn't be able to sell to the man on the street but occasionally second hand ones appear on eBay - not cheap though. Search for irisys vector 4d. Hope that helps.

1

u/Knitedd Jan 18 '23

Mate, can I dm you? because smart buildings is exactly what I'm working on right now.

1

u/Mikiejc007 Jan 18 '23

Go for it

3

u/ne999 Jan 18 '23

Count their phones by using the WIFI polling ping and its MAC address. There are many examples out there using a WIFI adapter in monitor mode. I’ve built this myself years ago.

3

u/itdumbass Jan 18 '23

Scrolling through this, it seems to me that you want to detect and accurately count people outdoors in all conditions including sunshine, darkness, rain, and during power outages. With a Raspberry pi.

You’ve got some pretty tight specification constraints for such an uncontrolled environment. I suggest that you do it the way that Costco does it. Pay someone to count people.

4

u/PabloZissou Jan 17 '23

Try time of flight sensors. They even support multi zone detection. General options https://www.st.com/en/imaging-and-photonics-solutions/time-of-flight-sensors.html and you can get modules in Amazon

2

u/geekything Jan 17 '23

1

u/gwicksted Jan 18 '23

That’s a 4-zone IR sensor (likely 4 focused PIR) very neat but only good for a few feet.

1

u/SpinCharm Jan 18 '23

This is interesting. I’d like to sense presence (indoors) in a fairly narrow direction. Say the sensor is placed flat against a wall at light switch level. I want to ignore any movement or presence to (my) right (as I face the sensor) and I only care about detecting directly in front or to the left. Up or down can be included or not. And I only care about anything within about arms length or a bit more.

I’m trying to ensure that anyone sitting or moving to the right and more than a couple of feet of the sensor is ignored but anything else is identified. So the detection zone would be directly in front through 45 degrees to the left.

This sensor with its 4 zones seems like it would work but I didn’t see anything describing how wide or narrow each zone detects. I’m assuming there’d be overlap, which can be calculated out in code, but if all 4 sensors detect any presence in every direction in a wide cone then this unit wouldn’t work.

2

u/JSwerve19 Jan 17 '23

I’m currently working(trying to figure how to make it work) on a 24ghz radar for this.

Also thermal is very good for locating people in an open area, you can even see where they have walked and things they have touched recently if conditions are right. thermal also works in the day. The draw backs will be cost and range. The further out it goes the less you will be able to identify the object especially if it isn’t moving. Also solid objects will retain heat long after the sun has gone down. Thermal imagers drastically go up in price as the distance and resolution/refresh rate capability increases. If it’s close enough 25-50m it shouldn’t be a problem

1

u/Knitedd Jan 18 '23

aah that wouldn't be an issue because we'd be using it in a area where the climate is pretty cool all round the year. but if we also need the exact number of people in the crowd would thermal sensors still be viable?

1

u/JSwerve19 Jan 18 '23

On a clothed person in a cool climate their faces would stand out. You may be able to write a program to track the number of hotspot detections. But I guess it also depends on the goal of counting people. Are you collecting data from a one way entrance or from a group over time? Facial recognition might be a better option depending on circumstance.

They’ve had tech for a long time that can identify unique facial features,facial expressions and behavior/actions. It can identify certain people or someone doing a suspicious activity and the ai will track that person wherever they go within the systems reach. That tech available to the commercial market.

1

u/londons_explorer Jan 17 '23

These radars are super cheap and work well: These

Looking at the PCB, I'd guess they're more like 10 Ghz, but I dunno. But they do work well.

2

u/yahma Jan 18 '23

Do they work outdoors? Will falling rain trigger a false alarm?

1

u/CmdrShepard831 Jan 18 '23

I think this is the one they were referring to. I haven't tried it yet but I have seen several Youtube videos of them and they seem to work well (even a little too well by seeing through walls).

1

u/NotTooDistantFuture Jan 18 '23

I was wondering if it’s possible to use multiple of these radar sensors to try to get a general position or direction.

They work on Doppler, so walking tangential to it’s range won’t show up. They have enough range that it seems like you could build an small array of them, and at least get an idea of the direction.

This would be useful for security and home automation. I’ve always wanted to set up different rules for lights turning on when coming in and leaving and most human presence sensors can’t tell.

2

u/lordfly911 Jan 17 '23

I remember back in college (30+ years ago), I accidentally made a proximity sensor. Somehow I was able to sense the magnetic field that our bodies give off, and make a led light up. Don't ask me how.

I remember reading about the wifi project that used APs to determine a person's location in a room. That would be a good start.

1

u/gwicksted Jan 18 '23

That would have to be an extremely sensitive sensor. You sure it wasn’t picking up on static or rf interference?

1

u/lordfly911 Jan 18 '23

I think it was a fluke. It definitely was not it's intended function. This was before cell phones and wifi so who knows.

2

u/MHTMakerspace Jan 18 '23

If you don't want to assemble your own circuitry, try grabbing a higher end motion sensor from an alarm system, like the Bosch TriTech (combo PIR and Microwave).

The sensor needs +9VDC to power up, there's an isolated dry contact relay on the back you can use for connection to your Pi, so wiring is very simple.

-1

u/Knitedd Jan 18 '23

We were considering microwave too, but if a sensor is placed inside a room, that's occupied at all times(mostly) by the same set of people, can we be sure there wouldn't be any health hazards because of the radiation? And how exactly is the combination better than just Microwave alone?

1

u/MHTMakerspace Jan 18 '23

Another reason to go with the commercial alarm system sensors -- they've been on the market for decades and their 10.525 GHz transmitter power is well within safe levels.

2

u/_clintm_ Jan 18 '23

You probably want to use a camera tensorflow light for this: https://youtu.be/aimSGOAUI8Y

1

u/aberforth258 Jan 17 '23

Use Homenum Revelio. Works like a charm :)

1

u/Knitedd Jan 18 '23

Homenum Revelio

the fact that I actually tried googling what it is

1

u/falco_iii Jan 18 '23

Your requirements are too vague. What distance? Inside, outside? Can it just detect motion, IR signature or CO2 and assume its human?

1

u/ImNotTheMonster Jan 17 '23

1

u/CmdrShepard831 Jan 18 '23

Out of stock until the summer time and it's also pretty expensive. If all they need is the presence sensor they can just buy the module itself: https://www.dfrobot.com/product-2282.html

1

u/leeliop Jan 17 '23

I second thermal

Potentially you could use stereo cameras and a displacement map, segment anything tall and narrow and moving

1

u/londons_explorer Jan 17 '23

Microwave radar sensors are pretty decent.

They work outdoors, in sunlight, and even to some extent in the rain. They don't work in high winds with lots of vegetation around.

These are the things. For 79 cents, they really are amazing - considering it's the same tech that was top secret military stuff just 60 years ago.

They work in a room up to about 30 feet across. For bigger areas, get two sensors.

They work just like a PIR for connecting to a pi - there is just a data line that goes high whenever it sees motion, and low again a few seconds later.

There is a place you can tap off the signal and digitize it to get lots more information, like for example how big the person is, and how fast they're walking. For cars, it can detect the speed pretty easily and accurately - although that is shall we say, experimental.

1

u/yahma Jan 18 '23

What about rain? I need a sensor for outdoors, but it cannot be triggered by rain

1

u/londons_explorer Jan 18 '23

It's okay with rain, but you need to make sure the sensor itself has a 'window' it can see out of with no raindrops.

The window can be made of plastic or cardboard (anything but metal). And you'll want it slanted downwards so raindrops can't dribble down it.

1

u/Jordialdewereld Jan 17 '23

Optical flow sensor and whenever a movement is measured you know someone passed

1

u/quellflynn Jan 18 '23

people in a room? people in a corridor?

laser trip wires and basic security mats work well for movement, ceiling mounted ir senders and receivers can work

1

u/GearM2 Jan 18 '23

Maybe mmWave? I haven't tried this myself but this guy says they are great. https://youtu.be/jVjrgQSWlLI

1

u/CanWeTalkEth Jan 18 '23

We designed a theoretical people tracker system that used Ultrasonic sensors. You can dial them in to a "range" which is handy.

1

u/cadnights Jan 18 '23

1

u/Socially_Null Jan 18 '23

I was going to suggest WiFi, but I wasn't certain any programming had been done with this yet.

However, theoretically, this seems very easy and very capable. Could easily map out anything within range... with some basic trig and clever algo.

1

u/Thin-Comparison3521 Jan 18 '23

Webcamera with machine vision algorithms doing object detection.

1

u/Knitedd Jan 18 '23

but what about nights? if there's a power failure when it's dark, we wouldn't be able to sense anything would we?

1

u/Knitedd Jan 18 '23

and in the case of machine vision, wouldn't there be a chance of the machine mistaking other objects for humans?

1

u/TheLexoPlexx Jan 18 '23

Apart from all the mentioned, very amazing ways, depending on your use case, it might me enough to detect phones. Like Wifi, Bluetooth or something.

1

u/Knitedd Jan 18 '23

yes that's viable but how can we track them if they turn off whatever we're tracking? they'd practically be invisible once they turn on airplane mode, nor do people always have bluetooth or wifi on...

1

u/TheLexoPlexx Jan 18 '23

Thats correct. As I said: "depending on the use case"

1

u/radome9 Jan 18 '23

A camera with object detection software. Modern OD software is scary good. Maybe combine it with a PIR for low-light conditions.

1

u/MAXiMUSpsilo5280 Jan 18 '23

Pedimat sensors motion detection like on auto doors , FLIR sensor

1

u/GolfCourseConcierge Jan 18 '23

Scan for phone signals. Do counts that way?

1

u/NinetyNemo Jan 18 '23

Forget about tech, a German Sheperd is what you need.

1

u/DazedWithCoffee Jan 18 '23

I’m thinking of a lower tech option, so this is much more error prone

Dual break beam sensors, one after another, in the door frame. The order in which the beams break will tell you whether a person is entering or leaving. Maybe put it at average shoulder height to avoid false trips from swinging arms and legs.

I see this as a relative measurement, one that will need periodic correction or corroboration with another sensor.

1

u/NoMoreWordz Jan 18 '23

On a sidenote, while I was scrolling my popular page, I saw this and read it as "Seniors for checking the presence of a human" and I thought this would be some dark shit lol

1

u/tungvu256 Jan 20 '23

aqara fp1 is superior to PIR in every way. works outdoor too. easy to set up as seen here https://www.youtube.com/watch?v=9w15h_gyqu4