[SOLVED] Is My Potentiometer Broken?

Hi There,
I am currently on chapter 3.13 on the arduino tutorial but my LED light program isn’t working. It is currently flashing at random intervals. I’ve copied the code straight off the website to make sure I didn’t type anything wrong and it is still flashing randomly. Then I moved on to the serial monitoring unit to see what my potentiometer was doing and this is what showed up:

Button: 1 Pot: 1001 Pot/4: 250
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 317 Pot/4: 79
Button: 1 Pot: 0 Pot/4: 0
Button: 1 Pot: 999 Pot/4: 249
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 768 Pot/4: 192
Button: 1 Pot: 32 Pot/4: 8
Button: 1 Pot: 0 Pot/4: 0
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 555 Pot/4: 138
Button: 1 Pot: 0 Pot/4: 0
Button: 1 Pot: 369 Pot/4: 92
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 304 Pot/4: 76
Button: 1 Pot: 0 Pot/4: 0
Button: 1 Pot: 1012 Pot/4: 253

The Pot seems to be fluctuating consistently without me touching anything and therefore my LED is also fluctuating. Also, no matter which way I spin the potentiometer, the results are still the same.

I’m pretty sure something is broken here but I don’t know what. Please help!

Hey, Bruce
If your pot is behaving as above then something is definitely up - looks like an intermittent connection.
It’s often helpful if you upload a neat picture of your setup so we can see how the wiring looks.

Have you ever wired this pot up incorrectly?
If you have ever connected the pot incorrectly and applied power you may have cooked the resistive element.

A split test, to make sure everything else works would be to substitute the pot for a voltage divider made out of two fixed resistors (each > 1k)
If you have, say, a 4k7 and a 10k then you should be able to read off values around 338 and 675 from your analog channel - depending on which way around the voltage divider is made.
The way we wire up potentiometers is just like a continuously variable voltage divider.

Hey, Michael,
I’ve uploaded some photos of my setup. It would be great if you can take a look.
Meanwhile, I’m gonna try and work out how to make your voltage divider (extra assistance welcome) but I should be alright.

Many Thanks,
Bruce

The layout of the wiring to the pot appears ok.

Do you measure 5V across the two outer tabs of the pot while the circuit is powered?
If so, measure the voltage between the ground-leg of the pot and the wiper (middle leg), and rotate the knob through it’s full scale. You should get a reading that moves from 0V at one end, to 5V at the other. In the middle you should get about 2.5V.
If you don’t, it will probably be beneficial to rebuild the circuit in different points of the breadboard. Breadboards can get a bit loose if you plug wide pins into them, and the thin pins on the jumper leads might not be making good contact.

I typed up a little program to see the outer tabs’ voltage without turning it. It looked like this:
otValueL: 1023 PotValueR: 1023
PotValueL: 1023 PotValueR: 1023
PotValueL: 1023 PotValueR: 1023
PotValueL: 1023 PotValueR: 1023
PotValueL: 1023 PotValueR: 1023
PotValueL: 1023 PotValueR: 1023
PotValueL: 617 PotValueR: 701
PotValueL: 0 PotValueR: 0
PotValueL: 0 PotValueR: 0
PotValueL: 1023 PotValueR: 1023
PotValueL: 1023 PotValueR: 1023
PotValueL: 1023 PotValueR: 1023
PotValueL: 1023 PotValueR: 1023
PotValueL: 1023 PotValueR: 1023

Then I went back to the previous program from your website. This is what the results looked like:
This was when it was in the middle:
Button: 1 Pot: 0 Pot/4: 0
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 247 Pot/4: 61
Button: 1 Pot: 0 Pot/4: 0
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 228 Pot/4: 57
Button: 1 Pot: 0 Pot/4: 0
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 978 Pot/4: 244

And this was when it was on the sides (both sides are the same):
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 967 Pot/4: 241
Button: 1 Pot: 861 Pot/4: 215
Button: 1 Pot: 823 Pot/4: 205
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 891 Pot/4: 222
Button: 1 Pot: 852 Pot/4: 213
Button: 1 Pot: 842 Pot/4: 210
Button: 1 Pot: 1023 Pot/4: 255
Button: 1 Pot: 1023 Pot/4: 255

(I did all my testing in a new spot in the breadboard)

I still don’t know how to build a voltage divider. :wink:
Thanks.

