Getting potentiometer value between 100 and 750. Hardware or Software ?

Hello Everyone,
I am trying to work with this 5k potentiometer. I am getting a value between 100 on the low and 750 on the highest on my monitor. I would like your help please why am I not getting 0 and 1023 ? Is it a hardware problem or a software problem ?

I am using a Nano
here is my sketch :

int potPin = A6;    // select the input pin for the potentiometer
int val = 0;       // variable to store the value coming from the sensor

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

void loop() {
  val = analogRead(potPin);  // read the value from the sensor
  Serial.println(val);
  delay(200);
}

How is it wired, exactly?

What resistance does your multimeter tell you it gives at either end of the range? When turned all the way left, the left + middle should give (near) zero resistance; when turned right that'd be the right + middle.

wvmarle:
How is it wired, exactly?

What resistance does your multimeter tell you it gives at either end of the range? When turned all the way left, the left + middle should give (near) zero resistance; when turned right that'd be the right + middle.

the middle pin is the output and the other pins are gnd and +5V

when I turn it left all the way: the value plays between 96 and 105
when I turn it right all the way: the value plays between 742 and 752

Do you have a DVM .

Sounds like a problem with the potentiometer.

Try a different pot.

larryd:
Sounds like a problem with the potentiometer.

Try a different pot.

I did, this is the second one, the first one was from different supplier and it was a 10k, and same problem happened

Do you have a DVM ?

If so, what voltage do you measure on the wiper when at minimum and at maximum ?

Does A0 work the same way ?

larryd:
Do you have a DVM ?

If so, what voltage do you measure on the wiper when at minimum and at maximum ?

Does A0 work the same way ?

I am using a nano, so I tried A7, now I changed the pot again and the min is around 78 and the max around 933

for voltmeter the value at min is 0 V and at max it is 3.90V

Can you provide a schematic so we can see how you are connecting it?

The arduino Nano has "Vin" "5V" and "3.3V" pins, show which you are using.

Can you also post a photograph of your circuit?

You are using a nano. the min is around 78 and the max around 933
for voltmeter the value at min is 0 V and at max it is 3.90V

Why is max=3.90? what is Vcc?

It may not be necessary but as good practice I'd like to see the analog pin declared as an input
pinMode(potPin, INPUT) ;

int potPin = A6;    // select the input pin for the potentiometer
int val = 0;       // variable to store the value coming from the sensor

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

void loop() {
  val = analogRead(potPin);  // read the value from the sensor
  Serial.println(val);
  delay(200);
}

johnerrington:
Can you provide a schematic so we can see how you are connecting it?

The arduino Nano has "Vin" "5V" and "3.3V" pins, show which you are using.

Can you also post a photograph of your circuit?

You are using a nano. the min is around 78 and the max around 933
for voltmeter the value at min is 0 V and at max it is 3.90V

Why is max=3.90? what is Vcc?

It may not be necessary but as good practice I'd like to see the analog pin declared as an input
pinMode(potPin, INPUT) ;

int potPin = A6;    // select the input pin for the potentiometer

int val = 0;      // variable to store the value coming from the sensor

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

void loop() {
  val = analogRead(potPin);  // read the value from the sensor
  Serial.println(val);
  delay(200);
}

Ok I am connecting the left pin of the pot to the GND and the right to the +5 coming from arduino, the middle pin to A7, and the VCC of arduino to nothing

I am not sure if my circuit picture would do any good because I have many ICs connected and 2 breaboards with capacitors, and many connected to the arduino. It is a circuit I started working on a year ago but I kept it on the table till now, it was time to continue with it for a project I was working on since. So I decided to start by checking if the pot is working by connecting it to the arduino and uploading its simple sketch

Can you measure the "5V" coming from the arduino? Dont assume its 5V because the label says so.

I tested with the map() function and I got these values

void loop() {
  val = analogRead(potPin);  // read the value from the sensor
  val =  map(val, 85, 860, 0, 255); 
  Serial.println(val);
  delay(200);
}

johnerrington:
Can you measure the "5V" coming from the arduino? Dont assume its 5V because the label says so.

it gave me a value of 4.55V

it gave me a value of 4.55V

So how is the end of the pot that is connected to "+5" reading 3.9V?

johnerrington:
So how is the end of the pot that is connected to "+5" reading 3.9V?

the end of the pot is reading 3.56V now the end which are + and GND

and the GND and output is reading also 3.56V at the maximum

the end of the pot is reading 3.56V now the end which are + and GND

But you say that the 5V coming from the Arduino

gave me a value of 4.55V

That does not make sense if the end of the pot is connected to a 5V pin on the Arduino

UKHeliBob:
But you say that the 5V coming from the Arduino
That does not make sense if the end of the pot is connected to a 5V pin on the Arduino

the arduino has a jumper wire going out of it to the side line of the breadboard and then the pot to the side line of the breadboard

firashelou:
the arduino has a jumper wire going out of it to the side line of the breadboard and then the pot to the side line of the breadboard

Then the voltage should be the same. Check your wiring and check the breadboard connections

Schematic and clear, well-lit photos of your setup (clearly showing all wires and where they are connected) seem to be in order indeed.

ok Gentlemen,
what I did is, I took the potentiometer and connected it to an arduino Uno with no connection at it but the potentiometer, and it worked perfectly ! I also tested an arduino nano which has no connections to it but the potentiometer and it also worked perfectly !
The potentiometer gave me readings from 0 to 1023, so do you think I should make no connections to the nano to get the right readings other than the potentiometer of course ? maybe because open connections would create problems ?

I think the other devices on your breadboard are drawing a lot of current and the jumper wires or connections have too high resistance.