PIR trouble trouble

Hell all, I'm messing around with a basic PIR sensor. The challenge I'm having is getting it to work properly. All connections are secure and PIR seems to get completely random input. I cover it up completely and sometimes it detects motion and sometimes it doesnt. I dont cover it and it will not detect motion at times and other times it will. I've adjusted the sensitivity and delay on the module and there seems to be no correlation. Module is brand new out of the package. Any experts out there have any thing I need to try?

 * PIR sensor tester
int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;

Do you see pin 2 on anywhere on this list of analog input pins.


Give us a Link to you PIR.

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

Try a simpler loop() so you can be sure about what the sensor is reported.

Note: The PIR may take a few minutes to stabilize.

Also: Follow instructions and advice for adjusting and adjustments and setting any jumpers on the unit.

void loop(){
  val = digitalRead(inputPin);  // read input value

  Serial.print(“sensor sez “);

If you still have trouble, you may have it wired incorrectly, many PIRs can be tested with a simple circuit not involving an Arduino. If that won’t work, or the above won’t work, neither will anything more sophisticate.

So draw even with a pencil your current wiring and yes we’d like to know the exact unit you are using.



Thanks for the help everyone, I got it working properly

You could tell us what you porblem was, and what you did to fix it.


1 Like

Your thanks sound hollow, because you have acted selfishly and unhelpfully. Other forum members may find this topic while searching for help with a similar problem. They will have no idea what was wrong with your circuit or how you fixed it. The forum members that tried to help you would also like to know, I'm sure.

Oops sorry, I forgot to add that part. All I did was switch the potPin to A4 and it worked fine. I guess it was some stray voltage.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.