Go Down

Topic: analogRead question (Read 11709 times) previous topic - next topic

erm213

Hello,

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?

Thanks,

Erik

ionito

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.

wayneft

With nothing connected to the pin it is "floating" and will return random values.  If you want to read 0 connect the pin to ground.

erm213

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.

Thanks,

Erik

retrolefty

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.

Lefty

erm213

So I will not be able to depend on a zero value when reading from another IC?

retrolefty

#6
Dec 31, 2010, 02:57 am Last Edit: Dec 31, 2010, 02:58 am by retrolefty Reason: 1
Quote
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.

Lefty

erm213

OK,  I am going to have to look into the pull-up resistor then.

Thanks,

Erik

wayneft

Quote
Output Offset VOS 600 mV

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?

erm213

I was seeing under a 100, usually a 60-70 range, but it did jump all around. Turning on the internal pull up resistor gives a tighter 38-41 range.

cmiyc

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."
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up