15 Nov 2012

Controlling LED brightness using Arduino board

Hello readers! In my previous post, I posted my miniproject on 8051 microcontroller based traffic light controller. But now a day, 8051 seems to be very outdated microcontroller. So this time I thought of doing some small experiments using Arduino.

If you don’t know about Arduino, then do checkout this outgoing link (arduino.cc). Basically Arduino is an open source prototyping platform using which you can easily build some extraordinary projects.


In this post, I have used Arduino Atmega328 board to control the brightness of LED using a PWM pin of Arduino.

So to get started, let us assemble the hardware in the breadboard. Follow these steps:

  1. Connect pin 11 (we have used pin 11 in our program) of the arduino to a 220 ohm resistor.
  2. Connect the LED in series with the resistor. Remember; connect the anode of LED to resistor and the cathode to the GND pin of the Arduino.

Now when you are done with your hardware assembling work, upload the program (or the so called sketch in arduino terms) to the Arduino board.

Program:

/*
Program to increase and decrease the brightness of LED
By: Amit Biswal
http://amitbiswal.blogspot.com
*/
int greenLED = 11;
int i;
void setup()
{
  pinMode(greenLED,OUTPUT);
}
void loop()
{
  for(i=0;i<=255;i=i+50)
  {
    analogWrite(greenLED,i);
    delay(500);
  }
  for(i=255;i>=0;i=i-50)
  {
    analogWrite(greenLED,i);
    delay(500);
  }
}

Now after you upload your sketch, you can see that the LED is slowly increasing its brightness and when it reaches its maximum value, it decreasing its brightness until it is switched off.

The program is self explanatory. I have used pin 11, which is one the 6 PWM pins available on Arduino. Then I have incremented/decremented the PWM value by a step of 50 units every time. After every increment/decrement, I am giving a delay of half second, so that human eye can observe the changes happening.

You can watch the demo video of this experiment, to get a clear idea of what is happening.



If you have any doubt or suggestions then do comment below and let me know.
Related Post :


3 comments:

  1. Thanks for continuing to write such wonderful articles, It is very helpful.

    ReplyDelete
  2. Its really nice to visit your post as we can get from here knowledge about LED brightness.

    ReplyDelete
  3. Thanks for continuing to write such wonderful articles..

    ReplyDelete

If you liked this blog then Join me at:
Facebook
Twitter
RSS