Why does my potentiometer sending random values?

hello,

why does my potentiometer give me random values to arduino nano?

Here's the code:

int pot = A2;

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

void loop() {
  // put your main code here, to run repeatedly:
  int potval = analogRead(pot);
  Serial.println(potval);
  delay(100);
}

Do you have both positive and negative wired to the potentiometer?
e.g. https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput

thanks for your reply. Yes, I had wired positive and negative to potentiometer.

What range of random values do you see if you don't move the pot ?

Does the value change when you move the pot ?

What value of pot are you using? 10K is usually recommended but 1K will also work and might give less random results. 100K will also work but might give more random results. 1M, 10M etc. too high and will give very random results.

no. the value doesn't change.

Post a bright, clear photo of your circuit so we can clearly see where every wire is connected.

ok. I will do that.

Post a diagram of your circuit and check the actual circuit very carefully

Are you using a breadboard and if so is it the type that has breaks in its power rails ? If the latter then are you sure that the 5V and GND from the Arduino are actually connected to the pot ?

Thanks for trying, but that picture is not much help as it not clear which wire is connected to what

What is the purpose of the LED ?

Does plugging the green wire into pin A2 instead of A1 help ?

1 Like

I got the arduino nano yesterday and now I experimenting with the nano. The led is only for fun purpose.

I will try

sadly:( it doesn't work.

Please read the posts above and answer the questions you missed.

Check each of those dupont wires with your multimeter using the resistance range. Each wire should have zero resistance, or very close to zero.

yes. it has.

Assuming you are using the sketch in post #1:
disconnect any existing wire from A2 then connect pin A2 to the 5volt terminal.
Do you see a value of 1023 in the serial monitor ?

no. I don't see 1023.

If you replace the sketch in post #1 with the following sketch, do you notice any difference ?

int pot = A2;
int led = 13 ;
bool flash = false ;

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

void loop() {
  // put your main code here, to run repeatedly:
  int potval = analogRead(pot);
  Serial.println(potval);
  delay(100);
  digitalWrite( led, flash ) ;
  flash = !flash ;
}