Serial Monitor Mishaps! ????

hey guys so i've been having this problem for a while and basically i am trying to get values from a analog signal to the arduino so to get the, say, baseline voltage levels of it i just ran code that serial printed the analog 0 value, but it unexpectedly showed a value of about 255, when it shouldnt have said that because i was doing nothing with the actual analog device itself, so long story short it kept saying this and i checked again and again, EVENTUALLY PLUGGING EVERYTHING OUT FROM THE ARDUINO ITSELF (meaning nothing in any analog inputs, the ground taken out and vcc's) and ran the code again and EVEN STILL the serial monitor is saying a value of around 255 ! help! it'll like gradually decrease its value from about 320ish then land up at 255 and stay there and i'm so confused lol.. here's the code

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead(A0);
Serial.println(sensorValue);

}

any input would be appreciated!

Hi,
You can not just let an analog input "float".

Test it: Connect to ground: should be close to zero
Connect to +5V ir should be close to 1023.

Connect a potentiometer from +5 to ground. Connect the center wiper to Analog in. You should be able to change the value from about zero to 1023.

Work??

terryking228:
Hi,
You can not just let an analog input "float".

Test it: Connect to ground: should be close to zero
Connect to +5V ir should be close to 1023.

Connect a potentiometer from +5 to ground. Connect the center wiper to Analog in. You should be able to change the value from about zero to 1023.

Work??

WOW! WORKED! haha ifeel stupid lol but thanks!

The behavior of floating inputs is highly non-intuitive. Because an input pin is very high impedance (ie, practically no current will pass through it), there's nothing nudging it towards a particular voltage, except for the protection diodes (which keep it between ~0v and ~Vcc), and ambient electromagnetic fields. It's capacitance to ground is very small, so the values can jump around.

If you read a floating input, you'll find that it changes depending on how close your hand is to the pin, for example. If you wire up a MOSFET to switch an LED on and off, but let the gate float, it will turn itself on and off, and you can see it react to you touching and getting close to or far from the wire connected to the gate.

The only time in a real design that you want a wire connected to an input pin and nothing else is when that wire is carefully shaped (by one versed in the dark arts of RF design) to be particularly good at picking up electromagnetic radiation of a particular frequency; We call such a wire an "antenna" - you may have heard of them.