strange behaviour with 2 analog inputs

Hi everybody,

i've got a strange behaviour with analog inputs: on software side i'm using 2 analog inputs, but on hardware side, i only plug one.

Now, i expected that the arduino would give me correct values on the pin, that does have a sensor plugged - and weird values on the other one.

But no! I'm getting the same vlaue for both pins. Even so, that one pin doesn't have any sensor plugged, it gives back similar values as the pin that does have a value (using a sharp distance sensor).

Isn't that strange? Or am I doing sth wrong?
(Tested with Arduino Mega and Arduino Nano)

int pin1 = 1;
int pin7 = 4;

void setup() {
 Serial.begin(9600);
}

void loop() {
 float in1 = analogRead(pin1)*0.0048828125;
 float in7 = analogRead(pin7)*0.0048828125;

 Serial.print("[");
 Serial.print(in1);
 Serial.print(":");
 Serial.print(in7);
 Serial.print("]");
 delay(10);
}

now i tested it with an arduino duemilanove (atmega 328). andthere it's different: on the pin that doesn't have any sensor connected, the values are differ more:

it's value connected pin +/- 300
(whereas with the other boards it was +/- 5)

is there any logic behind this? or can i do sth on hardware side?

You could search for "floating pin".

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261680395
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261765587

is there any logic behind this?

Yes, floating pins are high impedance.
The thing to remember is that there is only one A/D converter in an arduino and it's input is analogue multiplexed from the six analogue input pins.

There is a sample and hold capacitor on the input of the A/D converter and if that gets charged by the connected pin it can remain charge when the input multiplexer switches over to the unconnected pin.