Easiest Method to Make an LED Fade With the Arduino Uno

by DIYmasters in Circuits > Arduino

11328 Views, 113 Favorites, 0 Comments

Easiest Method to Make an LED Fade With the Arduino Uno

IMG_7152.JPG
IMG_7156.JPG
IMG_7158.JPG

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!

What You Will Need.

IMG_7161.JPG

1x 220 Ohm Resistor

2x Breadboarding Wires

1x Arduino

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

Attach the Ground Wire to the Arduino

IMG_7162.JPG

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

Attach a Jumper Wire to Pin 9 on the Arduino

IMG_7163.JPG

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

Breadboarding!

IMG_7164.JPG

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

Pin 9 Wire

IMG_7165.JPG

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.

Insert the 220 Ohm Resistor

IMG_7166.JPG
IMG_7168.JPG

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

The LED

IMG_7169.JPG
IMG_7170.JPG

Now attach the LED on the breadboard.

Plug in the Power!

IMG_7173.JPG

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

Upload the Code to Your Arduino.

Arduino_Fade.jpg

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.

Congratulations!

IMG_7152.JPG
IMG_7156.JPG

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