All submissions

LED Brightness Control Using Potentiometer

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

 

 

 

 

 

Submit Your Solution

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