LED Brightness Control Using PWM

Solving Approach:

How do you plan to solve it?

step 1:  Declare gpio pwm  pin  or led

step2 : initialize led as output

 

step3: will write code for led  so led will blink for 2s and off for 1s using delay method with analogwrite function.
 

 

 

Code

/*Paste your code here*/


int ledPin = 9; // Pin with PWM (marked ~ on Arduino Uno)

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

void loop() {
  // Increase brightness
  for (int brightness = 0; brightness <= 255; brightness++) {
    analogWrite(ledPin, brightness); // Set PWM duty cycle
    delay(2000);
  }

  // Decrease brightness
  for (int brightness = 255; brightness >= 0; brightness--) {
    analogWrite(ledPin, brightness);
    delay(1000);
  }
}

 

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!