I'm new to arduino. Maybe is an elemental question...

If I load this program:

int mval = 0;
void setup() {
  // set up the LCD's number of columns and rows: 


void loop() {

  mval = analogRead(1);


I get a value that varies between 300 and 400. When I think it have to be 0, being that there's nothing connected to that input.

Any ideas?? It's an arduino UNO connected to my laptop via USB


2 Answers 2


You're getting something called "floating input". When you think about it, an ideal device for measuring input will have a very high input impedance, and thus will not remove very much electricity from the pin.

So what happens is that random electrons float on to (or off of) the pin (either from electro-magnetic interference in the environment or from direct contact with something with a slight charge), and because it acts like a very high resistance connection to ground, this charge will drain off very slowly. Thus when you go to measure it, it looks like there's some voltage there! In general, you either hook this up to some device which provides a voltage, or you put in a pull-up or pull-down resistor and adjust your expectations on that pin.

I hope that helps and if not I'm sure someone has a link to another person who has answered this question more competently (I see in the related section at least one near-identical question).

  • 5
    \$\begingroup\$ Fun fact: The Arduino docs suggest using the return value of an analogRead call on an unused pin as the seed to the randomSeed function: arduino.cc/hu/Reference/RandomSeed \$\endgroup\$ Jul 13, 2012 at 18:48
  • 2
    \$\begingroup\$ Ha! That's pretty neat, I like it! I would think that adding in a little squiggily line of wire to your breadboard and/or PCB might help get a bit more randomness so long as you avoided an 60Hz antenna length (USA concern only) (then suddenly AC noise would dominate) \$\endgroup\$
    – Kit Scuzz
    Jul 13, 2012 at 18:54
  • 3
    \$\begingroup\$ A more robust (and space saving) approach would be to use the RFC 1149.5 standard random number generator \$\endgroup\$ Jul 13, 2012 at 18:56

The input is "floating", because there is nothing connected to "pull" the voltage one way or the other.
This is perfectly normal. If you connect a high impedance pull-down resistor (say 10k) from the pin to ground it will stop it doing this when nothing is connected (although there is no real need to do so as you won't be reading it when nothing is connected ;-))

  • \$\begingroup\$ Do pull-down resistor will be change the signal if connected to ADC? \$\endgroup\$
    – user30878
    Dec 11, 2015 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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