State change detection with analog input?

You can implement a digital low-pass filter easily.

Your issue is likely caused by interference - high input impedance on the input pin. One way to fix that is to lower its input impedance, by grounding that pin with a small resistor (<47k).