I’m not sure I follow.

EDIT: Oh I see, so you had two analog channels connected to the pot’s outer tabs to measure their voltages? If that’s the case you should see 1023 & 0. Not 1023 & 1023.

But given your results there’s definitely still something wrong. For your test with the pot in the middle you’d expect a stable reading in the vicinity of Pot: 512.
Have you tried using a different analogue channel? Of course you’d have to change the channel in the code as well.
We’re working with a Chinesium-grade arduino here, so the chip might be counterfiet, but that’s a long shot.

My advice, remove all other circuitry from the breadboard, and start with a sanity check. Connect the analog pin to 5V and measure that (1024) then move the connection to ground and measure that (0)

If that pans out, try a voltage divider circuit.

This is a voltage divider, with three scenarios prescribed in a table. I’ve included the voltage you should expect to measure at the analogue input (eg. using a multimeter), as well as an approximate ADC value that the Arduino should produce. I’ve drawn the voltage divider connected to A0, but of course you could choose which channel you connect to.
Forget buttons and logic and anything else, just stream the raw measurement over serial.

If you measure a voltage present at the analog input that doesn’t match near-enough to the corresponding ADC value then it’s probably time to get some new hardware

This all seems very low-level and slow, I know. But there’s valuable troubleshooting experience to be gained. Half the battle is inventing valid experiments to test your circuit.

That diagram was extremely helpful. Thank you!

For the 10k/10k voltage divider, this is what showed up:
A0 = 511
A0 = 511
A0 = 510
A0 = 510
A0 = 511
A0 = 511
A0 = 512
A0 = 511
A0 = 511
A0 = 511
A0 = 511
A0 = 511
A0 = 511
A0 = 512

The ADC value jumps from 1023 to 512-ish as I move the Ground jumper wire around in its breadboard hole. Without me holding the wire to its side, it stays as 1023.


10k/4k7:
A0 = 384
A0 = 385
A0 = 385
A0 = 384
A0 = 385
A0 = 384
A0 = 385
A0 = 384
A0 = 385
A0 = 385
A0 = 384
A0 = 385
A0 = 384
A0 = 384

The serial monitor shows 1023 without me holding the black ground jumper wire down to a corner.
4k7/10k:
A0 = 651
A0 = 649
A0 = 651
A0 = 651
A0 = 650
A0 = 651
A0 = 649
A0 = 650
A0 = 650
A0 = 651
A0 = 653
A0 = 651
A0 = 650
A0 = 652

Again, I had to hold the ground jumper wire to a corner for the serial monitor to show it in the 600’s.

Perhaps my breadboard is broken? It is also worth mentioning that I don’t have a 4k7 resistor so I used 4×1k resistors and 2×330ohms resistors to replace it.

I tried testing in different analogue inputs and different holes in the breadboard. I always have to hold the ground wire down.

Many Thanks,
Bruce

P.S. sorry for not explaining clearly to what I did earlier with the outer tabs of the potentiometer.

Hey, Result!

The combination of your breadboard and those (very thinly pinned) jumper wires was resulting in an intermittent connection! The spring contacts in the breadboard may be a little sloppy, but the jumpers are likely more to blame.

Good on you for actually laddering-up a whole line of series resistors too :stuck_out_tongue:

Now for some intuition building:
The formula for calculating the output voltage of a voltage divider like we have here is:
Vout = Vin * R2/(R1+R2)
Where Vin is the supply voltage (5V in this case)
That’s how I knew roughly what your readings should be.
Since 5V will show as the full-scale ADC reading (1023), you can calculate the expected ADC value with:
(Vout / 5) * 1023

It’s worth noting you could have repeated this experiment with 4k7&10k, or 470k&100k and had the exact same ADC reading.
The absolute resistance values are not so important, but rather the ratio (This is why you could use a 1k, 10k or 100k pot and they behave the same).

So now a bit of homework, if you’d like. Given the resistance values that you had to make up, what would your expected ADC readings be. Do they match close-enough to what you observed?

Vout = 5*4.66/(10+4.66) = approx. 1.59
ADC = Vout/5*1023 = approx. 325.2

Thank you for solving this problem. I also learnt a lot in this process. :smiley:

2 Likes

Glad you got there in the end @Bruce48683! Please do share your next projects here in the forum!