analogRead(A2) always at 1023 max value potentiometer arduino pro micro

Hi all, I've been working on a DIY handbrake for sim racing. I picked up a cheap arduino pro micro board and a linear sliding 10k potentiometer which suited my needs.

I installed the SparkFun board in the Arduino IDE and when I did the blinking test everyting seemed to work.

See my wiring diagram for the wiring info.

everytime I use analogRead(pin), no matter which pin I use I get the max value of 1023, even when moving the potentiometer slider.

I tested the analog input so I was sure they did work, when I connected a cable directly from GND to A2 I got the value 0, and this was the same for all other pins.

Then I measured the voltages, which were all at around 4.60.

Then to make sure the potentiometer wasn't malfunctioning I measured the Ohm too, and the values changed as expected when sliding the potentiometer.

I tried different usb wires, and different wiring, but no luck.

If I disconnect the power from the potentiometer, so only GND arduino, GND pot and input pin are connected the values go crazy, as soon as I reconnect the power it's stuck at 1023 again.

I'm out of ideas now, does anyone have an idea on what's causing this?

#include <Joystick.h>

void setup()

{pinMode(A2, INPUT); 
   Joystick.begin();}

const int pinToButtonMap = A2;

void loop()

{
Serial.println(analogRead(A2)); 
int pot = analogRead(A2);
int mapped = map(pot,0,1023,0,255);
{Joystick.setThrottle(mapped);}
}

(I'll include the code, not that it matters here I think but just in case anyone asks)



Sounds like a bad (open) ground connection. Did you carefully solder the joints?

Post a closeup, in focus photo.

jremington:
Sounds like a bad (open) ground connection. Did you carefully solder the joints?

Post a closeup, in focus photo.

Hmm should've taken a picture before, I removed all the soldered wires and switched to jumper cables for easier testing. When I soldered I just put the cable through the hole and put solder on top, is that wrong?

Your diagram shows the pot connected to A0. Your sketch says A2...

PaulRB:
Your diagram shows the pot connected to A0. Your sketch says A2...

Yes I know I was testing multiple ports, it doesn't matter which port I use they all give 1023 as output

I just put the cable through the hole and put solder on top, is that wrong?

Yes, the solder has to flow evenly, coat the entire joint and make a good connection.

There are plenty of on line tutorials showing how to solder, and the difference between good and bad solder joints.

jremington:
Yes, the solder has to flow evenly, coat the entire joint and make a good connection.

There are plenty of on line tutorials showing how to solder, and the difference between good and bad solder joints.

I know it's important, but is it really the problem here? Just using jumper wires without soldering doesn't work either, and a jumper cable directly from GND to a pin like A0 does show 0 so it should work right?

I measured the Ohm too, and the values changed as expected when sliding the potentiometer.

Where/how did you test that? At the wiper terminal of the pot or at the Pro Micro's analog input pin? Where did you apply the red and black probes of your multimeter?

PaulRB:
Where/how did you test that? At the wiper terminal of the pot or at the Pro Micro's analog input pin?

At the pot by using a multimeter, red probe at red wire and black probe at the yellow wire (it works at the start and end of the wire)

I know it's important, but is it really the problem here?

You have a problem that looks like an open ground connection. What more do we need to say?

jremington:
You have a problem that looks like an open ground connection. What more do we need to say?

Well um, how to fix it? I forgot to say this is my first arduino project I don't really know what you mean by an open ground connection, I just followed a tutorial and did the exact same wiring as they did. I connect the Arduino to my PC via USB micro so how would you suggest grounding it properly?

don't really know what you mean by an open ground connection

A ground connection that is not actually a connection. It looks like you have wired it up but there is no electrical connection.

With the power off check for continuity with your meter.

This line

If I disconnect the power from the potentiometer, so only GND arduino, GND pot and input pin are connected the values go crazy

Tells us your ground circuit is not making contact somewhere. It would not behave like this if it was.

If you still can’t see it then post a photograph of your wiring and we will see if we can spot where it is not connected.

Grumpy_Mike:
A ground connection that is not actually a connection. It looks like you have wired it up but there is no electrical connection.

With the power off check for continuity with your meter.

This line Tells us your ground circuit is not making contact somewhere.

With what should I connect it? Sorry I'm a newbie to this I just expected it would be grounded via USB to my PC.

Grumpy_Mike:
If you still can’t see it then post a photograph of your wiring and we will see if we can spot where it is not connected.

I will post a picture tomorrow when I solder everything back, it's really a mess of jumper cables now, I can't take a clear picture

Use your meter to measure resistances at the pot wires. Put the pot wiper near the middle. When you measure from Red to Black it should read 10K. When you measure from Red to Yellow it should read about 5K. When you measure from Black to Yellow it should read about 5K. If the Ground (Black) wire is not connected correctly you will get incorrect resistances measuring from Black to Red or from Black to Yellow.

wooter:
At the pot by using a multimeter, red probe at red wire and black probe at the yellow wire (it works at the start and end of the wire)

Ok, now measure with the black probe to the ground pin on the Pro Micro and the red probe to the analog pin.

johnwasser:
Use your meter to measure resistances at the pot wires. Put the pot wiper near the middle. When you measure from Red to Black it should read 10K. When you measure from Red to Yellow it should read about 5K. When you measure from Black to Yellow it should read about 5K. If the Ground (Black) wire is not connected correctly you will get incorrect resistances measuring from Black to Red or from Black to Yellow.

Okay I just measured, with no power. I measured at the pot itself first. Red and yellow shows 5K, black to red and black to yellow doesn't show anything, just 1 at 20k at my multimeter, but so does when nothing is being measured. This is measuring at the POT pins itself, not the wires. Just the starting points where I connected all the cables to.
Edit: at the cables it shows the same values.

wooter:
Okay I just measured, with no power. I measured at the pot itself first. Red and yellow shows 5K, black to red and black to yellow doesn't show anything, [...] so does when nothing is being measured. This is measuring at the POT pins itself, not the wires. Just the starting points where I connected all the cables to.
Edit: at the cables it shows the same values.

So, as we all thought, your Ground connection is broken. If I am correct in assuming that the pot only has three terminals to which you can attach wires, the pot must be broken internally and you will have to get another one.

Hi,
Can you do some measurements for us;
Using these points shown on your image, set the DMM to measure DC Volts.
Connect you circuit to power so it is running.


Connect the Negative Probe of the DMM to the gnd of the controller and leave it there.

Then connect the positive probe to point A and note the voltage as you slide the slider.

Then connect the positive probe to point B and note the voltage as you slide the slider.

Then connect the positive probe to point C and note the voltage as you slide the slider.

Thanks.. Tom... :slight_smile:

TomGeorge:
Then connect the positive probe to point A and note the voltage as you slide the slider.

point A shows 0.00
it does not change when sliding.

TomGeorge:
Then connect the positive probe to point B and note the voltage as you slide the slider.

point B shows 4.60
it does not change when sliding.

TomGeorge:
Then connect the positive probe to point C and note the voltage as you slide the slider.

point C shows 4.63
It does not change when sliding.

none of the points change in voltage when sliding, maybe by 0.02 but that's probably because my hand is not perfectly steady.

Thanks for your help! Clear explanation!