Grounding issue with Analog ins??

Hey,

I'm working with a duemilanov using the analog in to sense both variable range data (temp sensor) and on/off data (buttons). Everything was working beautifully, except now my analog in pins are reading around 250 with the analogRead(pin) command when the voltage at the pin is ZERO.

The pins all seem to read correct voltage when there IS ACTUAL voltage, but if the voltage is ZERO (confirmed with voltmeter) I get this mis-sense. This is important because I use the logic of...

if (analogRead(pin)) { // senses voltage on the line use temp sensor data } else { // 0 voltage on the line assume temp sensor not attached }

BUT if it mis-senses the analogRead when nothing is attached I get botched program data.

If I attach the analog pin to ground, it reads 0 ...making me think it's a grounding issue...but, of course, then I can't run a voltage through it.

Things were working perfectly yesterday (analog pins reading zero if nothing attached) so I don't know what's changed. I've reset the board, erased all code except for a test analog read, and tried it with a brand new board (it's doing the same thing).

Help!! :-)

Thanks!

Got an pull up or down resistor in? (Think I read somewhere that pull up was better than pull down)

When nothing is attached to the pin, the readings from it just bounces around.

Yes, there is no logical reason to read a analog input pin if there is nothing wired to it. The pin will be in a 'floating' condition and what it will read depends on circuit noise, voltage on adjacent pins, etc. If you must read a unwired analog input pin, wire a external pull down resistor or just wire the pin to ground.

Lefty

Thanks! I think a pull down is exactly what I need. It's weird that I didn't have any noise on this circuit for the last month or so of testing, but I have changed the power source. I guess it's lucky to have run into this issue before deplying the project!!

God Bless QA testing :-)

Make sure that the pull down resistor isn't too low otherwise it might load what ever you are trying to measure.

Hey GM,

Sound advice. I was going to go with either a 10K or a 47K. When the temp sensor is off or the buttons are open (both sending 0 volts) the ADC can just be pulled down to a constant low level (readin 100 -200). When they are sensing, however they need to read what's on the wire.

10K seems the best bet. Advice?

Yes the A/D specification on the chip says it is optimised for 10K so that is the one to go for if it suits the rest of the circuit.