Number gived by the potentiometer are random

Hello,

I'm new in electronics and I'm trying to understand some basics with the starter kit, but when I turn the potentiometer on my circuit, the serial monitor give me random number.

I tried to change the potentiometer but that don't seem to resolve the problem...

My code :

int const potPin = A0;
int potVal;

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

void loop() {

  potVal = analogRead(potPin);
  Serial.print("potVal : ");
  Serial.println(potVal);

  delay(100);
}

My arduino :



Thanks for your answer !!

Please post a schematic (wiring diagram).

Also please post a pinout for the potentiometer.

get rid of the capacity at first.

1 Like

It is almost certain that you have wired it up wrong, or the connectors are not making good contact.

Sadly we can't see a complete picture of how it is wired up because no picture shows everything.

But I can see you are just using wires striped to push into your connectors. This makes it difficult to make a good contact. You should use wires with crimped pins to make your connections.

It's probably wired wrong. ...The physical connections to the pot might not be what you think... (And I can't tell from the pictures.)

Random readings and no effect from the pot usually means there's no actual connection to the analog input. i.e. It's "floating" to an unknown value.)

Do you have a multimeter? With a multimeter you can check the pot, the connections, and the voltage. ...If electronics is going to be your hobby you need a multimeter, and a cheap multimeter is better than no multimeter.

If you connect A0 to ground it should read zero. If you connect A0 to 5V it should read 1023. (Disconnect the pot from A0 during the experiment.) That can confirm that your Arduino & code are working.

I test the pot using a multimeter, and it works well.

Also, if I connect A0 to 5V, it give me 1023 and if I connect A0 to ground, it give me 0.

Here are some pictures of the pot and the wires:



Ask if you need other pictures !

Can you take the view in picture 1 you just posted and take it from the angle looking directly down so the green wire attaching the wiper of the pot is at the center of the picture.

Also the pot might not be making good contact so you could try moving the pot a few holes to the left or right. That will mean moving the two ends of the pot as well.

OK. Check the volage at the pot terminals to make sure it's getting 5V, 0V on the other end, and 0-5V variable on the wiper as you rotate it. If you are getting 0-5V out of the pot, that voltage is (obviously) not getting to the A0 pin.

Ok I just move the pot to another holes and... well that works !

Thank you for your help !

1 Like

Breadboards are not designed to accommodate pins of all sizes. Oversized pins will bend the internal contacts, and later a normal wire or pin will not insert reliably. Sometimes I've twisted flat pot pins 90 degrees so the flat side is parallel with the strips, fits better. Sometimes I solder wires to something if it won't fit.

Yep :+1: !

Or solder the component on a piece of PCB and add headers to make it a clean insert (BYOS™ = build your own shield)

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