ultrasonic sensor timer

Hi guys. Im newbie here. Could you please give me example of code for ultrasonic that if the ultrasonic stables on the set distance in five seconds the process will go to in if instruction

i.e
If(distance==25)
{

}

But if the distance is not stable it will wait until the ultrasonic would reach the set distance.

Hope you guys help. Any suggestions will be much appreciated. Thank you and God bless everyone

Not entirely sure what you are looking for but something like this may work?

int ticker = 0;

void loop
{


if(distance == 25 && ticker < 5)  //
{

ticker = ticker + 1;   //use ticker to keep track of how many seconds the distance is at the set distance
delay(1000)   // wait one second

}

if (distance != 25)  //if it is not stable at the set distance reset the ticker 
{

ticker = 0;

}

if(ticker > 5)   // after 5 seconds do your thing 
{

do something 

}


}

i would suggest to have some sort of smoothening of the signal to prevent very small changes of the distance to reset the waiting period (or have the set distance be between 24 and 26 or something).

hope that helps.

Also what exactly are you trying to measure and why?

Sir I to have a default distance for example the range is 24-26 then when something(Aluminum, TIN can and pet bottles) passed through it the ultrasonic resets the counting. I used ultrasonic for triggering the one part of my program.

In that case i do not understand what you mean. Maybe upload a schematic of what you are trying to do? Or if you speak dutch or german post in that language.

Then whenever you see the distance drop below a certain number, reset your counts. The no-object distance is irrelevant as long as it is sufficiently larger.