I have been trying to figure out an issue with my potentiometer

I set up the setup and program (slightly altered to my own liking)

I am not new to the world of programming but new to engineering anf arduinos. I am using the exact same Elegoo kit as he is and I haven't noticed any problems yet, the only thing I have found weird is the potentiometer. My potentiometer for some reason, upon being plugged in, gives me two different scenarios.
I have it set up to give values from 0 to 5 (as in volts) instead of 0 to 1023. I just think it is simpler for me to understand that way.

Scenario One: The number usually is 5, but sometimes it gives random values, like goes from 5 to 2 in 100 milliseconds, and back up to 5

Scenarip Two: This one is more commo, and what happens is (without touching the dial) the value will fluctuate from 5 to 0 and back up to 5, it will stay at 5 for a bit and do the same over and over, turning the dial has minimal effect if anytbing.

I really need to know if my potentiometer is working for a school project I have coming up, and I want to know if mine is broken, or if I am using it incorrectly somehow. Feel free to ask questions, I am desperate. Thank you guys!

p.s if my current one is broken/ bad quality, what brand would you recommend me getting a replacement for/
Also please do not use advanced language because I am new to this arduino thing and so far am enjoying it, I just want to ensure that I understand the problem and know how to solve it next time.

How exactly did you connect the potentiometer ? Please share your sketch.

filyxx:
I set up the setup and program (slightly altered to my own liking)

So rather than posting a link to a video of something that isn't what you are using please post YOUR program code and a schematic or at least clear picture of YOUR setup.

My first guess is that you're trying to plug the potentiometer directly into a breadboard and it isn't making good connections. Second guess, there's something wrong with your code.

Steve

No one on here is going to watch a 30 minute video so please share your circuit diagram and your code.

Sorry about that. Here is the way i hooked it up
https://drive.google.com/file/d/15j8n-NYMH9KWC94bwUArZtET7sF6CV9b/view?usp=sharing
https://drive.google.com/file/d/15vQc38UM6vTuJiyHQayiSTHjoESyb8ke/view?usp=sharing

Here is the code I used
int readV = A0;
int readVal;
float V2;
int wait = 100;
String message = "Potentiometer Voltage is ";

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

void loop() {
readVal = analogRead(readV);
V2 = (5. / 1023.) * readVal;
Serial.println(message + V2);
delay(wait);

}

Your 100mS delay is too short.
Try increasing it to 300 to 500 mS.

raschemmel:
Your 100mS delay is too short.
Try increasing it to 300 to 500 mS.

Id doesn't matter in this case. Most likely just a connection issue. I'd recommend to solder wires directly to pot.

alesam:
Id doesn't matter in this case. Most likely just a connection issue. I'd recommend to solder wires directly to pot.

By solder do you mean actually solder, or just connect it directly to the arduino with the female to male wires?

raschemmel:
Your 100mS delay is too short.
Try increasing it to 300 to 500 mS.

:) Thank you! Someone else said it wont work but I will definetely try it, it's worth a shot. As long as my potentiometer works and I can figure out what the problem was idc

FYI, the standard procedure is to use a loop to take 10 measurements and then add them up and divide by 10
to get the average. It's called sample averaging.

raschemmel:
FYI, the standard procedure is to use a loop to take 10 measurements and then add them up and divide by 10
to get the average. It's called sample averaging.

I see, but I still am wondering if the potentiometer is broken or not. Thanks for the heads up though! :slight_smile:

filyxx:
By solder do you mean actually solder, or just connect it directly to the arduino with the female to male wires?

I'd take male-mail dupon wires and solder one pin of each to the pot. Then use other pins to connect pot to arduino

alesam:
I'd take male-mail dupon wires and solder one pin of each to the pot. Then use other pins to connect pot to arduino

The male to female wires? I tried doing that and connecting it to the breadboard but not directly to the arduino.

TO review some of the previous comments:

100ms is NOT too short.

On ATmega based boards (UNO, Nano, Mini, Mega), it takes about 100 microseconds (0.0001 s) to read an analog input,

Breadboard connections are usually OK; however the pins on the back of your pot may be too short to make a good connection. So maybe soldering wires to them would improve the connection.

I've tested your code and made some modifications as you will see to take 16 readings and average them

//int readV = A0;
#define readV 0
int readVal;
float V2;
int wait = 100;
String message = "Potentiometer Voltage is ";

void setup() {
  Serial.begin(57600);  //9600 was good for teletypes, a bit unnecessary today!
}

void loop() {
  readVal = 0;
  for (int i = 0; i < 16; i++) {
    readVal += analogRead(readV);
    delay(10);
  }
  readVal = readVal >> 4;  //divide by 16
  V2 = (5. / 1024.) * readVal;
  Serial.println(message + V2);
  delay(wait);
}

The code is working fine so either you have a bad pot - not unknown - or poor connections.

Finally, have a look at my tutorial on posting schematics and images

johnerrington:
Breadboard connections are usually OK; however the pins on the back of your pot may be too short to make a good connection. So maybe soldering wires to them would improve the connection.

Okay I'll definetly try it. But is it possible to do it in a way where I don't solder? If not I can probably find a way to do that.

Post a picture of your pot so we can see the rear connections.

But generally to get reliable good connections solder is the way.

Here is my pot, after I read what you said and checked the middle pin is definetly smaller than the input and grounding pin. For some reason when I add two images it gives me a "too large" error so I just attached the bets image out of the three I had taken

Okok I know you didn't want google drive links but the image system is glitching out for me, I am senging this message because the image didnt show up on the previous post, I am going to try it again, but I am sending a google drive link just incase. Sorry!

As I suspected the pins are probably too short to make a good connection to breadboard.

I use these and solder single core wire to the terminals, which then fits nicely in breadboard.

You need to use something like paint.net to reduce the size of your image and try different formats -
.gif, .jpg .png (NOT .jpeg, .JPG etc)

Allowed file types: doc, gif, jpg, mpg, pdf, png, txt, zip, c, h, cpp, ino, pde
Restrictions: maximum total size 2 MB, maximum individual size 2 MB

Electronic-Component-Potentiometer.jpg

Electronic-Component-Potentiometer.jpg

Did you try to put it in a breadboard?
Only way to test it is outside a breadboard with
alligator or clip jumpers or solder 22 AWG solid
wire to leads