Gunnewiek.com

Arduino Basics 1: LEDs

I am going to start with some very simple programs, but hopefully build and program them in such a way that they can easily be reused in larger programs without too much modification.

LEDs are used in many applications and can be very useful when debugging. Turning on an LED can be compared to writing "Hello World" or some other test statement to the terminal window. LEDs have a positive end (the longer one) and a negative end (shorter). When hooking up a circuit make sure that the LED has the correct orientation.

My LEDs are rated at 3.4V, and the Arduino supplies 5V at the DC output. Most LEDs require about 20mA of current to flow through them. If you allow more current to flow through then it will shine brighter but it will also burn out / stop working more quickly. If you allow less then the LED will not shine as brightly and if using a battery it will last longer. Using Ohm's Law we can calculate:

(V2-V1) / I = R

and substituting in we get:

(5-3.4)/0.02 = 80Ω

I will use a 100Ω resistor because that is the closest thing I have over 80, and as mentioned previously this will just cause the LED to shine a little dimmer. I have created the circuit diagram below for a single LED:

Basic Arduino circuit with one LED

To turn on multiple LEDs from the same source, they must be connected in parallel (each with its own resistor). This can be seen below:

Basic Arduino circuit with multiple LEDs

You can see below how I hooked up my circuit (sorry for the poor picture quality). There are multiple ways to do it, so it doesn't have to look exactly like this.

Multiple LEDs on a breadboard with an Arduino

Now that the circuit is all hooked up it is time to program it. With only LEDs there isn't much to do, so we will just turn it on / off with a delay. The code and circuit diagrams can be downloaded below. I tried to make the functions as modular as possible even though they are not really needed in this basic example.

Download

And here is a video of it in action:

Comments (0)

Leave a comment

(required)