#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); } // the number of the LED pin //const int ledPin = 4; // 16 corresponds to GPIO16 // //// setting PWM properties //const int freq = 5000; //const int ledChannel = 0; //const int resolution = 8; // //void setup(){ // // configure LED PWM functionalitites // ledcSetup(ledChannel, freq, resolution); // // // attach the channel to the GPIO to be controlled // ledcAttachPin(ledPin, ledChannel); //} // //void loop(){ // // increase the LED brightness // for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){ // // changing the LED brightness with PWM // ledcWrite(ledChannel, dutyCycle); // delay(15); // } // // // decrease the LED brightness // for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){ // // changing the LED brightness with PWM // ledcWrite(ledChannel, dutyCycle); // delay(15); // } //}