#include // Potentiometer is connected to GPIO 15 or A0 const int potPin = 15; //May be change according to your connections const int LEDPin=5; // setting PWM properties const int freq = 5000; const int ledChannel = 0; const int resolution = 8; // The value of potentiometer is being stored in this vairable int ValuePot = 0; int brightness=0; void setup() { Serial.begin(115200); delay(1000); ledcSetup(ledChannel, freq, resolution); // attach the channel to the GPIO to be controlled ledcAttachPin(LEDPin, ledChannel); } void loop() { // Reading potentiometer value ValuePot = analogRead(potPin); //AnalogRead function o get value of Potentiometer brightness=ValuePot/16; // analogWrite(LEDPin,brightness); // ledcWrite(LEDPin,brightness); Serial.println(ValuePot); Serial.println("\nLED value"); Serial.println(brightness); for(int dutyCycle =0 ; dutyCycle<=brightness; dutyCycle++){ // changing the LED brightness with PWM ledcWrite(ledChannel, dutyCycle); } //Serial.println(ValuePot); //To print the value of Potentiometer delay(500); }