Introduction: Easiest Method to Make an LED Fade With the Arduino Uno

Picture of Easiest Method to Make an LED Fade With the Arduino Uno

Hi everyone, this is my first Instructable, and in it, I'll be showing you how to fade an LED with an Arduino Uno , 2 Jumper wires, 1 Resistor, and a breadboard.

Enjoy!

Step 1: What You Will Need.

Picture of What You Will Need.

1x 220 Ohm Resistor

2x Breadboarding Wires

1x Arduino

...and a computer with the Arduino IDE software installed.

Step 2: Attach the Ground Wire to the Arduino

Picture of Attach the Ground Wire to the Arduino

Attach a jumper wire to the ground (GND) output pin on the Arduino.

Step 3: Attach a Jumper Wire to Pin 9 on the Arduino

Picture of Attach a Jumper Wire to Pin 9 on the Arduino

Next, attach a jumper wire to Pin 9 on your Arduino.

Step 4: Breadboarding!

Picture of Breadboarding!

Now get out your breadboard out and attach the ground wire.

Step 5: Pin 9 Wire

Picture of Pin 9 Wire

Now take the wire leading from pin 9 on the Arduino and attach it behind the non-conductive space in the middle of the breadboard.

The reason for this is because the Arduino does not have a built-in resistor leading out of Pin 9, you will need to put one in of your own. Putting the Pin 9 wire on the other side will keep it from burning out your LED and will provide enough space to comfortably fit the resistor in.

Step 6: Insert the 220 Ohm Resistor

Picture of Insert the 220 Ohm Resistor

Now insert the resistor from the pin 9 wire an plug the other end beside the Ground wire.

Step 7: The LED

Picture of The LED

Now attach the LED on the breadboard.

Step 8: Plug in the Power!

Picture of Plug in the Power!

Now plug in the Arduino into your computer. The board will power on, but the LED will not light up...not yet.

Step 9: Upload the Code to Your Arduino.

Picture of Upload the Code to Your Arduino.

Open the Arduino IDE software, assuming you have already downloaded and installed it. (You can get it for free from: www.arduino.cc/en/Main/Software

Navigate to File>Examples>Basics>Fade. The script is included in the install, but if you do not have it, here it is.

/*
Fade
 This example shows how to fade an LED on pin 9
 using the analogWrite() function.
 This example code is in the public domain.
 */
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 routine 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 30 milliseconds to see the dimming effect
  delay(30);
}

Now upload the code to your board.

Step 10: Congratulations!

Picture of Congratulations!

If you did everything right, after a few seconds, the led will begin to fade.

Comments

VitorM11 (author)2016-01-31

This was my first project with the Uno. Thank you :)

DIYmasters (author)VitorM112016-02-01

You're welcome!! Glad you enjoyed it!! :-)

taobaoed (author)2016-01-08

Nice!

WARNING, and to answer @johnstallone1
Lights can only be dimmed by this method using PWM (pulse width modulation) pins, which are Pins 3, 5, 6, 9, 10, or 11.


Doing this project on, say, pins 2, 4, 7, 8, 12, or 13 will not work. The LED may light up initially at a high write, but it will not dim, only on/off.


If you want to change the pin, be sure to update the LED pin in the code "int led = 9" replacing 9 with the new pin.

johnstallone1 (author)2015-11-06

i did everything . just changed the pin number to 13. nothing is happening

johnstallone1 (author)2015-11-06

i did everything . just changed the pin number to 13. nothing is happening

tcodd86 (author)2015-09-16

This is a great Instructable for someone just getting started with Arduino. I might recommend a Fritzing diagrams for more complicated projects.

grayl (author)2015-09-15

Looks like a job for an ATTiny not an ARDUINO UNO