Go Down

Topic: How to Detect voltage Noise in the analog pins. (Read 666 times) previous topic - next topic

baligena

I'm using the analog pin (A0) to control a relay using a power supply and a battery.  The reading is perfect until I remove the battery.  I get noise and numbers are all over the place. 

I want to know what code can I write to detect that the reading has gone berserk so I can notify myself?

Here is the reading below coming out of the serial monitor
498
410
355
969
1023
1023
897
539
438
373
980
1023
1023
719
500
411
356
986
1023
1023
792
516
422
363
967
1023
1023
712
500
409
355

afremont

Compute the difference between the current reading and the last reading.  If it is ten times greater than anything you'd normally see in your software, then assume that the battery was disconnected.  You could possible install a 100k pulldown down resistor to ground on the analog pin, and then readings would just drop to zero when the battery is disconnected.  100k shouldn't interfere with the pin's ability to drive the pin high on a digitalWrite().
Experience, it's what you get when you were expecting something else.

robtillaart

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up