Problems with NeoPixels and PIR sensor

Hi, I'm relatively new to programming with the arduino. I hope my problem is easier too solve then it looks for me.
I want to make a night light which lights up when im standing up.
My Problem: no matter what i put into the pir pin, the lights light up. a single wire not even connected to the pir is enough. Maybe you guys can help me.

edit: with a "normal" LED everything works fine

cheers
lukas

int PirPin = 5;
int ledPin = 13;
int PIR = 0;


#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

#define PIN            10
#define LEDS      32

Adafruit_NeoPixel strip(LEDS, PIN, NEO_RGB + NEO_KHZ800);


void setup() {

  Serial.begin(9600);
  pinMode(PirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  strip.begin();
  strip.setBrightness(10); 
    }

  
  void loop() {
  PIR=digitalRead(PirPin);
  if (PIR == HIGH)
    {
    digitalWrite(ledPin, HIGH);
    Serial.println("PIR");  


 for(int i=0; i<LEDS; i++)
  {
      strip.setPixelColor(i, strip.Color(71,63,131)); 
      }
   

    strip.show();
    }

else
  {
      digitalWrite(ledPin,LOW);
  }

 
}

Nachtlicht.ino (2.09 KB)

What if you put the pir pin to ground?

When you say "lights light up" do you mean the NeoPixels or the led on the Arduino, or both?

Your sketch has no code to switch the NeoPixels off.

+1 karma for using code tags on your first post. Please perform Tools->Auto Format on your code before you post it next time.

the neopixels and the led on the arduino light up. they even light up when i put a wire in pin 6. which is not in use. the other pins are good.

they even light up when i put a wire in pin 6. which is not in use

I am assuming that putting the wire in Pin6 involves removing it from pin 5. I notice this pin is set as just an input, with nothing attached to it it could read as any value. We say it is floating.

If your PIR sensor has an open collector output it will need a pull up resistor on the Arduino. You can use the internal ones on the Arduino by using the following line in the setup function:-

pinMode(PirPin, INPUT_PULLUP);

You will then need to change:-

if (PIR == HIGH)

into

if (PIR == LOW)

to get the case where the PIR "sees" something.

Maybe you experience noise from the NexPixels?

I had a same problem with a PIR sensor and a 4 digit 7-segment LED display. The LED display generated noise that caused the PIR sensor to be "on" all the time.

Is solved it by adding a LC filter on the power line to the PIR sensor.