I’m trying to use a motion sensor with the Raspberry Pi but despite all the tutorials I followed, the input of the raspberry pi is always high.
Here is my code below. I used a LED to turn it on when movement is detected but I didn’t insert the code to do it yet. I’m trying first to make the motion sensor work.
I thought it was the sensors that didn’t work but I have tried with 3 different sensors so it might not be this. I checked all the connection too so it’s not the connection. The Raspberry Pi works fine with other projects so it’s not the Raspberry Pi. I don’t how to solve this. I spent almost 3 days trying to make it work.
Someone help me !
1code * (not “Image if my connections”, I wrote too fast sorry) – Menelik Nouvellon Jun 1 at 2:43
raspberrypi.stackexchange.com/questions/98371/… – tlfong01 Jun 1 at 2:50
2DO NOT post pictures – post text! Without details of WHAT you have used and how it is CONNECTED the Question is meaningless. – Milliways Jun 1 at 4:47
1ok I’ve made another post with the connections and the written code. I really need help ! – Menelik Nouvellon Jun 1 at 6:14
1But you can edit your old question here, instead of posting another new question confusing readers. Perhaps you can copy the photo there and pasted it here. By the way, the most important guy, the sensor, is not completely shown there. Is it a HC-SR501? – tlfong01 Jun 1 at 7:02
How come all my three PIRs are always on?
Because all of them are bad guys.
Try the smallest guys below. They are very good.
You might like to show your PIR and a schematic, like below.
You might also like to study the datasheet and make a summary for troubleshooting reference.
More details are in Appendix A. You need to know more details when testing and troubleshooting.
You might notice that the datasheet does not give the output voltage values for motion detect and motion not detected. What are given are current values IOH, IOL +-10mA, and corresponding VOH, VOL values (Yes, you need a have a basic idea of IOH, IOL, VOH, VOL). The reason is that PIRs are often placed far far away from Rpi, so outputting currents through a long wire, perhaps 20 meters, and causes a DC voltage drop across a resistance (Note 1) near the Rpi is the usual trick for the PIR application.
If you don’t have installed this current sensing resistor, you might have fake positives, I mean High signal, for ever.
I forgot to tell you how to check out the always High PIRs are bad guys. The trick is to use a rice bowl to cover up the bad guy. If the bad guy still says something is moving, of course he is lying.
(1) Introduction to HC-SR501 A complete step by step tutorial on Introduction to HC-SR501
(2) TaoBao HC-SR501 PIR Sensor Module – ¥3.23
(3) TaoBao DC 12V Water Proof Smart PIR Sensor Module With Switch – ¥12.80
(4) TaoBao AM312 PIR Sensor ¥5.28
(5) AliExpress AM312 DC 2.7 to 12V Mini IR Pyroelectric Infrared PIR Motion Human Sensor Automatic Detector Module – US$1.29
(6) Pyroelectric Infrared Radial Sensor AM312 (DSP, Schmidtt) Manual – NanYang SenBa
(7) PIR Sensor Description and Technical Details – AdaFruit
(8) PIR Sensor Tutorial – AdaFruit
(9) PIR Human Motion Module 10*8mm 2S delay time SB00322A-1 – Nanyang Senba Optical And Electronic, China
(10) SB312 Passive Infrared Sensor Module for Home Security System
(11) SB612 Human Motion Detector for Smart Toys From Senba Manufacturer
(12) SB412 High Sensitivity Digital PIR Modlue for Light Control Lamp
(14) Nanyang Senba Optical And Electronic Co., LtdNanyang Senba Optical And Electronic Co., Ltd
(15) How to use HC-SR501 PIR Motion Sensor with Arduino – Benne de Bakker, Maker Guides 2020Jan
(16) HC-SR501 PIR Motion Detect Producat Description
(17) BISS0001 Micro Power PIR Motion Detector IC Datasheet
(18) IR Parts Manual RE200B FL65 S211FL – GloLab
(19) Amazon Panasonic Plastic Pir Sensor (EKMC1603111, 3V~6VDC power, 12m detection range, digital output) – HK$110
(20) Panasonic PIR EKMC1603111, 102°, 12m, 3~6V enter link description here
Appendix A – Pyroelectric Infrared Radial Sensor AM312 Specification
- Working voltage: DC 2.7-12V;
- Delay time: 2 seconds;
- Blocking time: 2 seconds;
- Triggering method: repeatable
- Sensing range: ≤ 100 degrees cone angle, 3-5 meters; (according to the specific lens)
- Operating temperature: -20 – +60 °
- Anti-interference enhancement, the internal use of digital signal processing, direct high-low output.
- Repeatable triggering mode: If a cat moves in the sensing range during the delay period, and output is high, output will remain high until delay time after the cast has left, ie, the sensing module will automatically delay after detecting an activity of the cat, with the time of the last activity as the starting point of the delay time.
Appendix B – SB312 Passive Infrared Sensor Module for Home Security System
SB312 Passive Infrared Sensor Module for Home Security System
New Smart PIR Sensor Module with improved digital sensor.
This unit has enhanced delay time adjustments, with an expanded range from 2 seconds to 70 minutes. The unit includes an integral light sensor with adjustable sensitivity, the unit is suitable for outdoor and indoor mounting. Detecting length is also adjustable. The output is a standard TTL output signal, that can be used with a microcontroller or for switching lights, etc.
(B1) PIR Human Motion Module 10*8mm 2S delay time SB00322A-1 – Nanyang Senba Optical And Electronic, China https://www.asmag.com/suppliers/productcontent.aspx?co=senba&id=22978
(B2) SB312 Passive Infrared Sensor Module for Home Security System https://www.senbasensor.com/products/sb312-passive-infrared-sensor-module-2s.html
(B3) SB612 Human Motion Detector for Smart Toys From Senba Manufacturer https://www.senbasensor.com/products/sb612-human-motion-detector-for-smart-toys.html
(B4) SB412 High Sensitivity Digital PIR Modlue for Light Control Lamp https://www.senbasensor.com/products/high-sensitivity-digital-pir-modlue.html
(B5) Senbasensor https://www.senbasensor.com/
(B6) Nanyang Senba Optical And Electronic Co., LtdNanyang Senba Optical And Electronic Co., Ltd https://www.asmag.com/senba.co
Appendix C – AM312 Application Schematic
Appendix D – AM312 Setup
This PIR sensor is “plug and play”. This is no adjustments necessary. Just power and sensor is automatically set up, in two seconds.
Appendix E – HC-SR501 Adjustment Cheat Sheet
1Thank you very much for answering me ! I’ll try the AM312 sensor ! – Menelik Nouvellon Jun 1 at 12:39
@Menelik Nouvellon. You are welcome. By the way, my PIR knowledge is a bit out of date. So just now I had a quick google to catch up, as summarized in Appendix B. Please feel free to ask me any newbie questions. – tlfong01 Jun 2 at 2:01
@Menelik Nouvellon, The HS-SR501 always returns High for at least two reasons: (1) They are knockoffs or reject grade pieces, (2) the impatient newbies don’t bother to read the friendly user guide and therefore does not set the sensors properly, (say, impatient to wait for 1 minute to let sensor settle down after powering up, turn the adj know blindly, without knowing what they are doing, etc, etc. So if you are waiting for your new toys to arrive, perhaps you can read the manual and patiently try your luck again. References 15~18 are your friends. Good luck. Cheers. – tlfong01 Jun 2 at 3:02
@Menelik Nouvellon, Just now I set up the AM312 again, just to refresh my memory. As usual, there is no setup necessary, just plug and play, as illustrated in Appendix D. Please let me if you have any AM312 setup problems. – tlfong01 Jun 2 at 9:16
1Thank you so much the sensor works !!!! – Menelik Nouvellon Jun 7 at 3:29
1And is it possible to change the block time ? – Menelik Nouvellon Jun 7 at 3:38
How nice to hear the good news. Ah, I forgot you are talking about the old guy or the new guy. Pls let me know which manual you are following. – tlfong01 Jun 7 at 4:14
And I forgot to tell you that you need to read my cheat sheet in Appendix E, to check out if your module is a bad knock off guy, or actually it is a good one. If you digested and “fully” understand my cheat sheet, you might agree that the reason of many newbies complaining that their module is always high are bad stuff. Actually they are too lazy to read the friendly manual, and therefore do not know how to adjust the one jumper, two adj pots. – tlfong01 Jun 7 at 4:57
for the AM312 sensor. And also is it possible to change the sensitivity ? – Menelik Nouvellon Jun 10 at 2:47
I still have a problem. I have often some false positives (≈ 1 false positive/min) and it’s not good for my project because it has to be pretty accurate. Do you have some suggestions? Thank you – Menelik Nouvellon 2 days ago
I am hopping among a couple of forums and entertaining more than 10 questions at the same time. So forgive me if I forgot what you are doing. Could you please update you question, or compile an answer here, detailing all the details, and what have you been trying, so I can refresh my memory. Also please let me know if you are under 16, doing a school project, … then let me join in your school project website, … or you own github etc. – tlfong01 2 days ago
and I forgot if you are using 12V industrial grade stuff, no more Micky Mouse toys? aliexpress.com/w/wholesale-12v-pir-sensor.html. – tlfong01 2 days ago
And for entry level supermarket/hospital grade, try this: fr.aliexpress.com/item/…. – tlfong01 2 days ago
No, i’m doing this for me. It’s supposed to be a camera that starts filming when an animal (for me it’s a reptile) is passing in front of it (that’s where the motion sensor is useful). I bought an AM312 motion sensor and it worked better than the HC-SR501. The first sensor I had was good but too much false positives and the second one is not very sensitive (both are AM312 motion sensor). Thank you – Menelik Nouvellon yesterday
Thank you for your clarification. Your project is interesting. I forgot to tell you that beside hopping around a couple of forums, I have been reading Google alert at some 5 or 6 subjects including Rpi, and have also subscribed and reading “The Code Project Insider Daily Developer News” etc, and I am also DIYing more than 20 home automation projects at the same time, (well, most of them are on and off, stalled and resumed, much like reading 20 books at the same time but which never finished any, ..) – tlfong01 23 hours ago
I need to know more about your background, because I am not interested to share my hobbyist experience with any commercial, or would be start up project sponsors. There are also out there many elite uni grad students doing final projects who would look down hobbyists and would think that their reputation would be damaged if talking to friendly hobbyists. So they multi-post and just hit and run, never bother to reply, … / to continue, … – tlfong01 23 hours ago
I also have a home automation project for monitoring gekkos who help to eat mosquitos and cockroaches etc at home. I have been thinking of using Rpi IR camera and HX711 weigh sensor to monitor their behaviour and growth rate, but I have not been using PIR perhaps I might try later. So if you can update your question here as the first PIR selection and setup question. We can move to another new questions, perhaps how to reduce false positives etc. There are too many solutions, such as (1) take moving average, (2) digital filer, etc. / to continue, … – tlfong01 23 hours ago
Ah times up for my daily morning use of English assignment, see you later. PS, And before I go, I extract some references from my project log for my English teacher: (1) Gekko – Wikipedia en.wikipedia.org/wiki/Gekko (2) baike.baidu.com/item/%E5%A3%81%E8%99%8E/1124 (3) ol.mingpao.com/ldy/cultureleisure/culture/20190326/…, to continue, … . – tlfong01 23 hours ago
(4) kknews.cc/zh-hk/home/vkvag6q.html (5) skypost.ulifestyle.com.hk/article/2633916/…. End of references, cheers. – tlfong01 23 hours ago
The gekkos in my home from time to time make strange big noises, so I googled to find out why. I once thought of using a gekko voice activated device to start my monitoring system, I also have stainless containers with high slippy walls to trap those little things and take pictures before letting them go. See you later. – tlfong01 23 hours ago
Coming back to your false positive problem, as I said: “There are too many solutions, such as (1) take moving average, (2) digital filer, etc.”. Actually (1) and (2) and related. In your case, moving average “absorbs” the abnormal/unlikely measurement is not that appropriate, because it is better to “discard” the too abnormal/almost definitely rubbish measurement. One solution is to use multiple, say two,three or even 10 AM312 digital output PIRs at the same time, and take the “location/device average”. Just brainstorming. Comments and counter suggestions welcome. – tlfong01 22 hours ago
Last time I gave you the link to senbasesenor.com, hoping that you might find sensors suited to your application. The following may give you an idea: senbasensor.com/products/digital-pir-sensor. The sensitivity/delay parameter depends on you application. For example my gekkos are only 2cm to 5cm long, but your crocodiles are 2 feet to 20 feet long, so you need different PIR sensor modules. BTW, if you don’t know how to use a multi-meter and don’t know Ohm’s Law, never heard of moving average, not to mention digital filter, it is hard to give you any suggestions. – tlfong01 18 hours ago
Before I forgot, if you are watching crocodiles 30 feet away, you might like to consider 12V power, 5V DC 20mA output models (Yes, you can of course convert 20mA signal to 3V logic signal for Rpi). Industrial and professional guys usually prefer 20mA signals for less noise interference etc. But those 12V version are usually bulky, as shown in my answer above. – tlfong01 15 hours ago
Coming back to your AM312 PIR false alarm problem. For my gekko video project, I don’t use any moving/location average or extreme/abnormal measurement digital filtering methods, because I am using at the same time gekko voice activated, and HX711 weighing sensor, and also Montion/MotionEyte stuff. You may also like to try MotionEye.(1) HX711 Weigh Scale 1/3 raspberrypi.org/forums/viewtopic.php?p=1395602#p1395211 (2) HX711 Weigh Scale 2/3 raspberrypi.org/forums/…, /to continue, … – tlfong01 5 mins ago
(3) HX711 Weigh Scale 3/3 citywidesolicitors.co.uk/bnugrad2/…, (4) Motion – Wikipedia en.wikipedia.org/wiki/Motion_(surveillance_software), (5) MotionEye. github.com/ccrisan/motioneye. BTW, my HX711 based weigh sensors can measure in a range of 100g to 10kg, with an accuracy of less than 1%. So I can monitor the growth rate of my baby gekkos and also my microgreens. But your crocodiles are over 500 kg, so my project experience might not be shared. Cheers. – tlfong01 just now Edit