Arduino Uno Serial readings

So I was using my Uno today, Windows 10 Pro, Arduino Ide 1.8.13, ran a program that wasn't working as I expected. So I then decided to just try a simple sketch reading a value from a potentiometer . No matter where I placed the pot by turning I would not get full voltage and what changed is not what I expected, I should be able to get 0 to 5VDC or close . I put vcc to pin 1, G pin 3 and A2 to pin2 . See photo Like I said a simple read.
So no matter where I set the pot it doesn't read properly, I checked the settings , I made sure that there were no other sketches open. I removed all wires and loaded a blank sketch , serial window is clear. I did a loop back test and typed Hello World and it responded. I reloaded the sketch and same results. I have another Arduino Uno , plugged that in and still same thing, I thought maybe something was wrong with my Arduino but that proved to be false.

int readVal;
int myPin=A2;
float V2;
int dt=250;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
readVal=analogRead(myPin);
V2=(5.0/1023.)*readVal;
Serial.print("Pot ");
Serial.println(V2);
delay(dt);
}

Connect A2 to 5V and show reading, then GND and show reading.

Looks like you have the pot connected to 3.3V and 5V in the picture!

No in fact the angle of the photo may have it looking that way but what I did realize after your comment was I actually had A01 connected and code was set for A2 . Stupid mistake, working on a project too long and totally missed that .I guess I was not considering that there was an A0 and just thought it as A1. ( egg on face).
Well I loaded the program and indeed it is working, I must be on this too long to have missed that . Just curious , is it normal for the Arduino to be disconnected from the circuit and still read stray voltage off the serial monitor? I loaded a blank sketch and it didn't show anything but once I loaded the sketch again it shows that stray voltage or noise on the monitor.
Anyway, thanks ,you got me to look at it again and I saw the A1 connection.

Glad you got it working, and yes, an unconnected pin will pick up EMF.

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