Analog Input to Digital Serial occasionally quits (Uno)

A input of +5vdc or greater will return a 1023 count value, if it doesn't destroy the input pin as it has a Vcc +.5vdc limit.

The best course of action to troubleshoot this problem is to run the sketch with the sensor connected and when and if you see it reading zero again, just measure the voltage at the input pin with your Digital Multimeter. That will 'half-split' the problem from being a sensor problem or a arduino problem. If you don't own one, go on-line and order one, they are cheap these days and no one should be wiring up arduino projects without having and learning to utilize a DMM.

Lefty