PIR Notes

Active today
Viewed 16 times

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 !

Thank you

Image if my connections the code

share  edit  follow  close  flag
 New contributor
  • 1
    code * (not “Image if my connections”, I wrote too fast sorry) – Menelik Nouvellon 5 hours ago
  • 1
    DO NOT post pictures – post text! Without details of WHAT you have used and how it is CONNECTED the Question is meaningless. – Milliways 3 hours ago
  • Hi @Menelik Nouvellon, Welcome and nice to meet you. Ah, let me see. I quickly read twice your question’s three short paragraphs which describe succinctly what you have researched, the problem you encountered, your troubleshooting procedures, and your deduced conclusion, which I think is very reasonable. I have been answering perhaps more than twenty interesting questions like yours in the past two years. What is common in those interesting questions is what is reflected behind, the sorrow of problem solving newbies, … Ah, lunch time. See you later. Cheers. – tlfong01 2 hours ago
  • ok I’ve made another post with the connections and the written code. I really need help ! – Menelik Nouvellon 1 hour ago


How come all my three PIRs are always on?

pir 1


Because all of them are bad guys.

pir 2

Try the smallest guys below. They are very good.

pir 3

You might like to show your PIR and a schematic, like below.

am312 pir 1

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.

am312 pir 2

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


Appendix A – Pyroelectric Infrared Radial Sensor AM312 Specification

  1. Working voltage: DC 2.7-12V;
  2. Delay time: 2 seconds;
  3. Blocking time: 2 seconds;
  4. Triggering method: repeatable
  5. Sensing range: ≤ 100 degrees cone angle, 3-5 meters; (according to the specific lens)
  6. Operating temperature: -20 – +60 °


  1. Anti-interference enhancement, the internal use of digital signal processing, direct high-low output.
  2. 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.

am312 pir 1

am312 pir 2

share  edit  delete  flag

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: