voltage sensor unstable in my code

What voltage are you trying to sense? Appears to be a 5:1 voltagedivider for DC.