Go Down

Topic: Basic problem with analogRead() (Read 2829 times) previous topic - next topic

samuz__15

I am working with arduino UNO and when i use the command analogRead("X") the program indicate a value in bits.
The problem is that i am not putting voltage y the arduino board, there is nothing connected.
Help please, it is for a college project.

AWOL

Quote
when i use the command analogRead("X")

analogRead does not accept a string as an argument.

samuz__15

What do you mean with "analogRead not accept a string argument"?

AWOL

Quote
analogRead("X")

"X" is a string.
analogRead accepts only "int" arguments.

Grumpy_Mike

Quote
The problem is that i am not putting voltage y the arduino board, there is nothing connected

So the input is what is known as floating and it is picking up interference. It happens to all unconnected inputs in digital electronics, it is no problem and no magic.

samuz__15

"X" is one example, I meant that if I write analogRead (1 .... 5), it returns a response bits that should not exist because I'm not giving voltage.

here is the code:
// Pin analógico que utilizaremos como entrada de datos
int entradaDatos = A0;
// Variable que recogerá las lecturas de A0
int valorDatos = 0;

void setup()
{
  // Establecemos la velocidad para transmitir datos en serie a
  // 9600 baudios
  Serial.begin(9600);
}

void loop()
{
  // Leemos el valor en la entrada analógica A0 y se lo asignamos a
  // valorDatos
  valorDatos = analogRead(entradaDatos);
  // Imprimimos el valor por el puerto serie
  Serial.println(valorDatos);
}

and i open de serial monitor and indicate values as if it had a 1 volt, it means, 200 bits

Grumpy_Mike


Quote
The problem is that i am not putting voltage y the arduino board, there is nothing connected

So the input is what is known as floating and it is picking up interference. It happens to all unconnected inputs in digital electronics, it is no problem and no magic.


Do you read answers?

AWOL

Quote
it returns a response bits that should not exist because I'm not giving voltage.

You're not, but what about the environment?

samuz__15

sorry, i was writting when you sent the message, and sorry for my ignorance but:  how to remove that interference in arduino analog pins?

AWOL

Quote
how to remove that interference in arduino analog pins?

Short them to ground.

samuz__15

i really sorry for my ignorance. if i short them to ground, how i connect the analog input of voltage?
and thank you very much for your help and patience

AWOL

If you connect the inputs to a source, they'll no longer be floating.
(when we say "floating", think "antenna")

larryd

The suggestion to short them to ground is to prove that floating condition was indeed causing readings with no input connected.
Connect then input to an analog sensor with an output between 0 and 5 volts to get your readings.
Do not leave the analog input floating else you will see some sort of signal when you expect to see none.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

retrolefty


i really sorry for my ignorance. if i short them to ground, how i connect the analog input of voltage?
and thank you very much for your help and patience


What we are trying to say is that you do not have a problem, you just think you do. If you do not have anything wired up to a specific analog input pin then simply do not perform a analogRead() on that pin, so no problem with that correct?

If you do have a valid electrical signal wired to a analog input pin then you are free to perform analogRead() function on it and use it's value as you please in your program.

Does that answer your concerns?

Go Up