Controlling an External LED

In this project, you'll learn how to connect and control an external LED.

Before you do this project, you'll first need to know how to use a breadboard, and how a LED works

Parts needed: Software stuff you'll learn: Arduino      LED      Breadboard      150 ohm resistor 150 ohm resistor
Questions:
How do you turn on a LED?  Connect it to a power source. (If you don't know how to do it then read this first.)

How do you turn off a LED?  Disconnect it from the power source.

How do you make a LED blink once?   Connect and then disconnect the LED from the power source.

How do you make a LED blink continuously?   Keep connecting and disconnecting the LED from the power source.



     This is very tiring and boring!
boring



To automatically turn on and off a LED, we need to get the Arduino to control it by connecting one leg of the LED to a digital I/O pin on the Arduino board.

The pins labeled 2 to 13 on the Arduino board are the digital I/O pins.
Arduino digital I/O pins

 
1 Making the connections
  • Connect the positive end (long leg) of the LED to pin 3 on the Arduino board.
  • Connect the negative end (short leg) of the LED to one end of the 150 Ω resistor.
  • Connect the other end of the resistor to GND on the Arduino.
External LED connections
2 Create a new program by selecting File from the menu, and then select New.

You will see this new template.
BareMinimum template
3 Type in this program.









The pinMode command tells the Arduino that you will be controlling pin 3 for OUTPUT since you connected the LED to pin 3.




The digitalWrite command sends a HIGH or LOW signal to pin 3.

The delay command makes the Arduino wait a bit. The number specified in the delay command is the number of milliseconds to wait.

1000 ms = 1 sec
External LED program
4 Upload and run the program. You should see the external LED blink on for 1 second and then off for another second.


How (not) to blow up a LED. If you have not read the document on how a LED works then you should read it before going any further, otherwise you'll end up with a lot of blown up LEDs.
Stop