I am working on a project, and I noticed I was not getting values from analogRead that I expected. I have an Arduino Uno. If I read from any of the analog pins (A0-A5), no wires or anything connected, I would expect to get a 0 from analogRead. Sometimes I do, sometimes the value is as high as 255. Nothing else except USB is connected to the board. Why am I seeing these values?
I think it is a normal behavior for ADC. I have the same effect with Diemilanove and Mega and also other chips with ADC.
You need to use a pull-up or pull-down resistor (like 10K connected to Vcc or GND) to define you default value.
OK, I can accept that if nothing is connected, it is floating.
What started all of this, was trying to read the DC output from a MSGEQ7. When nothing was hooked up to the input of the chip, it was reading non zero values. They were low, but I would expect them to be 0, as the chip is connected to the same ground... I think I am missing something.
Same applies to digital input pins. Reading one that has nothing wired to it will give invalid readings, returning sometimes high, sometimes low, sometimes changing. Pins do have an internal pull-up resistor that can be enabled with software to deal with this situation if required.
So I will not be able to depend on a zero value when reading from another IC?
Yes you should, assuming the arduino and the IC share a common ground connection and the output signal from the IC is standard TTL logic or 0-5vdc analog voltage levels. If the output signal from the IC is a 'open collector' output that is one exception where a pull-up resistor (external or internal) is required to get a valid reading.
If I'm reading the datasheet correctly there can be a maximum output voltage offset of 0.6 volts which means a zero can be read on the ADC as anything from 0 to 122. What kind of numbers are you seeing?
Keep in mind the MSGEQ7 is not your typical digital IC. It is reading an analog input and providing outputs based on that. So you'll probably never get to a point where it reads zero.
ICs are noisy.
If you want to know when "nothing is connected" or the input to the MSGEQ7 is "off", then do so testing. Determine what the lower-limit of your numbers will be. Then when you get an input level less than X, you'll have a high degree of confidence the input to the MSGEQ7 is "off."