17. LED Brightness Control Using Potentiometer

Back To All Submissions
Previous Submission
Next Submission

Solving Approach:

How do you plan to solve it?

Connect pot to any analog pin and use map function to scale the value from 0 to 1023 to 0 to 255. Used this scaled value to control the LED.

Code

#define POTENTIOMETER A0
#define LED 9

int potValue = 0;

void setup() 
{
  pinMode(POTENTIOMETER, INPUT);
  pinMode(LED, OUTPUT);

}

void loop() 
{
  potValue = analogRead(POTENTIOMETER);

  potValue = map(potValue, 0, 1023, 0, 255);

  analogWrite(LED, potValue);

}



 

Output

Video

Video of output (know more)

 

 

 

 

 

Photo of Output

 

 

 

 

 

Was this helpful?
Upvote
Downvote