State change detection with analog input?

deikoalita:
Thanks Mark
so you mind the preferred option would be to use digital inputs using a low -pass-filter and schmitt trigger.
I never used low- pass-filter ...can you please explain shortly how to connect it?
the schmitt trigger code I'll try to find it searching i nthe forum, but if you also can help me...

Thanks.

I would suggest a digital low pass filter. Read the analog input "X" times, add the results together in an accumulator, then divide the final result by "X".

example:

/*
unsigned int x;
unsigned int samples = 1000;
unsigned long int accumulator = 0; // initialize accumulator
for (x = 0; x < samples; x++) {
accumulator += analogRead(channel);
}
return accumulator / samples;
*/

Any random noise on the analog input will be averaged out and return you a clean reading.

Change the constant "1000" to whatever you like (larger == more smoothing but slower response, smaller == less smoothing but faster response).

Note that the "accumulator" variable must be large enough to hold (1023 * number_of_samples).

Hope this helps.

-- Roger