All submissions

LED Brightness Control Using Potentiometer

Solving Approach:

How do you plan to solve it?

  • Connections
    • Potentiometer middle pin → Arduino A0 (Analog input).
    • Potentiometer side pins → 5V and GND.
    • LED (with resistor, e.g. 220Ω) → PWM-capable pin (e.g., D9).
  • Analog Input (ADC)
    • analogRead(A0) returns values from 0 → 1023 (10-bit ADC).
  • PWM Output
    • analogWrite(pin, value) takes 0 → 255 (8-bit duty cycle).
  • Mapping
    • Use map() to scale potentiometer values:
      ledValue = map(potValue, 0, 1023, 0, 255);
  • Write to LED
    • Send mapped value to LED using analogWrite().

 

Code

/*Paste your code here*/
const int potPin = A0;   // Potentiometer input pin
const int ledPin = 9;    // PWM pin for LED

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

void loop() {
  int potValue = analogRead(potPin);              // Read potentiometer (0–1023)
  int ledValue = map(potValue, 0, 1023, 0, 255); // Map to 0–255 for PWM
  analogWrite(ledPin, ledValue);                 // Adjust LED brightness
}



 

Output

Video50+ Free Arduino & Microcontroller Images - Pixabay

 

Add video of output (know more)

 

 

 

 

 

Photo of Output

Add a photo of your hardware showing the output.

 

 

 

 

 

Submit Your Solution

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