Connect the potentiometer to A0 Pin and read the analogue voltage
Write that analogue voltage to the PWM Pin
Code
/*Paste your code here*/
// Fade an LED using PWM
int ledPin = 9; // Pin with PWM (marked ~ on Arduino Uno)
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int val = analogRead(A0);
analogWrite(ledPin, val); // Set PWM duty cycle
Serial.println(val);
delay(100);
}