Control an LED With PWM Output
by dev.alessiobigini in Circuits > Arduino
10753 Views, 24 Favorites, 0 Comments
Control an LED With PWM Output
![10966922_718353928262563_2052976409_n.jpg](/proxy/?url=https://content.instructables.com/F7M/MM1L/I6SNWPKC/F7MMM1LI6SNWPKC.jpg&filename=10966922_718353928262563_2052976409_n.jpg)
![duty_cycle.gif](/proxy/?url=https://content.instructables.com/F1X/4X0N/I6SNWPL8/F1X4X0NI6SNWPL8.gif&filename=duty_cycle.gif)
As you may have noticed in the Arduino board (Uno, Mega-etc.) Are present some PIN that have next a symbol like a wave.
This symbol indicates that the output can also be used in "PWM" or "Pulse-width modulation".
Using this function, it is possible to vary, for example, the frequency of switching on and off of an LED.
The Circuit
![Cattura di schermata (17).png](/proxy/?url=https://content.instructables.com/F3F/PY1M/I6SNWPKY/F3FPY1MI6SNWPKY.png&filename=Cattura di schermata (17).png)
First we need to:
- Arduino Uno
- A resistor 220Ohm
- A LED
- Breadboard
- Wires for links
Mounted the circuit as described in the picture
The Sketch
![10968112_718353938262562_350337577_n-e1423230337722.jpg](/proxy/?url=https://content.instructables.com/FKL/IUEG/I6SNWPKN/FKLIUEGI6SNWPKN.jpg&filename=10968112_718353938262562_350337577_n-e1423230337722.jpg)
// Created by //
// Alessio Bigini 2015 //
// http://alessiobigini.it //
int lum = 0;
void setup()
{
pinMode(9, OUTPUT);
}
void loop()
{
for (lum = 0; lum < 255; lum++ )
{
analogWrite(9, lum);
delay(10);
}
for (lum = 255; lum > 0; lum-- )
{
analogWrite(9, lum);
delay(10);
}
}
Now load the sketch into your board
In this code I used two simple For loops that allow me to increase the variable "Lum" from 0 to 255 and then decrease it.
Downloads
The Video
![Arduino: uscita PWM e LED](/proxy/?url=https://content.instructables.com/FJA/ABSI/I6SNWPPG/FJAABSII6SNWPPG.jpg&filename=Arduino: uscita PWM e LED)