Fading LED

In this project, you'll learn how to control the brightness of a LED.

You can control the brightness of a LED by specifying how much power you provide to it. This is done by using an analog signal instead of a digital signal.

The analog output pins on the Arduino board are labeled with a ~ symbol. They are pins 3, 5, 6, 9, 10 and 11.

Parts needed:
  • Arduino
  • LED (any color)
  • A 150 Ω resistors (brown-green-brown)
  • Wires
  • Breadboard
Software stuff you'll learn:
LED     150 ohm resistor
1 Making the connections
  • Connect the positive end (long leg) of the LED to pin 3 on the Arduino board.
  • Connect the negative end (short leg) of the LED to one end of the 150 Ω resistor.
  • Connect the other end of the resistor to GND on the Arduino board.
External LED connections
2 Create a new Bare Minimum program by selecting File from the menu
  • then select Examples
  • then select Basics
  • then select BareMinimum

Then type in this program.




Just like the digitalWrite command, the analogWrite command also sends a signal out to the specified pin. The only difference is that instead of just specifying a HIGH or LOW value, any number between 0 and 255 can be used. In this case, it is the value 14 that is assigned to the fadeValue variable using the assignment operator = in the previous line.
Fade LED
3 Run the program and notice the brightness of the LED.
4 Change the fadeValue from 14 to another number between 0 and 255. Run the program and notice the difference in the brightness of the LED.