Got myself a HC-SR501 passive infrared sensor from ebay for less than 5€.
As information about this sensor is hard to find but usage is pretty easy I thought I share my findings.

HC-SR501: Left poti is to adjust sensitivity. I have set it to medium. Right poti is to adjust the delay. I set it to minimum which means it triggers about every 5 seconds.

On the bottom are the connections for 5V (left), signal (middle) and GND (right). I tried around with the jumper on the top right, but couldn’t really tell a different behaviour.
I thought the signal pin delivers an analog value according to the distance so I added a LED to pin 11 for the output. This was the initial setup:
#define pir A0 #define led 11 void setup() { pinMode(pir, INPUT); pinMode(led, OUTPUT); Serial.begin(9600); } void loop() { int i = analogRead(pir); int l = map(i,0,1023,0,255); Serial.print(i); Serial.print(" / "); Serial.println(l); analogWrite(led, l); delay(100); }
I realized that the value I was reading at the sensor pin was always around 680 not matter what.
I then went on to change analogRead to digitalRead:
#define pir A0 #define led 11 void setup() { pinMode(pir, INPUT); pinMode(led, OUTPUT); } void loop() { digitalWrite(led, digitalRead(pir)); delay(100); }
And it worked too… but I think going forward I will use analogRead and will react to motion once the value delivered by the PIR is higher than 500.
Pingback: Spycam with Arduino / Digispark | Hacking – DIY and Coding
i am stuck using this sensor for one of my projects, and i will be using a 5V DC input, and as im new to coding in C would you be able to tell me what the H and L pins are required for? and according to your post, the o/p can be either analog or digital? :s
Shemi, I’m guessing you are referring to the jumper pins L and H.
On http://www.aliexpress.com/store/product/5PCS-HC-SR501-Adjust-IR-Pyroelectric-Infrared-PIR-Motion-Sensor-Detector-Module-LHI778-Free-shipping/200314_570581413.html it says that if the jumper is set to L the detector triggers only once. If set to H it triggers continuously. Setting H is default and I would recommend leaving it that way.
how to set it in H trigger….?
Could you please measure the quiescent current of the device. On ebay http://www.ebay.de/itm/Sale-1-PCS-Pyroelectric-Infrared-PIR-Motion-Sensor-Detector-Module-HC-SR501-ER99-/121088083675?pt=AU_B_I_Electrical_Test_Equipment&hash=item1c316986db it is given with:
Static power consumption: 65 microamps
This is hard to believe. I want to use the device as a proximity sensor with battery.
Thank you.
I have got one and thanks to this post I was able to power it because there no pin markings on my module. I have measured the current. At 5 V It uses about 40 uA in static mode and about 150 uA when there is motion. Signal pin was disconnected.
Thank you, Domas!
Hi, i’m a novice with this.
How can I know to limit the distance or range of measure? thanks
Man, please look at the caption of my first picture. It’s the left poti that you have to play around with.
Hi, thanks for the tutorial, it works!
I’m a newbie of these and I have a question about the code. Is there anyway to make it output “1” when the sensor senses an object (instead of just lighting up the LED). This sensor is used in a sensor network and we need to gather the information it gets (the LED output can only be read by people but not PC).
Please help! Thanks a lot!!!
Hi Jane
what do you mean by “output 1”? lighting up an LED is nothing else than writing a “1” to an output pin.
I mean to have it output “1” in the monitor in the arduino software, so that if I sees a “1” on the screen, I know there is an object. The code you provided is very concise so that I have no idea where to add a println statement. Could you please help?
Jane, just make sure you add
Serial.begin(9600);
to the setup() function.
and then the loop() should look like
void loop() {
int val = digitalRead(inPin);
if (val == HIGH) {
Serial.println(“1”);
} else {
Serial.println(“0”);
}
}
NOTE: This is untested! You probably need to adapt this.
It works! I added a delay and it’s perfect! Thanks!!
hi, my project using this sensor model. but i use PIC16f as it microcontroller.. do u have sample coding for this pir sensor using pic16f?
No.
Actually the PIR outputs a digital signal no matter how much movement there is. Its either a 1 (movement detected) or 0 (no movement). So, analog is of no extra use here.
P.S: My PIR came without markings of 5V or GND or Trigger pin. Thanks to your pics I was able to figure it out.
Thanks so much for this! I finally got around to trying these things out, and this made it very simple to get it started! I’ve got a really unnecessary but cool project planned, using 2 PIR sensors.
Thanks again!
You can find a nice tutorial for this sensor here : http://www.elecfreaks.com/wiki/index.php?title=PIR_Motion_Sensor_Module:DYP-ME003
Phil
thanks for the additional info!
im new to all dis stuff. can u plz tell me how to make robot? thnx
sure!
Hi
You set the poti to minimum which means it triggers about every 5 seconds, and it really too slow for my needs.
Is it possible to trigger the sensor every 1 sec or even less?
Did you try?
thanks
Ben
Sorry, I guess it’s the minimum for this sensor. Not sure about other sensors out there.
Thank you so much!
I’ve been thinking that my sensor is broken. I always got xxx number from it and never ZERO.
Sooo…
The problem was that instead pin = 0 i should use pin = A0.
I think it listened the wrong port!
Thanks again! 🙂
why do we have so many numbers in the answer
42?
no there many numbers. the numbers went up to 1223 and the lowest is 420
miranda, those are analog values from the sensor.
the code in the loop function is being executed for ever. this means – and because of the delay(100) statement – that you will get 10 readings from the PIR sensor per second.
Hello! I like this page it’s very useful!!
I just want to share this store, where you can get the HC-SR501 PIR Motion Sensor for a great price: http://voltatek.com/en/sensors/69-motion-sensor-module-hc-sr501-pyroelectric-ir-infrared-adjustable.html
Hi. I’m having a problem with my HC-SR501 Sensor. I am getting 3.3V on the signal pin all the time as soon as I power it up. It doesn’t change during the power up sequence or ever after. What could be wrong?
I just tried a backup unit and it works fine so I guess the one unit is defective? Guess you get what you pay for 🙂
Hi Glen.
So, Is it possible to power HC-SR501 with 3.3v and it works?.
It seems that a power supply of 5v are indicated in all datasheet i have found.
Hello and thanks for the concept code. I am so going to scare the hell out of my neighbours cats when they enter my shed to do their needs. Just need a Nano, some tweeter, a led strobe…
Hey Roman,
I want to bridge the button of the remote control GoPro to make a video when something moves, and stop when no more moves.
The Digispark / Arduino should control an optocoupler to “press” the remote control button.
How can I get a impulse (200 ms) from the Digispark / Arduino when motion is detected?
And again a pulse (200 ms) when no movement is detected to stop the recording?
Thank you very much! 🙂
Hi Steffen
Sorry, I have no idea on how the gopro remote works.
This has nothing to do with the remote.
Pingback: DuinoLab Starter Kit #14 : PIR Sensor (Motion Detector) – DuinoLab.com
Hi everyone, help me please, I bought this sensor and the 5V relay, but sensor TRUE is the 3.3V and relay not working, I tried connect the 2n2222a transistor (E – relay, B – sensor 3.3V, C – 5V), but the output of the E is same 3.3V, what I do wrong, I need the 5V output on the TRUE
Hi I have the SR501HC only,there is not interface I need to say what pin is gnd, vss and data. I search in the datasheets but I did’nt find it.