Go Down

Topic: Arduino Uno - Analog Input: Random power readings. (Read 552 times) previous topic - next topic

Irellus

Feb 28, 2013, 05:44 am Last Edit: Feb 28, 2013, 06:32 am by Coding Badly Reason: 1
Hello, I'm currently working with my arduino uno, and i noticed sections of my script triggering when I had not intended for them to be triggered, then i tracked the issue to my analog input.

the analog inputs A0 through A5 are all displaying absolutely random readings.

Here's my output:
292--286--296--0--0--81--272--442--439--642--668--739--779--804--739--578--485--405--348--282--276--283--280--0--70--131--160--260--362--45

and my code:

Code: [Select]
int x = A1;
void setup()
{
 pinMode(x,INPUT);
 Serial.begin(9600);
}

void loop()
{
 int var = analogRead(x);
 Serial.print(var);
 Serial.print("--");
 delay(500);
}



I used this code to test my theory of these random readings, and sure enough it was true.
This is an issue.
My trigger uses a the analog inputs to read the power from the 3.3V power source on the arduino.
Running this script, 671 is often printed, and that's causing my script to fire when i do not want it to.

Does anyone know why this is happening?


Note:
The A1 port is totally disconnected from anything, and i've even lifted the Arduino Uno in the air so it's suspended by it's cable to the computer, yet these random readings are still there.


Moderator edit: [code] [/code] tags added.

Arrch

Floating Input. Completely expected. If you want it to default to a reading of 0 or 1023, you need a pulldown/pullup resistor, respectively.

Irellus

I'm quite new to this, and I have not studied any of this in any sort of class. (I'm 16 also)

What's a pull-up/down resistor?

Is this a reliable page?
http://en.wikipedia.org/wiki/Pull-up_resistor

Nick Gammon

That's the general idea.

Quote
The A1 port is totally disconnected from anything ...


It therefore won't give a reading of zero, it will give an undefined reading.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Docedison

Yes and lookup pull-downs too.... Most handy to be able to 'preset' inputs to known states... which is what it is all about, that and understanding when it is necessary and when not... A 'hint', better safe then sorry as you found out... start with 100 K and go as low as necessary to keep the open pin quiet or not reporting change that isn't there...

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Irellus

I got it working, thanks guys!

You've all helped me greatly.
My understanding of the arduino and circuits increased much.

Farewell for now!

Go Up