I am trying to use the value of analogRead in a project. I did a small test like the bellow. Why there is always a value even without any input to the pin A3.
There is always a value between 300 -320.
I was expecting a zero. Am I missing something?
int analogPin = A3;
int val = 0; // variable to store the value read
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(analogPin); // read the input pin
Serial.println(val);
delay(1000);
}
If you have nothing connected to an analogue pin to keep it at a known voltage then it can pick up electrical interference from the environment. Hence you get a value other than zero from analogRead() and that value may vary
You wrote that the analogPin = A3 which means you define the pin on which you are going to place the object. And you want to bring that object value in serial monitor correct? I think you want to know the voltage. If you have nothing connected to an analogue pin to keep it at a known voltage then it will not show the right value and just shows picked up electrical interference from the environment. As it gets the value from enviroment for the same and any thing like 1,2,3 will show in the serial monitor. Hence you get a value other than zero from analogRead() and that value may vary.
So you should put something in the pin define. To get it voltage
You wrote that the analog Pin = A3 which means you define the pin on which you are going to place the object. And you want to bring that object value in serial monitor correct? I think you want to know the voltage. If you have nothing connected to an analogue pin to keep it at a known voltage then it will not show the right value and just shows picked up electrical interference from the environment. As it gets the value from environment for the same and any thing like 1,2,3 will show in the serilal monitor. You have to put some object in A3 pin for which you want to know the voltage.