Read analog pin

Hello, I have a problem about reading an anologic pin on Arduino. I use the analogRead function with A1 in parameter, to read the value in the analog pin 1 but when I see it on the oscilloscope I have a constant value but in my software I read a variable value. I have tried analogRead with A1 and 1 in parameter but I have always got the same problem. And when I unplug the wire I have the same problem. Always a variable value. I have also tried to make a calcul with the value like this : value = value * 5 / 1024 But the problem is already here. Can you help me ? Thank you in advance, Cordially, Styvak

Please post a program and a schematic of your circuit that illustrates the problem.

My code is :

int analogPin = 1;
int val = 0;

void setup() {
  Serial.begin(9600);          //  setup serial
}

void loop() {
  val = analogRead(analogPin);    // read the input pin

  Serial.println(val); 
  delay(100);
}

And the schematic is attach, but I don’t know how do you want a schematic so I made this.
Thank you for your answer,
Styvak

It looks like you have 2 shields stacked on the Arduino. What happens if you reduce the circuit to just the Arduino board itself ?

Incidentally, if the shields pass the signals straight up through the pins and sockets then the point at which you have indicated you attach to the Arduino is not an analogue pin it is the 5V line and will not vary.

You can not just attach an input at one point you must also have a common ground. If you do not you get results like you have been getting.

And the schematic is attach, but I don't know how do you want a schematic so I made this.

You get a pencil and paper and draw one, then photograph it and attach it.

Sorry I’m late to answer but I haven’t got a lot of time :confused:
I have draw the schematics
Thank you for your answer,
Styvak

In order for analogRead() to work it needs to have a voltage to measure against. This is provided by having a common GND connection between the Arduino and the device being measured. Your drawing does not show such a common GND connection. Have you missed it from the drawing or does it not exist ?

I just missed to write it sorry

Have you taken note of what I wrote in reply #3 ?

Yes I've tried to unplug the shields stack but there is no difference :/

Are you sure that the socket that you indicate in your picture is pin A1 ?