New with sensors

It's getting late here but this might have a chance of working

int IRpin = 0; 
    // select the input pin for the potentiometer
int fanPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

#define TRIG_VAL 100  // play with this value

void setup() {
  Serial.begin(9600);  
}
void loop() {
	sensorValue = analogRead(IRpin);    
 
	if (sensorValue > TRIG_VAL) {			
		digitalWrite(fanPin, HIGH); 
		delay(5000);
		digitalWrite(fanPin, LOW); 
		while (analogRead(IRpin) > TRIG_VAL); // now wait for the object to leave before allowing a repeat performance
	}
}

It's based on my reading of the data sheet, the TRIG_VAL should be a value just over the reading you get with nothing in front of the sensor. That's why I wanted to know the values.

This is not very clever code as it stops the processor from doing anything else, but it should do for now.

Note also that the sensor output dives at about 15cm, that will be difficult to deal with because that will look the same as the object moving away really fast.


Rob