Ignoring a device with a rising value

Im want to have a ultrasonic distance sensor trigger a light at a specified value but I only want it to trigger when the value of the distance sensor is declining. Using the IF function would there be a way to either ignore the input from the sensor or keep the light off?


You need to keep track of at least the last distance read, to give you an indication of direction.

int prevVal = 0;  //Previous value
int currVal;      //Current value

void setup()

void loop()
  currVal = analogRead(0);    //or however you get your current value

  if(currVal < prevVal) {
    //value is declining, 
    //so do your thing
  prevVal = currVal;          //remember current value so we can see if it declines

Good luck!

thanks cant wait for my kit to arrive