Error analog input

Status
Not open for further replies.

atersolis

New member
I have a teensy++ 2.0 and I tried the code given in one of the tutorial :

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

int val;

void loop()
{
val = analogRead(0);
Serial.print("analog 0 is: ");
Serial.println(val);
delay(250);
}

It's said in the tutorial that the value should be 0 when is at 0 volts.
However, when nothing is connected to the pin (and the other pins) I get something like this :

analog 0 is: 386
analog 0 is: 373
analog 0 is: 374
analog 0 is: 368
analog 0 is: 380
analog 0 is: 378
analog 0 is: 376
analog 0 is: 368
analog 0 is: 345
analog 0 is: 342
analog 0 is: 365
analog 0 is: 359
....

Do you have any idea of where the problem might come from ?
Thanks in advance.
 
If nothing is connected the the Analog pin, then you are picking up all the EM radiation in the room much like an antenna. If you want to read 0 volts it must (as Michael has said) be connected to the ground, which is where 0V is as far as your circuit is concerned.

Google for information about voltage dividers (or potential dividers if in the UK) to get a better idea of analogue circuits :)
 
Status
Not open for further replies.
Back
Top