Dont increment pulsesdetected every time you see input LOW, just whenever input changes from HIGH to LOW.