Using PWM to Control Lights

by Abhirup Rudra in Circuits > Arduino

387 Views, 0 Favorites, 0 Comments

Using PWM to Control Lights

20201024_110515.jpg
Hi guys,
In this project I am going to tell how you can use PWM to control LED's.

Supplies

For this project you need,
1. Arduino UNO (you can use any simillar boards you like)
2. Led
3. Some jumper wires

Circuit Description.

20201024_110515.jpg
First we need to connect the LED's cathode pin to the gnd pin of arduino. Then we will connect the anode to the pin 5 of arduino. Now we are all done with the circuits.

Coding.

Now just connect your arduino to your computer and just paste this code in your arduino ide and hit the upload button.
The code is here:
int a = 6;
void setup()
{
pinMode(a,OUTPUT);
}

void loop()
{
for(int p = 0; p <= 255; p = p+2)
{
analogWrite(a,p);
}
delay(200);
for(int p = 255; p >= 0; p = p-2)
{
analogWrite(a,p);
}
}