PIR sensor data regulating

Hi all,

I've been trying to make a smart lamp that switches between a warm light, a purple light and an off state according to light levels and people in vicinity. However, the PIR sensor that I'm currently using gives off data in a weird way. Instead of giving a constant "1" when it detects something in its range, it drops to "0" for about a second before returning to "1". This makes it switch to the wrong light for a little and I want to fix this. I've tried regulating it by setting up an intterupt with a timer, so that only when the signal is "0" for more than 2 seconds, the other color lamp turns on.

Here is the code I'm using:

/macro definitions of PIR motion sensor pin and LED pin/
#define PIR_MOTION_SENSOR 2//Use pin 2 to receive the signal from the module
#include <ChainableLED.h>
int pin1=4,pin2=5,number_of_LED=1;
ChainableLED leds(4,5,1);
int pin3=2;
int TimeUpdateInterval = 2000;
int LastUpdateTime;

void setup()
attachInterrupt(digitalPinToInterrupt(PIR_MOTION_SENSOR), PIR, FALLING);

void loop()
int light=analogRead(pin3);
int PIRstatus=digitalRead(PIR_MOTION_SENSOR);
Serial.print(" ");

if (light > 400 && PIRstatus == 1)

if(light < 400 && PIRstatus == 1)

if (millis() - LastUpdateTime > TimeUpdateInterval && light < 400 && PIRstatus == 0)

void PIR() {

LastUpdateTime = millis();


Please provide a link to the exect PIR sensor.

A possible work around is to do a state change detection (see example in IDE) and detect when the pin goes from LOW to HIGH and react on that.

Any reason why you posted this in Arduino IDE 2.0 beta? Sounds more like a general problem than an IDE problem.