Potentiometer doesn't work

When I run the code below on an Arduino Uno, the monitor always show 1023 even I changed the amount of resistance through the variable resistor. The result was that the LED was always on (e.g. the brightness never changes). I have checked all the hardware connection and the coding, nothing seems wrong. Could anyone tell how to fix this problem? Thanks, Raymond

/* potentiometer
  AnalogReadSerial
  Reads an analog input on pin 3, prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin 3, and the outside pins to +5V and ground.
 
// the setup routine runs once when you press reset:

int potPin=A3;//select the input pin for the potentiometer
int ledPin=13;//select the pin for the LED
int sensorValue=0;

void setup(){
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 3:
  sensorValue = analogRead(potPin);
  // print out the value you read:
  Serial.println(sensorValue,DEC);
  
sensorValue=sensorValue/4;//convert from 0-1024 to 0-255
 analogWrite(ledPin, sensorValue);

  delay(150);        // delay in between reads for stability
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Attach the center pin of a potentiometer to pin 3, and the outside pins to +5V and ground.

Wired to digital pin 3 or analog pin 3? There is a difference.

Yes, I have wired it to analog pin 3 to read the analog signal. To isolate the problem, I have measured the voltage between 5V pin and the ground. It is not 5V. Is it normal? Again, for the power supply, is the USB supply sufficient? Thanks, Raymond

To isolate the problem, I have measured the voltage between 5V pin and the ground. It is not 5V.

What is that voltage? What is the voltage at the center pin of the potentiometer? Does the latter vary when you rotate the shaft?

pin 13 is not a PWM pin, any non-zero value = on
try connecting the LED to 5, 6, 9, 10 or 11 instead

pin 13 is not a PWM pin, any non-zero value = on

Isn't it "on" if the PWM value is > 128, not just non-zero?

AWOL:

pin 13 is not a PWM pin, any non-zero value = on

Isn't it "on" if the PWM value is > 128, not just non-zero?

that's what happens when you post instead of trying it!
exactly as you said :frowning:

int ledPin=13;//select the pin for the LED
int sensorValue;
void setup()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}
void loop() 
{
  for (sensorValue = 0; sensorValue < 256; sensorValue++)
  {
    Serial.println(sensorValue);
    analogWrite(ledPin, sensorValue);  
    delay(100); 
  }
}

Dear All,

Thanks for the help! Eventually I found that one of the jumping wire was broken. I have also used the pin 9 instead. It works now!

Raymond