Arduino Lesson 3
Arduino Lesson 3
LEDs
Created by : Mr. Leng Por
Email: [email protected]
Institute of Electrical Science
8/15/2017 1
Last updated on 2016-10-18
Guide Contents
Guide Contents
Overview
Parts
LEDs
Resistors
Breadboard Layout
Moving the Resistor
Blinking the LED
8/15/2017 2
Overview
8/15/2017 3
Parts
To carry out the experiment described in this lesson, you will need the
following parts.
1) 5MM RED LED 1
8/15/2017 4
Parts
8/15/2017 5
Parts
8/15/2017 6
Parts
8/15/2017 7
Parts
8/15/2017 8
Parts
6) full-size Breadboard 1
8/15/2017 9
Parts
7) Arduino Uno R3 1
8/15/2017 10
Parts
8/15/2017 11
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!
8/15/2017 12
LEDs
8/15/2017 13
LEDs
8/15/2017 14
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.
8/15/2017 15
Resistors
8/15/2017 16
Resistors
The resistor color code works like this, for resistors like
this with three colored stripes and then a gold stripe at
8/15/2017 17
one end.
Resistors
8/15/2017 18
Resistors
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.
8/15/2017 19
Breadboard Layout
Connect up your stripboard as shown below, using the 270Ω resistor.
8/15/2017 20
Breadboard Layout
8/15/2017 21
Breadboard Layout
8/15/2017 22
Breadboard Layout
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.
8/15/2017 23
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.
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.
8/15/2017 24
Moving the Resistor
8/15/2017 25
Blinking the LED
8/15/2017 26
Blinking the LED
8/15/2017 27
Blinking the LED
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.
/*
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;
8/15/2017 28
Blinking the LED
// 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
} 8/15/2017 29
Blinking the LED
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:
int led = 13;
so that it reads:
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.
8/15/2017 30
The End
8/15/2017 31