Pages: [1]   Go Down
Author Topic: Arduino Uno - Analog Input: Random power readings.  (Read 498 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: February 28, 2013, 12:32:46 am by Coding Badly » Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18815
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2892
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

--> 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

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

I got it working, thanks guys!

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

Farewell for now!
Logged

Pages: [1]   Go Up
Jump to: