erratic values with potentiometer

I was using a 10K potentiometer for a project, and I realised that the results I was getting where not what I was expecting, so I decided to monitor what I was receiving from the potentiometer with the following code:

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

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  delay(1);   
}

The result is that when I turn the know from one end until the middle, the value increments from 0 to +-3040. If I continue, lets say a 25% more of the whole rotation I get to 4064, and after this value it gets really weird... It starts going back down, but it gets stuck in certain values, and for example at 100% the value I get is 2540

What is going on there?

How is the pot wired to the Arduino ?

Do you have a multimeter ?

Are you sure that it is a linear pot ?

wired as explained in https://www.arduino.cc/en/tutorial/potentiometer

I do have a multimeter

I am not sure. I took it out from a midi controller

I do have a multimeter

Measure the A0 voltage (relative to the Arduino's ground).

And, are you using a "regular" Arduino? The regular Arduino with the ATmega chip has a 10-bit ADC so it should NEVER read greater than 1023.

jm... that seems to be the problem.

I tried it with a real arduino and it works fine.

I was before using a clone that I bought by mistake: https://www.aliexpress.com/item/WAVGAT-high-quality-One-set-UNO-R3-CH340G-MEGA328P-for-Arduino-UNO-R3-USB-CABLE-ATMEGA328P/32959902921.html?spm=a2g0s.9042311.0.0.22a14c4drIVHbo

How can I sort this out with this (shitty) boards?

I got weird readings from a pot, until I realised I had to connect the pot to 3.3 V and not to 5 V. It was a Netduino, not an Arduino.

I do have a multimeter

It looks like you may have solved the problem but with a multimeter you could measure the resistence of the pot across its range of movement.

Uno clone should be just fine.
It's usually a user mistake (breadboard, wiring, wrong pot, soldering wires to the rivets, etc).
Pot should be a 'B' type (linear), not a 'C' (log) or 'A' (audio taper).
So 10kB or B10k.
Leo..

A lot (all?) of the WAVGAT boards use the LGT8F328P chip, even though they don't mention this fact anywhere in the listing. The other listings I've seen for WAVGAT boards actually advertised the boards as using ATmega328P, but this listing is a bit vague about it. You can tell it's an LGT8F328P by the listing giving a link to WAVGAT's custom hardware package you need to use to have a chance of getting the board to work in a somewhat acceptable fashion.

The LGT8F328P has a 12 bit ADC. It's actually a very interesting chip but due to WAVGAT's shady business practices and low quality software support, it has been nothing but trouble for the Arduino community so far.

Johan_Ha:
I got weird readings from a pot, until I realised I had to connect the pot to 3.3 V and not to 5 V. It was a Netduino, not an Arduino.

With scepticism, I connected the potentiometer to 3.3v instead of 5v, and still the values goes from 0 to 4064, but this time linearly, and not as erratic as when it is connected to 5V, which means that there are no interruptions in the values or jumps, etc.

It seems to be confirmed that the chip is a 12bit chip instead of a 10bit chip from a "real" arduino uno.

UKHeliBob:
It looks like you may have solved the problem but with a multimeter you could measure the resistence of the pot across its range of movement.

I dont think I need to do so anymore, since I confirmed that is a board problem and not a potentiometer problem.

Wawa:
Uno clone should be just fine.
It's usually a user mistake (breadboard, wiring, wrong pot, soldering wires to the rivets, etc).

It is not in this case

pert:
The LGT8F328P has a 12 bit ADC. It's actually a very interesting chip but due to WAVGAT's shady business practices and low quality software support, it has been nothing but trouble for the Arduino community so far.

This seems to be confirmed by the values I got by connecting the potentiometer to 3.3v instead of 5v.