PIR Sensor - remove the 'delay' when detecting motion?

Howdy,

I have a PIR sensor and simply want to have a green LED light up when there's motion detected, otherwise have a red LED light up. I have that part working, no problemo. However, it seems that when I move my hand in front of the sensor, and then move it away, the PIR still thinks the motion is there for a slight delay (a second maybe). Is there a way to get rid of this delay, so it will only light the green LED while something is moving?

Or, is it more of a matter of buying a higher quality PIR sensor?

Here's my code, FYI:

int IRpin = 2;               // choose the input pin (for PIR sensor)
int greenLed = 4;            // choose the green LED
int redLed = 3;              // choose the red LED
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status


void setup() {                
  // initialize the digital pin as an output.
  pinMode(greenLed, OUTPUT);
  pinMode(redLed, OUTPUT);
  pinMode(IRpin, INPUT);
  Serial.begin(9600);
}

void GreenOn(){
    digitalWrite(greenLed, HIGH);   // turn the green LED on (HIGH is the voltage level)
//  delay(250);               // wait for a second
//  digitalWrite(greenLed, LOW);    // turn the green LED off by making the voltage LOW
//  delay(250);               // wait for a second
}

void GreenOff () {
  digitalWrite(greenLed, LOW);
}
void RedOn() {
    digitalWrite(redLed, HIGH);   // turn the green LED on (HIGH is the voltage level)
//  delay(250);               // wait for a second
//  digitalWrite(redLed, LOW);    // turn the green LED off by making the voltage LOW
//  delay(250);               // wait for a second
}
void RedOff() {
  digitalWrite(redLed, LOW);
}
// the loop routine runs over and over again forever:
void loop() {
  val = digitalRead(IRpin); //read the input value from the IR sensor
  if (val == HIGH) { //check if the input is HIGH (i.e. detects motion)
    RedOff();
    GreenOn();
  }
  else { // if there's no movement, blink RED
  GreenOff();
  RedOn();
  }

}

Thanks for any help/ideas!

Might be able to change a part on the PIR so it turns off quicker after motion stops.

CrossRoads:
Might be able to change a part on the PIR so it turns off quicker after motion stops.

Hm, I'm just learning Arduino/electonics, that seems like a step for down the road yeah?

Yes, not really a beginner step.

CrossRoads:
Yes, not really a beginner step.

Gotcha, thanks!

there is 2 Adjustable resistor on the PIR sensor, have a try to adjust them. the delay time do not have any relationship with the coding, do not waste time on the coding.