# Arduino Lesson 2. LEDs

## Overview

In this lesson, you will learn how to change the brightness of an LED by using different values of resistor.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/158/medium800/learn_arduino_overview.jpg?1396780031)

# Arduino Lesson 2. LEDs

## Parts

To carry out the experiment described in this lesson, you will need the following parts.

# Arduino Lesson 2. LEDs

## LEDs

LEDs make great indicator lights. They use very little electricity and they pretty much last forever.  
  
In this lession you will use perhaps the most common of all LEDs a 5mm red LED. 5Mm refers to the diameter of the LED and as well as 5mm, other common sizes are 3mm and the large fun 10mm LEDs.  
  
You cannot directly connect an LED to a battery or voltage source. Firstly, because the LED has a positive and a negative lead and will not light if they are the wrong way around and secondly, an LED must be used with a resistor to limit or 'choke' the amount of current flowing through the LED - otherwise the LED could burn out!

![](https://cdn-learn.adafruit.com/assets/assets/000/002/167/medium800/learn_arduino_led_labelled.jpg?1396780101)

If you do not use a resistor with an LED, then it may well be destroyed almost immediately, as too much current will flow through the LED, heating it and destroying the 'junction' where the light is produced.  
  
There are two ways to tell which is the positive lead of the LED and which the negative.&nbsp;

- Firstly, the positive lead is longer.  
- Secondly, where the negative lead enters the body of the LED, there is a flat edge to the case of the LED.

If you happen to have an LED that has a flat side next to the longer lead, you should assume that the longer lead is positive.  
# Arduino Lesson 2. LEDs

## Resistors

As the name suggests, resistors resist the flow of electricity and the higher the value of the resistor, the more it resists and the less electrical current will flow through it. We are going to use this to control how much electricity flows through the LED and therefore how brightly it shines.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/168/medium800/learn_arduino_R-270-level.jpg?1396780106)

But first, a bit more about resistors.&nbsp;  
  
The unit of resistance is called the Ohm, which is usually shortened to Ω the Greek letter Omega. Because an Ohm is a low value of resistance (it doesn't resist much at all), we also give the values of resistors in &nbsp;kΩ (1000 Ω) and MΩ (1000,000 Ω). These are called kilo-ohms and mega-ohms.  
  
In this lesson, we are going to use four different values of resistor, 270Ω, 470Ω, 2.2kΩ and 10kΩ. These resistors all look the same, except that they have different colored stripes on them. These stripes tell you the value of the resistor.  
  
The resistor color code works like this, for resistors like this with three colored stripes and then a gold stripe at one end.  
  
Each color has a number, as follows:

- Black 0
- Brown 1
- Red 2
- Orange 3
- Yellow 4
- Green 5
- Blue 6
- Purple 7
- Gray 8
- White 9

The first two striped are the first two digits of the value, so red, purple means 2, 7. The next stripe is the number of zeros that need to come after the first two digits, so if the third stripe is brown, as it is in the photograph above, then there will be one zero and so the resistor is 270Ω.  
  
A resistor with stripes brown, black, orange is 10 and three zeros so 10,000 Ω in other words 10 kΩ.  
  
Unlike LEDs, resistors do not have a positive and negative lead. They can be connected either way around.# Arduino Lesson 2. LEDs

## Breadboard Layout

Connect up your stripboard as shown below, using the 270Ω resistor.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/169/medium800/learn_arduino_fritzing.jpg?1396780115)

The Arduino is a convenient source of 5 Volts, that we will use to provide power to the LED and resistor. You do not need to do anything with your Arduino, except plug it into a USB cable.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/170/medium800/learn_arduino_overview.jpg?1396780130)

With the 270 Ω resistor in place, the LED should be quite bright. If you swap out the 270 Ω resistor for the 470 Ω resistor, then the LED will appear a little dimmer. With the 2.2kΩ resistor in place the LED should be quite faint. Finally, with the 10 kΩ resistor in place, the LED will be just about visible. Pull the red jumper lead out of the breadboard and touch it into the hole and remove it, so that it acts like a switch. You should just be able to notice the difference.&nbsp;  
  
Turning out the lights might help even more.

# Arduino Lesson 2. LEDs

## Moving the Resistor

At the moment, you have 5V going to one leg of the resistor, the other leg of the resistor going to the positive side of the LED and the other side of the LED going to GND. However, if we moved the resistor so that it came after the LED, as shown below, the LED will still light.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/171/medium800/learn_arduino_fritzing_2.jpg?1396780135)

Note, you will probably want to put the 270Ω resistor back in place.  
  
So, it does not matter which side of the LED we put the resistor, as long as it is there somewhere.

# Arduino Lesson 2. LEDs

## Blinking the LED

With a simple modification of the breadboard, we could attach the LED to an output &nbsp;pin of the Arduino. Move the red jumper wire from the Arduino 5V connector to D13, as shown below:

