How do I check if a pin has been high for a specified amount time?

I want to be able to do something like this, but i dont know the code to use...

I have a PIR motion sensor, and I want to filter out any bugs / rodents / false triggers...

The PIR Sensor pin goes HIGH when there is motion, and LOW when there is no motion.

I want to be able to check how long the PIN has been HIGH for, and if the pin has been high for > 2 seconds, then execute a code.

Any ideas how to do this? Or does anyone else have any better ideas how to filter a PIR Sensor?

Most PIRs work the other way around, with an open collector output that gets pulled low when active.

Anyway, There is a command called pulseIn() that will tell how long a pulse is, go check it out it the reference section.

Yeah, this one is from parallax and it sends a high signal...

With the pulse in, doesn't the pin have to go low before I can access the results?

I need it so I can access it before the pin goes low...

Use the millis() function to timestamp a variable when the input first goes high. Then you can test how much time has elapsed by testing how much time has passed sense you stored the timestamp variable. Bad sentence I know but hopefully you get the concept. ;)

It's the same application as one would use the millis() to deal with switch contact bounce, but just with a longer time frame. Heck you might even be able to use the bounce library using a 2000 millsecond debounce time value.