17. LED Brightness Control Using Potentiometer

Back To All Submissions
Previous Submission
Next Submission

Solving Approach:

How do you plan to solve it?

  •  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);
    }
    
    
     

Output

Video

Add video of output (know more)

 

 

 

 

 

Photo of Output

Add a photo of your hardware showing the output.

 

 

 

 

Was this helpful?
Upvote
Downvote