![](https://cdn-learn.adafruit.com/assets/assets/000/002/177/medium800/learn_arduino_fritzing_pin_13.jpg?1396780180)

Now load the 'Blink' example sketch from Lesson 1. You will notice that both the built-in 'L' LED and the external LED should now blink.

```auto
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}
```

Lets try using a different pin of the Arduino – say D7. Move the red jumper lead from pin D13 to pin D7 and modify the following line near the top of the sketch:

```auto
int led = 13;
```

so that it reads:

```auto
int led = 7;
```

Upload the modified sketch to your Arduino board and the LED should still be blinking, but this time using pin D7.  
  
In the next lesson, we will be using LEDs again, this time, the Arduino will be controlling the LED.

[Click Here for the Next Lesson](http://learn.adafruit.com/adafruit-arduino-lesson-3-rgb-leds)
 **About the Author**  
  
Simon Monk is author of a number of books relating to Open Source Hardware. The following books written by Simon are available from Adafruit:&nbsp;[Programming Arduino](https://www.adafruit.com/products/1019),&nbsp;[30 Arduino Projects for the Evil Genius](https://www.adafruit.com/products/868)&nbsp;and&nbsp;[Programming the&nbsp;Raspberry Pi](https://www.adafruit.com/index.php?main_page=adasearch&q=programming+raspberry+pi "Link: https://www.adafruit.com/index.php?main\_page=adasearch&q=programming+raspberry+pi"). 
## Featured Products

### Adafruit METRO 328 Fully Assembled - Arduino IDE compatible

[Adafruit METRO 328 Fully Assembled - Arduino IDE compatible](https://www.adafruit.com/product/50)
We sure love the ATmega328 here at Adafruit, and we use them&nbsp;_a lot_&nbsp;for our own projects. The processor has plenty of GPIO, Analog inputs, hardware UART SPI and I2C, timers and PWM galore - just enough for most simple projects. When we need to go small, we use a <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/50)
[Related Guides to the Product](https://learn.adafruit.com/products/50/guides)
### Diffused Red 5mm LED (25 pack)

[Diffused Red 5mm LED (25 pack)](https://www.adafruit.com/product/299)
Need some indicators? We are big fans of these diffused red LEDs, in fact we use them exclusively in our kits. They are fairly bright so they can be seen in daytime, and from any angle. They go easily into a breadboard and will add that extra zing to your project.

- Pack of 25...

In Stock
[Buy Now](https://www.adafruit.com/product/299)
[Related Guides to the Product](https://learn.adafruit.com/products/299/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

In Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)
### Premium Male/Male Jumper Wires - 40 x 6" (150mm)

[Premium Male/Male Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/758)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on either end and fit cleanly next to each other...

Out of Stock
[Buy Now](https://www.adafruit.com/product/758)
[Related Guides to the Product](https://learn.adafruit.com/products/758/guides)

## Related Guides

- [TTL Serial Camera](https://learn.adafruit.com/ttl-serial-camera.md)
- [Adafruit Analog Accelerometer Breakouts](https://learn.adafruit.com/adafruit-analog-accelerometer-breakouts.md)
- [2.8" TFT Touch Shield](https://learn.adafruit.com/2-8-tft-touch-shield.md)
- [Photocells](https://learn.adafruit.com/photocells.md)
- [RGB LED Matrix Basics](https://learn.adafruit.com/32x16-32x32-rgb-led-matrix.md)
- [Adafruit Optical Fingerprint Sensor](https://learn.adafruit.com/adafruit-optical-fingerprint-sensor.md)
- [Adafruit Ultimate GPS Logger Shield](https://learn.adafruit.com/adafruit-ultimate-gps-logger-shield.md)
- [WiFi Controlled Mobile Robot](https://learn.adafruit.com/wifi-controlled-mobile-robot.md)
- [Remote controlled door lock using a fingerprint sensor & Adafruit IO](https://learn.adafruit.com/remote-controlled-door-lock-using-a-fingerprint-sensor-and-adafruit-io.md)
- [Wireless Power Switch with Arduino & the CC3000 WiFi Chip](https://learn.adafruit.com/wireless-power-switch-with-arduino-and-the-cc3000-wifi-chip.md)
- [Collin's Lab: MIDI](https://learn.adafruit.com/collins-lab-midi.md)
- [Skill Badge Requirements: Microcontrollers](https://learn.adafruit.com/skill-badge-requirements-microcontrollers.md)
- [Arduino Lesson 7. Make an RGB LED Fader](https://learn.adafruit.com/adafruit-arduino-lesson-7-make-an-rgb-led-fader.md)
- [Arduino Lesson 16. Stepper Motors](https://learn.adafruit.com/adafruit-arduino-lesson-16-stepper-motors.md)
- [Arduino "Hunt The Wumpus"](https://learn.adafruit.com/arduino-hunt-the-wumpus.md)
