ZachLabs Arduino

Lab 1: LEDs

Diodes are a type of semiconductor that only allow current to flow in one direction. They are useful, but not to us, and are not included in your kit.

Light-emitting diodes (or “LEDs”), on the other hand, light up when current flows through them, which is much more fun. Unlike old-fashioned incandescent lightbulbs they do not limit the amount of current that passes through them, and so they must always be used in conjunction with a resistor so that they do not “burn out.” The LEDs in your kit have two “legs” of different length; the shorter leg should always be wired closer to ground (0 V or GND).

Resistors “resist” the flow of current and are used to limit the amount of current in a circuit. The amount of resistance of each resistor is measured in ohms (Ω) and is indicated by the difficult to read colored stripes on the resistor. Your kit contains two types of resistors (330 Ω and 10 kΩ) and a helpful card for telling them apart.

Example Program

Assemble the following circuit and upload the program to your Arduino:

void setup()
{
    pinMode(2, OUTPUT);
}

void loop()
{
    // Blink the LED on pin 2 once per second:
    digitalWrite(2, HIGH);
    delay(500);
    digitalWrite(2, LOW);
    delay(500);
}

If your program has uploaded without any errors you should see the LED blinking on and off once per second. If your LED is not blinking you may have it connected backward; verify that the longer leg is connected to pin 2 and the shorter leg is connected to ground (“GND”).

Learn More

Assignment

Using the circuit and program above as a starting point, configure your Arduino to blink out your name in Morse code on an LED. An introduction to Morse code is provided below.

Your name probably has quite a few letters, and those letters probably have quite a few dots and dashes, and those dots and dashes probably require quite a few digitalWrite() and delay() calls. Check out the deep dives on the next pages for some hot C tips that can help make your programs less tedious to write (and better prepare you for the AP exam). At a minimum, consider creating a function for dots and a function for dashes, and use them to construct your Morse code message.

International Morse Code

  1. The length of a dot (•) is 1 unit.
  2. The length of a dash (−) is 3 units.
  3. The space between dots and dashes within a letter is 1 unit.
  4. The space between letters is 3 units.
  5. The space between words is 7 units.
Letter Morse Code Letter Morse Code Letter Morse Code
A •− N −• 0 −−−−−
B −••• O −−− 1 •−−−−
C −•−• P •−−• 2 ••−−−
D −•• Q −−•− 3 •••−−
E R •−• 4 ••••−
F ••−• S ••• 5 •••••
G −−• T 6 −••••
H •••• U ••− 7 −−•••
I •• V •••− 8 −−−••
J •−−− W •−− 9 −−−−•
K −•− X −••−
L •−•• Y −•−−
M −− Z −−••