You are on page 1of 6

By Aryeh Laufer

Lesson 1: Get LED’s (Light Emitting Diode) to blink

Part 1: Get an LED to turn on.

To get an LED to turn on, Grab an LED. Take the long leg, and plug it into
D12, and the short leg into GND, like in the diagram below.
D12 is where we will send our electricity out of (Our positive, +, or cathode), and
GND(negative, -, or Anode) is where the electricity will flow to complete our circuit.
GND has an assumed voltage of 0.

Why?

“So, where do you find a higher voltage and a lower voltage? Here's something really
useful to know: every source of electricity has two sides. You can see this on
batteries, which have metal caps on both ends, or your wall outlet that has two (or
more) holes. In batteries and other DC (Direct Current) voltage sources, these sides
(often called terminals) are named positive (or "+"), and negative (or "-").

Why does every source of electricity have two sides? This goes back to the idea of
“potential”, and that you need a voltage difference in order to get electricity to flow. It
sounds silly, but you can’t have a difference without two things to be different. In any
power supply, the positive side will have a higher voltage than the negative side, which
is exactly what we want. In fact, when we measure voltage, we usually say that the
negative side is 0 volts, and the positive side is however many volts the supply can
provide.

Once your LED is placed like the diagram above, you’re ready for coding the LED to
blink!

Open your Arduino application, and open a new file window if need be, so your screen
looks like this:

Its ok if yours doesn’t have numbers.

Notice the weird curly brackets on lines 1, 4, 6, and 9? All code needs to be placed in
between those curly brackets. Think of the curly brackets as the paragraph markers of
your code. It's how you tell your computer what lines of code are a part of which section.
Make sure not to delete those, or delete the void setup or void loop. You need both to
run your code!

All the code you want to run only once you place inside the curly brackets of void setup.
All the code you want to run in a loop, over and over again, place inside the curly
brackets in void loop.

Next, we will write our code.


The first line says to send electricity out of pin 12 of the Arduino board. We use the
digitalWrite command to send electricity out of the board; Notice the digitalWrite turned
orange. This means that the Arduino system recognizes this command as a function!
That means that someone already wrote some code behind the scenes, so that when
you say “digitalWrite”, the Arduino will know to send out electricity. Make sure to
capitalize the W, and use parentheses. And don’t forget the semicolon; Those are like
periods in coding language. Without a semi colon, your computer won’t know where a
line of code ends and another line begins!

Now you’re finally ready to run your code. To make sure your Arduino board is
connected to your computer, click on the top bar Tools -> Port -> and then click on the
port which says (Arduino Uno) after the COM.

Finally, click upload (The forward arrow button at the top):


This should send the code to your Arduino, turning on your first LED!

Note: if you get an error - try clicking tools -> port and make sure the port that has
(Arduino Uno) at the end of it is selected.

Part 2: Blinking an LED


The next step is to blink the LED. We will need to learn another function now, called delay.
Delay stops the Arduino from sending out an electrical signal for a defined amount of time,
counted in milliseconds. For example, delay(1000); means that the Arduino should stop sending
out an electrical signal for 1 second. We will use these to give our human eyes the chance to
see our LED Blink. Here is the code for blinking:
Note, we tell PIN 12 on the Arduino to turn on when we write HIGH, and now also tell it to turn
off when we say LOW. With the delays, our human eye can actually see the blink - otherwise,
the blink would happen so fast that it would look like the LED was just on.

Now, try to play around with the delays. How low can you go with the delays until you can’t see
the blink?

Congratulations, you’ve finished Lesson 1, Blink!

You might also like