Build the following circuit:

Enter the following code:
// Pins
const int knob_pin = A0;
const int led_pin = 5;
void setup() {
pinMode(led_pin, OUTPUT);
}
void loop() {
// Read knob value (0 - 1023)
int val = analogRead(knob_pin);
// Convert knob value to PWM value (0 - 255)
int brightness = map(val, 0, 1023, 0, 255);
// Set LED brightness
analogWrite(led_pin, brightness);
}
Simulator: https://tinkercad.com/things/bs1jVzFCfZ8