PIR sensor reads HIGH even with no motion

The PIR sensor stayed as HIGH as soon as I uploaded the code into the arduino board. May I ask is there something wrong with my code?

The circuit diagram looks like this:

Here is the code:

int LED = 13;             // the pin that the LED is atteched to
int PIR = 2;              // the pin that the sensor is atteched to

void setup() {
  pinMode(LED, OUTPUT);   // initalize LED as an output
  pinMode(PIR, INPUT);    // initialize sensor as an input
  Serial.begin(9600);     // initialize serial
}

void loop(){
  if (digitalRead(PIR == HIGH)) { // check if the sensor is HIGH
    digitalWrite(LED, HIGH);      // turn LED ON 
    Serial.println("Motion detected!"); 
    delay(100);                   // delay 100 milliseconds 
  } 
  else {
    digitalWrite(LED, LOW);       // turn LED OFF
    Serial.println("Motion stopped!");
    delay(100);                   // delay 100 milliseconds
  }
}

Check the PIR sensor for adjustment potentiometers for sensitivity and time on.
Also check the ground connection to the PIR which does not appear clearly on your image.
Post a link to a product page describing your sensor.

The connection to the sensor looks incorrect for HC-SR501, but who knows which one you are using

ground does not seem connected to the breadboard rail.. only to the LED..

Oops

Hi, @gwynethchiew

Can you post a link to the PIR please?
Is its output open collector?
If so then change.

pinMode(PIR, INPUT);    // initialize sensor as an input

To;

pinMode(PIR, INPUT_PULLUP);    // initialize sensor as an input

It will turn on the internal pull up resistor in the UNO so a circuit exist for collector current.

Tom.... :smiley: :+1: :coffee: :australia:

thank you so much, it worked

Thanks to everyone for helping me, i have found the solution :+1: