Help with reading of arduino uno

Hi everyone, I'm having problems with a project because of the Analog and Digital read with my arduino uno (Actually I have made tests with two Arduino uno, getting same problem).

The question is, is it normal to get values major to 0 (even 350, 1.5 V) in an Analog read when there is nothing connected to the analog port ? Literally the only connection to the arduino is the USB cable. Also if I connect a cable to other port (im reading A0 for example, and i connect 5V to A5), A0 starts to receive 3V.

Also, I am having problem with the digital reading because with no cables it shows 0 as reading, but just connecting a Jumper or a cable (with no voltage connection in the other side) goes crazy showing 0 and 1 sometimes.

Never before I asked myself if its normal, so thats why I'm asking.

Thank you.

The code I'm using for now is an example of arduino:

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  int sensorValue2 = analogRead (A2);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  float voltage2 = sensorValue2 * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println("voltage A0");
  Serial.println(voltage);
  Serial.println("voltage A2");
  Serial.println(voltage2);
  delay(1500);
}

It's normal. Look up floating input.

The result of an analog read on a pin that is floating is so random, it is often used as a random seed for the random function.

Here is example code for that.

long randNumber;

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

  // if analog input pin 0 is unconnected, random analog
  // noise will cause the call to randomSeed() to generate
  // different seed numbers each time the sketch runs.
  // randomSeed() will then shuffle the random function.
  randomSeed(analogRead(0));
}

void loop() {
  // print a random number from 0 to 299
  randNumber = random(300);
  Serial.println(randNumber);

  // print a random number from 10 to 19
  randNumber = random(10, 20);
  Serial.println(randNumber);

  delay(50);
}

Thanks everyone for your help. Floating the inputs worked.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.