Sei sulla pagina 1di 5

Food

Living

Outside

Play

Technology

Workshop

Lighting LED's with Arduino


by cash7d on May 21, 2014

Table of Contents
Lighting LED's with Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Intro: Lighting LED's with Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 1: Turning on the LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 2: Adjusting LED Brightness With a Potentiometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 3: Using A Potentiometer to Trigger an LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Step 4: Switch Between a Red and Green LED Using a Potentiometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

http://www.instructables.com/id/Lighting-LEDs-with-Arduino/

Intro: Lighting LED's with Arduino


This is the ultimate LED tutorial. This will give you the basic building blocks needed to do just about anything with LED's. Pictured are all the things you need for this
whole tutorial, which consists of a couple different mini-projects. The pieces are:
a) Breadboard - If you're going to do more than one project ever in your life (you are.) then get the bigger one. It will make things much easier later.
b) Jumper Wires - again, you won't need all of these for this one project but it's nice to have short wires that aren't as flexible to make nice neat breadboard setups. Down
the road, an organized breadboard can be the difference between an easily fixed problem and a computer being thrown out the window through pure frustration. That
being said, you should also get.....
c) Flexible jumper wires - good to have, and so cheap.
d) Potentiometer - known as a "Pot" for short. voltage divider usually used for calibration or adjusting an analog input
e) LED's - one red, one green
f) Resistors - 1000 ohm, colored brown-black-red-gold
g) Arduino Uno - you can really use any Arduino but I have an Uno so all of these tutorials are built on the Uno.
Check my blog for a link where you can buy all the parts for this project at once. It's here. <---coming soon.

Step 1: Turning on the LED


First, we're going to turn on the LED. Grab your Uno, and set it up the way it is in the picture. You'll need to run a jumper from pin 10 (yellow wire) to the breadboard. Use
a 1K (1000 ohm) resistor to go to the anode, or positive end of the LED. LED's will only work if the anode and cathode are at high voltage and low voltage respectively.
Run the other wire (pictured as green wire) to ground. Then upload the code.
About the Code:
The digitalWrite function sets the pin at either a LOW (low voltage) or HIGH (high voltage) state. This code will cause the LED to flash.

Image Notes
1. Yellow wire goes from pin 10 to the resistor. Resistor goes to anode (longer end) of LED. Green wire goes from cathode to ground.

http://www.instructables.com/id/Lighting-LEDs-with-Arduino/

File Downloads

LightUpLED.ino (295 bytes)


[NOTE: When saving, if you see .tmp as the file ext, rename it to 'LightUpLED.ino']

Step 2: Adjusting LED Brightness With a Potentiometer


For this, there actually is no code. First, hook the three pot pins into different rows of your breadboard. Attach the 5V line to the middle of the pot, then using a 1k resistor,
tie the anode (long end) of the led to the side pin of the pot (doesn't matter which side). Then just take the cathode of the LED to ground. Now, when you turn the pot, you
should see a varying brightness in the LED. This is due to the fact that the potentiometer is a voltage divider. Turning the knob one direction will increase the electrical
resistance and turning the knob the other way will decrease it.
For extra credit: attach another LED to the un-used pin of the pot via a 1K resistor, then the other end of that LED to ground. As you turn the knob, one LED will get
brighter while the other gets more dim.

Step 3: Using A Potentiometer to Trigger an LED


This example goes more in depth with inputs and outputs. You're going to send the potentiometer value to the Arduino by assigning analog pin A0 as an input. An analog
input will send the Arduino an integer between 0 and 1024. In the code, an "if statement" is used to tell the Arduino that if the pot value gets above a certain value, then
set the LED pin to a HIGH state (turn it on). Otherwise, it will turn off.
In this example, the LED is set up the same way as before. Use a jumper to go from pin 10 to a resistor, then the anode of the LED, then cathode to ground. The pot is
also set up similarly. Take a side pin to 5 volts (in the picture, I have the red rail set as a 5 volt rail, and blue as ground), and the other side pin to ground. A jumper will go
from the middle pin to analog pin A0.

http://www.instructables.com/id/Lighting-LEDs-with-Arduino/

Image Notes
1. It's a little hard to see, but the cathode of the LED is tied to ground via the blue rail. Notice the red jumpers on the right side of the bread board that connect the 5V
and ground rails.

File Downloads

triggerled.ino (501 bytes)


[NOTE: When saving, if you see .tmp as the file ext, rename it to 'triggerled.ino']

Step 4: Switch Between a Red and Green LED Using a Potentiometer


This is simply an extension of the previous step. Just attach another LED in the same fashion as the first, but go from pin 9. Then, in the code, notice some extra if
statements that now essentially tell the Arduino that above 1000 turn on one, and below 200 turn on the other.
These examples are simple, but are basic building blocks to understanding how the Arduino interacts with the environment. I plan on uploading more tutorials that will be
demos for all the sensors that I can possibly get to work. For more information about me and my projects, as well as where to buy the books and associated parts, check
my blog at www.thepartslist.com
Thanks! See you next time!
RGB leds to come.

File Downloads

RedGreenSwitch.ino (515 bytes)


[NOTE: When saving, if you see .tmp as the file ext, rename it to 'RedGreenSwitch.ino']

http://www.instructables.com/id/Lighting-LEDs-with-Arduino/

Related Instructables

How to Make an
LED Ambient
Mood Light: A
Beginner
Tutorial by
elevenbytes

Basics of the
Arduino
(Duemilanove)
by vishalapr

Tutorial One:
Arduino Switch
Light (No
Arduino
Programming
needed)
[Beginner] by
WildWalkerCT

Arduino based
simple
programming
tutorials: 1 with
LED's by
abelaaa

Advertisements

Comments

http://www.instructables.com/id/Lighting-LEDs-with-Arduino/

Arduino Insight
-Beginner
LED'S and
(Binary counter
16 bit) by
abrezengineer

Visual
Computer
Stress MeterArduino by
alecnotalex

Potrebbero piacerti anche