Pages: [1]   Go Down
Author Topic: Why are my analog inputs values floating?  (Read 1054 times)
0 Members and 1 Guest are viewing this topic.
Albury, NSW, Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 188
Soon to be master of the Electric Scooter!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again,

Using Nano, I'm measuring the inputs of some analog pins.

Sometimes nothing is connected to them (while I'm debugging).  When this is the case, the values returned from analogRead(intPin) on these pins tend to "float".

Does this mean I need to have the analog input pins pulled to ground with a small resistor, or can I enable one of the internal resistors on each pin to stop this from happening?

I'm reading this page and it refers to pullup resistors: http://www.arduino.cc/en/Tutorial/DigitalPins
And it specifies this code:
digitalWrite(pin, HIGH);       // turn on pullup resistors

Does that means I tun on a pulldown resistor by using digitalWrite(pin, LOW);?

Foncused!

Thanks for your help.

Cheers,
Scott.
« Last Edit: November 24, 2008, 11:36:49 pm by scootabug » Logged

Albury, NSW, Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 188
Soon to be master of the Electric Scooter!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually I now realise that I can't do a digitalWrite() to an analog pin.  Or can I?
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are using them as analog inputs don't use a pullup.

I don't know how enabling the pullup interacts with analog inputs.

The  ATmega does not have a pulldown.

The analog pins can also be used as digital pins, so the digitalWrite() call is potentially valid.

-j

Logged

Albury, NSW, Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 188
Soon to be master of the Electric Scooter!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I didn't try the digital write but I did try analogWrite(0) to it...really didn't help.  Pointless trying anything else if the ATmega doesn't have any internal pulldown resistors...

I've put a 150k resistor on the analog input to pull it to ground when there's nothing coming into the input.  It seems to be reducing the input (I can only get to 1016 or so?) range, probably not wired up the way it should be...I'd have no idea realistically.  In reality I might not need this at all, just airing my issues as they arise.

Thanks for the help...
Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 4
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a reminder that when you do digitalWrite(0) and analogWrite(0) you are dealing with two different pins...  This has tripped me up before.

M
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

th reason you only get 1016 maximum is because you are dividing your input between the pulldown resistor and the internal resistance of the analog pin.
Logged

Pages: [1]   Go Up
Jump to: