Newbie stuck with pir sensor

Hello everyone ,

I am, a starter with arduino , using a uno3 compatible board. I ama good enough programmer without a electronic background..

recently I bought a pir sensor and tried experimenting with it. My expectation was to see a high or low when I am I front of it and opposite when I move away. How ever when I print the state to serial, I see high for a few seconds then low for few seconds and so on. It keeps alater aging by itself even when there is no subject I front of it.

Am I to do some adjustments or is this simply a defective item ?

pir sensors detect CHANGE.. they slowly recover to ambient..sounds like its working just fine..

Turn the “time” pot fully anti-clockwise, so the ‘on’ time is very short (a few seconds, not 7minutes).
Leaven the “sensitivity” pot in the middle.

Let Arduino extend the “on time” if needed.

PIR sensors detect MOVING warm objects between the segments of the fresnel lens that is covering the sensor.
That could be a human being, or cat, or the rising air of a heater.
They are very sensitive (>7meters).
AFAIK the sensitivity pot has nothing to do with range, but with how many detections are needed to change the outut to high.

Thank you I will try that and post back. But for more Info I also observed that after leaving it alone for any amount of time, when I go and move infront of it it detects nothing not even in close proximity. The alternating blocks of high and low continues. Only when I hold it in hand it goes to low till I keep it back.

Hi Rajdee,

Awesome that you're getting started with Arduino things! Welcome!

Can you post the model of PIR you have (or a datasheet), and your circuit?

A few things to try:

  1. adding a resistor to your circuit (10 k ohm), if you haven't already

  2. limiting the field of view of the PIR by putting it in a small box (that way you can be sure it's responding to your moving hand, rather than other moving things around it, like your body)

Perhaps you've already stumbled across these, but they're good resources:

Good luck!

I am back from some testing. i am lost i must admit and feel stupid. I bought 2 more sensors and they are also acting in the same way. either all are defective or i have no clue to what i should be expecting.

Here is what my console output:




int pirPin = 2;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;
int val;


void setup(){
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);


void loop(){

  val = digitalRead(pirPin);
  if(val == HIGH)
    Serial.println(" HIGH");
    Serial.println(" LOW");



So whether i stand in front of sensor or not it does not matter ? Then how does it work ?

Your code looks fine.

Can you share a diagram or photo of your circuit?

Try covering the PIR sensor for the first 30 seconds after pressing upload-- during this time, I think the PIR calibrates itself.

There is one led one Buzzer (out of the photo) and one PIR sensor on my board setup. Sorry if it looks confusing. Its very basic actualy. Just the first two image should be clear enough.

I simply don't understand what i am doing wrong.

Pir is connected to vcc- 5v (red), GND - GND (black), out - pin2 (brown - green)

Try connecting your PIR like this.

Well its almost same except that i don't have a 10k resistor. Is that a mandatory item ?

I will try and check back.

This module does NOT need a 10k resistor.

Remove the breadboard and the ratsnest of wires.
Connect the 3 pir wires directly to +5volt, ground, and a digital input.
Use the onboard LED (pin13) or the serial monitor as indicator.

Make sure you stand very still when testing.
Moving a finger will trigger these sensors.

P.S. Always use a current limiting resistor with a LED.
I don't see one on your breadboard.

So whether i stand in front of sensor or not it does not matter ? Then how does it work ?

Can you post a link to the actual sensor you are using. ?

pir sensors detect CHANGE… they slowly recover to ambient…sounds like its working just fine…

Sounds right.

Need detail of the sensor you are using.

I have exactly the same PIR detectors. They usually work faultlessly and are very reliable. I’ve had a pair of them running for about a year now without problems.

They’re different to the one shown in Brayd’s link. They are not open-collector and, as pointed out by Wawa, don’t require a pullup resistor.

The output signal is 3.3V, active-high.
Operating voltage range is 4.5V to 20V.
Calibration time after powerup is about 35 seconds with these units, so in my firmware I wait 40 seconds before reading the PIR pin. There is no need to cover the module during this period. (That might negatively affect the calibration.)
This is the (pidgin English) info from the eBay listing:-

The automatic sensor: to enter the sensor output range is high, people leave the sensor range of the automatic
delay off high, output low.
The photosensitive control (optional, factory is not set) may set the photosensitive control during the day or
light intensity without induction.
The temperature compensation (optional, factory is not set): In the summer when the ambient temperature rises
to 30 ~ 32 ℃, slightly shorter detection range, temperature compensation can be used as a performance compensation.
Two trigger mode: (can be selected by jumpers)
With induction blocking time (the default setting: 2.5S block time)
Micro-power consumption
The output high level signals

Product Type: HC–SR501 Body Sensor Module
(BSS0001 IC)
Operating voltage range: DC 4.5-20V
Quiescent Current: <50uA
Level output: High 3.3 V /Low 0V
Trigger: L can not be repeated trigger/H can be repeated trigger(Default repeated trigger)
Delay time: 5-200S(adjustable) the range is (0.xx second to tens of second)
Block time: 2.5S(default)Can be made a range(0.xx to tens of seconds
Board Dimensions: 32mm*24mm
Angle Sensor: <100 ° cone angle
Operation Temp: -15-+70 degrees
Size:3.2 x 2.5 x 2.5cm(L x W x H)
Net weight:7g

Here’s a clearer pic of the back of one of one of the boards that I have, for comparison:-
Pins, left to right are Vcc, OUT, GND.

Yes thats the one. thanks for the details. so then i tried this :

same connections and using hr program given on that page: OUTPUT

upload pics

You seem to have a long breadboard.
Long boards like this could have split power and ground strips.

I have already tried 3 sensors. some people say on this forum its normal. i don't understand how that could be so. If its really going to do all that by itself where si the trigger ? i just got started with this stuff and simple stuff like buzzer beep / led light up etc work just fine. But PIR sensor is not something I am understanding.

Edit: i will remove breadboard from the equation and try again.

WOAH believe ti or not it works as i expect when i get rid of the breadboard.!!!! YIPPEE !!. So one question is it that bread board is faulty ? or something else ? cause when i need to multiplex stuff i will need breadboard. what to do then ?

Ok i understood your point and i checked some things on the board for my knowledge. Thank you very much to everyone on this forum for helping me getting started on arduino. thank you for The product specs, for the troubleshooting and everything. Arduino rocks!!

Don’t forget to have your program wait for at least 40 seconds on powerup for the PIR detector to calibrate, or you will get false triggers.
(I had said more, but was mistaken so deleted it. :slight_smile: )