1

After watching something weird on the serial monitor I wrote a simple code to monitor the analog pin input values. There was nothing connected to the analog pins still they where showing decimal representation of some analog values.

the code is

float ana [] = {A0,A1,A2,A3,A4,A5};
float dec [6];  

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

void loop() 
{ 
  for(int i = 0; i<6 ; i++)
  {
    dec[i] = analogRead(ana[i]);
    Serial.println(dec[i]);
    delay(1000);
  }
}

How is this even possible?

this is the output result

enter image description here

marked as duplicate by VE7JRO, gre_gor, sempaiscuba, Nick Gammon Jun 14 '18 at 6:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Your input is floating if nothing is connected. It is reading whatever random noise it happens to pick up. That's what it is supposed to do. For it to read 0 it would need to be connected to ground. Google "floating input" for more info.

Not the answer you're looking for? Browse other questions tagged or ask your own question.