In the previous tutorials[1][2], we have discussed how to blink LEDs using Arduino boards. In this work, we will discuss how the brightness of LED can be controlled by controlling the applied voltage. This project is also known as LED Dimmer circuit using Arduino. At full voltage, the brightness of the LED is highest and at low voltage the LED brightness is also low. This way brightness of an LED can be controlled. The voltage of the LED is controlled by Pulse Width Modulation (PWM) technique. Using the PWM technique the voltage is calculated as
This experiment demonstrates the use of the function analogWrite(). This function will generate a steady rectangular wave of the specified duty cycle until the next call to analogWrite(). This rectangular wave or PWM signal is then converted to equivalent voltage by a simple RC filter.
Required Components for LED Dimmer
- Arduino Uno Board
- LED
- 100 Ohm Resistor.
- Jumper Wires.
- Breadboard.
Connection
The digital pin 9 (PWM for 490 Hz) of the Arduino is connected to the positive terminal of the LED and the negative terminal of the LED is connected to the GND pin of Arduino. LED dimmer circuit is shown in Figure 1.
LED Dimmer using Arduino Code
int led = 9 ; // the pin that the LED is attached to
int brightness = 0 ; // how bright the LED is
int fadeAmount = 5 ; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup ( ) {
// declare pin 9 to be an output:
pinMode ( led , OUTPUT ) ;
}
// the loop runs over and over again forever:
void loop ( ) {
// set the brightness of pin 9:
analogWrite ( led , brightness ) ;
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount ;
// reverse the direction of the fading at the ends of the fade:
if ( brightness == 0 || brightness == 255 ) {
fadeAmount = - fadeAmount ;
}
// wait for 100 milliseconds to see the dimming effect
delay ( 100 ) ;
}
Conclusion
In this project, we have demonstrated that how PWM can be used in dimming LED. Also shows how to use the PWM pins of Arduino. This basic project is useful for some beautiful projects on LED chaser circuit and for home decoration purpose. Anyone can use it as a DIY project according to their needs.