Arduino not reading potentiometer values

Hello, i have a problem. My arduino leonardo is not reading potentiometer values until i turn it halfway through its range of rotation. Potentiometer is not the problem i have replaced it and it still doesnt work. This is the code that i am using:


#include <Joystick.h>

#define potpin A1

int throttle_ = 0;
int gear = 0;
int some = 0;                    
int some1= 255;

Joystick_ Joystick(0x12,JOYSTICK_TYPE_JOYSTICK,1,0,true,true,false,true,false,false,true,true,false,false,true);

const bool initAutoSendState = true;

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

pinMode(9,INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
int variable1 = 461;
int variable2 = 464;
int variable3 = 0;
int variable4 = 0;

throttle_ = analogRead(A5);


if(throttle_ > variable1){
throttle_ = variable2;
}
if(throttle_ < variable3){
throttle_ = variable4;
}


  Joystick.setThrottle(throttle_);
  Serial.println(throttle_);





}

You have potpin defined as A1 but you are reading A5 for throttle

I dont use the potpin.I just directly type in A5.It serves no purpose.

You need to use either A0,A1,A2,A3, or A4 for the pot.
A5 and A6 are actually being used by the Joystick

What do you mean? That is just a library, but it is used for throttle.I tried to use A0 and A1, but nothing works.

Do you have one end of the pot connected to 5V, the other end connected to GND and the middle pin connected to A0.

Yes.

The middle connected to A5.

see analogRead()

I tried to use A0.It doesnt work.

Arduino doesnt work.At least i think so.On serial monitor it shows a dead zero until i turn the potentiometer halfway.

it works on my board

OK I think I know whats wrong If it's a logarithmic pot, then that will happen
You need a linear pot

The previous pot worked for a long time.It started to act like this like today.

Is the pot you are using now the same as the previous.

I think that they are both linear.

Do you have an ohmmeter?

yes

Connect the ohmmeter leads to the two end pins of the pot and measure the resistance. This is the pot resistance.

Then connect one one lead to one end and one the the middle. Set the pot half way and read the resistance. It should be around half of the reading of the pot resistance.

Example pot resirtance =10K

With pot set halfway =5K

Disconnect it from the arduino before you do this

I already tested it.The pot isnt linear.But the one linear pot that i have it still doesnt change the resistance much at the beginning. I am not using the whole range of the pot.