Arduino Mega 2560 reads a voltage in the analog in pins while nothing is connected. I noticed the problem while working the bugs out of a photo-resistor/IR sensor project. Finally I wrote a sketch to read the analog pins to the serial monitor and they read out a number that starts just shy of 400, over the span of a few seconds they drop to about 300.
Is this a defective board? Am I missing something? Nothing is plugged in except the usb... code and serial monitor info is provided below.
Floating pins (aka unconnected pins) pick up stray energy, creating a voltage on them.
It is sort of why the following note is on the analogRead() reference page:
"If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.)."
James, I have not yet looked at the reference pages yet. I bought the Arduino book from Radio Shack and have been working through that. I just looked at the reference page and found a wealth of information. Thank you!
Cross Roads, Thanks for your input. My electronics is a bit lacking. The issue was a lack of grounding... please don't tell anyone. Now my Night Light Motion Detector works like Ford from the 60's (great!).