How to detect the presence or absence of a 5v square-wave pulse

I am writing a motor control routine. My motor has a led sensor that produces a 5v square-wave pulse as the motor rotates, so counting the pulses allows me to compute the rotation rate and the number of rotations; the program shuts off the motor after so many pulses have been counted. The problem is that the motor continues to produce pulses after the control pin has been shut off as the motor spins down to a stop.

I need to know the count when the pulses have ceased... that is, when the motor has stopped completely. I could build in a delay, but this seems like an unsophisticated approach. My idea is to detect when the count does not change for a specified period of time, say, for a period of one second. But is there a more "elegant" way to accomplish this? Simpler is better, I think...

I am using an Arduino Uno board.

Dave Emery

No, that is "elegant" enough. It basically defines a minimum RPM and detects it.