loading

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.

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

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

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

Step 4: Breadboarding!

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

Step 5: 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

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

Step 7: The LED

Now attach the LED on the breadboard.

Step 8: 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.

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!

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

<p>This was my first project with the Uno. Thank you :)</p>
You're welcome!! Glad you enjoyed it!! :-)
<p>Nice! </p><p>WARNING, and to answer @johnstallone1<br>Lights can only be dimmed by this method using PWM (pulse width modulation) pins, which are Pins 3, 5, 6, 9, 10, or 11. </p><p><br>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.</p><p><br>If you want to change the pin, be sure to update the LED pin in the code &quot;int led = 9&quot; replacing 9 with the new pin.</p>
<p>i did everything . just changed the pin number to 13. nothing is happening</p>
<p>i did everything . just changed the pin number to 13. nothing is happening</p>
<p>This is a great Instructable for someone just getting started with Arduino. I might recommend a Fritzing diagrams for more complicated projects.</p>
<p>Looks like a job for an ATTiny not an ARDUINO UNO</p>

About This Instructable

9,822views

108favorites

License:

More by DIYmasters:How to Install Ubuntu Onto a Flashdrive How to Control an RGB LED with an Arduino Easiest Method to Make an LED Fade with the Arduino Uno 
Add instructable to: