Dustsentry - 5second timer for a Sharp IR sensor

Hello

I'm currently trying to build a dust sentry for a workshop. It involves a

Arduino Duemilanove
Sharp IR sensor
Sound alarm(on relay)
Strobelight(on relay)
4 digit LED 7/8 segment (on a breadboard)

There will be a lot of small wood chips flying past the sensor, so I need it to:

"spot object - wait 5 seconds - spot if object is still there - reaction"

I've tried a delay(5000) but it seems to make trouble in the multiplexing LED. So I guess the only solution would be something with millis()?

It basically just shows the distance from 80cm until between 20 and 15cm, where I want the alarm to react.
Then I've tried a lot of stuff like this:

else if (distance_cm >= 15 || distance_cm <= 0) //over 15cm
{
now = millis(); //tid nu
}

if((distance_cm >= 15) && (millis() - now >= vente)) //vente 5 sek.
{LED and alarm starts here.

Hope you guys can help :slight_smile:

ARduino_dust_sentry.ino (12.6 KB)