Project 2

PWM Dimming LED - Arduino Uno

Project Description

A PWM LED Light is an LED lighting system that uses Pulse Width Modulation (PWM) to control the brightness of the LED. Instead of changing the voltage, PWM rapidly switches the LED on and off at high speed. By adjusting the duty cycle (the percentage of time the LED stays ON during each cycle), the brightness can be smoothly increased or decreased.

PWM is a popular technique for controlling electronics using an on off technique where the total energy delivered is controlled by the ratio of the on-off cycle. Read more here

PWM is used in applications ranging from motor speed control, lighting, sound generation, battery charging, switching power supplies and much more. 

Components
  • Arduino Uno
  • LED(x3) - any colour
  • 220 Ohm Resistors(x3) - [Red-Red-Brown-Gold]
  • Jumper wires
  • Breadboard
Code

//Project 2
//Three LEDS are controlled by the Arduino to slowly dim and brighten using built-in the analogWrite() PWM function

int d = 5;
void setup() 
{
  pinMode(3,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
}
 void loop ()
 {
  for ( int a=0; a<256; a++)
  {
   analogWrite(3,a);
   delay(d);
   analogWrite(5,a);
   delay(d);
   analogWrite(6,a);
   delay(d);
  }
  for ( int a=255;a>=0;a--)
  {
    analogWrite(3,a);
    delay (d);
    analogWrite(5,a);
    delay (d);
    analogWrite(6,a);
    delay (d);
  }
  delay (200);
 }

Taking things further
  • PWM motor speed controller (motor has to be driven through a transistor or motor driver
  • Remote controlled light dimmer
  • Beeper volume control: PWM can be used to control the volume of a buzzer