Pages: [1]   Go Down
Author Topic: Question about Analog Ports....  (Read 990 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm hoping that someone can help explain something for me that I can not seem to figure out.  So I'm trying to build a capacitance water sensor to use with my Arduino Uno board.  The concept is simple as you are just measuring voltage on one of the analog pins.  My issue comes in when I do an analogRead and nothing is hooked up to the pin.  I started getting random values that range from low 100's to low 400's.  However when ever I ground the pin out I always get a value of 0 back and when I send a full 5V to the pin I always get a value of 1023 as expected.  My question is why the weird random values when nothing is connected to the pin and how can I account for that?

Thanks,

whit3fir3
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
My question is why the weird random values when nothing is connected to the pin and how can I account for that?

That is standard behaviour of reading from any input pin, digital or analog, that has nothing wired to it. It's called a 'floating input pin condition'. Why would you assume there is 0 vdc applied to a pin that has nothing wired to it? And why would you be interested in reading a analog input pin that has nothing wired to it? As you saw grounding the pin returned a good 0 counts return and you wired +5vdc to the pin and found a good solid 1023 count return, life doesn't get much better then that in the ADC world.  smiley-cool

Lefty
« Last Edit: January 31, 2013, 11:46:28 am by retrolefty » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lefty,

Thanks for the quick reply.  I guess my concern comes from more of my software design background and trying to test for the "floating input pin condition" to ensure that something is connected to the pins.  For example lets say I had 2 of the water sensors but wanted to disconnect one.  Instead of having to change the code a simple IF statement could catch this floating input pin condition, test for it and then NOT read the voltage from that pin if nothing was connected to it.  This all depending on there being a way to test for the floating input pin condition, which I'm going to take a stab at and say there isn't a way from looking at the Arduino reference library.  If I'm wrong please let me know.

Thanks,

whit3fir3
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lefty,

Thanks for the quick reply.  I guess my concern comes from more of my software design background and trying to test for the "floating input pin condition" to ensure that something is connected to the pins.  For example lets say I had 2 of the water sensors but wanted to disconnect one.  Instead of having to change the code a simple IF statement could catch this floating input pin condition, test for it and then NOT read the voltage from that pin if nothing was connected to it.  This all depending on there being a way to test for the floating input pin condition, which I'm going to take a stab at and say there isn't a way from looking at the Arduino reference library.  If I'm wrong please let me know.

Thanks,

whit3fir3

No, there is no logical method I can think of for a program to determine if a returned ADC count of say 200 was the result of a valid input voltage of that value sent by a sensor or of the results of a disconnected sensor. You must either be able to tell your program you are going to disconnect an input so it can stop reading it or some kind of external electrical circuitry that applies a known default voltage value onto the pin when there is no sensor voltage to override that default voltage (very high impedance pull-up or pull-down resistor perhaps? There is probably a hardware interfacing solution or workaround, but is it really worth the effort?

Lefty
Logged

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4400
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
my software design background and trying to test

Wow... they still do that? Test, I mean.

Quote
but is it really worth the effort

Well that depends on the mission-criticality of reading all the sensors, coupled with the risk of those pesky user people unplugging one....

Maybe some kind of redundancy of sensors could work?

Logged

Roy from ITCrowd: Have you tried turning it off and on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34220
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
No, there is no logical method I can think of for a program to determine if a returned ADC count of say 200 was the result of a valid input voltage of that value sent by a sensor or of the results of a disconnected sensor.
Well in this project:-

I have to decide if the spoon is touching the conducting pad or not.
The spoon is connected to the analogue input pin and each end of the conducting surface ( let's just consider one of the two dimensions here ) is connected to an output pin.
The method I use is:-
Discharge the sample and hold capacitor in the A/D by switching the input multiplexer to ground.
Then
The two outputs to one - if I measure anything below a large threshold it is floating
Then
The two outputs to zero - if I measure anything above a small threshold it is floating
If any of those two tests say it is floating then I assume it is.
If not floating then one output to one and the other to zero and take the reading, which is proportional to the spoon distance on one axis.
I then make the two outputs into inputs and repeat the measurement only for the other axis.

Maybe you could adapt this technique to your situation.

Having said that capacitance measurements on an arduino is flaky at the best of times.

Logged

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4400
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok Mike, I'll be muggins and be the one that asks....

Quote
Why do you want to see if the spoon is touching the pad... and (supplementary question) why is it all dolled up in that snazzy Bond, James Bond spy case?
Logged

Roy from ITCrowd: Have you tried turning it off and on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34220
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Why do you want to see if the spoon is touching the pad.
Because you only want it to make a sound when it is.

Quote
why is it all dolled up in that snazzy Bond, James Bond spy case?
1) Because I could
2) Because the competition I made it for was for a portable sound generator
3) Because my son bought me three flight cases like that as a 2011 Christmas present and that was the smallest
Logged

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm going to substitute your answer for this one:

Quote
The blue button dispenses Corn Flakes, and the red dispenses Fruity Pebbles.  White dispenses milk, of course.  All actions are ignored unless a cereal bowl is detected on the pad.  The spoon conducts according to the amount of milk dispensed, ensuring that at all times there is a proper milk/cereal ratio.

It's in a flight case 'cause that's how I roll.   smiley-cool
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've used a so called single-pole low pass digital filter before, and it might be worth a try to create a high-pass filter that you could apply to the adc input, and based on the noise level you could detect the floating input condition. Not sure how to code that off-hand, but that should point you in a good direction.
I've tried using 3.5mm stereo jacks with built-in switches for detecting a connection and it was so problematic that I gave up. This could be a good idea for a "smart" input.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34220
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it might be worth a try to create a high-pass filter that you could apply to the adc input, and based on the noise level you could detect the floating input condition.
The problem is that the input is floating, this does not mean there is high or low frequency noise but it could be anything so a filter is not going to cut it.
Logged

0
Online Online
Shannon Member
****
Karma: 207
Posts: 12197
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My question is why the weird random values when nothing is connected to the pin and how can I account for that?

It might look "random", but its acting as a capacitive sensor picking up the local electrical noise from nearby pins, wires,
mains, nearby radio transmitters etc.  There is a thermal noise component too but its microvolts so undetectable ("kTC noise")
Logged

[ I won't respond to messages, use the forum please ]

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 94
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A frequency analysis of the floating values would probably be similar to white noise, which has a mix of all frequencies. With a normal impedance connection established to the ADC, depending on the signal, one would expect the high frequency component to drop substantially.
Perhaps a better way of consider it would be a first or second derivative approach. If differences in the rate of change of value are high enough, then that would indicate a floating (open port) condition.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34220
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
A frequency analysis of the floating values would probably be similar to white noise,
No it won't.
It will be dominated by a strong mains frequency component, there will not be the equal spectral spread you would get with white noise.
Logged

Pages: [1]   Go Up
Jump to: