Problems on analog inputs.

Hi, I m new to Arduino and i maybe made a noob's mistake. Excuse me for that if it is the case :confused: I have a joystick with return to center axis. I just wrote a program to simply read the analog input and print it to screen to see the value for the center, maximum and minimum. The problem is that it returns fluctuating values.

I made these to check for problems:

1- Connect the analog input i read to the ground and it returns a rock solid 0. 2- Connect the analog input i read to the 5V and it returns a rock solid 1023. 3- Deconnect the analog input i read and the value fluctuate between 300 and 500 (no cables left on arduino). 4- Tried some potentiometers, the problem is not hardware (???). 5- Tried changing the delay of the loop. Fluctuating value.

Here the code i use:

void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); }

// the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(5); // print out the value you read: Serial.println(sensorValue); delay(1000); // delay in between reads for stability }

Please help. Thank you in advance.

With nothing connected to an input, whether it be analog or digital, it's in a high impedance "HIGHZ" state (floating).

You can expect to read anything fluctuating from 0-1023 for analog, or HIGH or LOW (1 or 0) for digital inputs. Of course, with nothing connected, the reading is mostly meaningless.

What is your purpose of reading a disconnected input? Do you need the voltage level "pulled" to a certain level?

Hi ,
reading a disconnected input was only a test.

I just changed the variable in FLOAT and remade all wires. Now i have a pretty stable value.
Max is 1023 and min is 0.

So i just plug my 3 axis joystick with return to center spring.

But another problems come:
In the middle i have a value of 39, if i turn left is 0 and the maximum is around 600.
Maybe this joystick need more volts? How can i know if it is the problem?
The joystick is this one:

How are the pot terminals connected?

left on 5v, the middle on the analog input and the right to the grnd on the arduino.

Not familiar with the product ... maybe the control isn't designed to span the full range like for this product: http://www.seeedstudio.com/wiki/Grove_-_Thumb_Joystick

I try to contact the supplier. Waiting a reply. Thank you.