LED Brightness Control Using Potentiometer

Solving Approach:

How do you plan to solve it?

 

 

Code

/*Paste your code here*/

const int potPin = A0;     // Potentiometer input
const int ledPin = 9;      // PWM output pin

void setup() 
{
  pinMode(ledPin, OUTPUT);
}

void loop() 
{
  int adcValue = analogRead(potPin);     // 0 – 1023
  
  int pwmValue = adcValue / 4;           // Scale to 0 – 255
  
  analogWrite(ledPin, pwmValue);         // Update brightness
}

 

Output

Video

Add video of output (know more)

 

 

 

 

 

Photo of Output

Add a photo of your hardware showing the output.

 

 

 

 

 

Upvote
Downvote

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!