Introduction: Using PWM to Control Lights
Hi guys,
In this project I am going to tell how you can use PWM to control LED's.
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
1. Arduino UNO (you can use any simillar boards you like)
2. Led
3. Some jumper wires
Step 1: Circuit Description.
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.
Step 2: 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);
}
}
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);
}
}