Learning Objectives
- Emphasis: Equal
- Hardware: LED, Arduino
- Software: setup, loop, digitalRead/Write, delay
Materials
- Arduino Uno (of course!)
- Breadboard and wires
- Single-color LED
- 330 ohm resistor
Reference Files
Breadboard Layout
- Power supply: Connect a digital pin on the Arduino - let's say pin 10 - to the positive rail on your breadboard and the ground pin to the negative rail. This will provide power to your LED.
- Resistance: Connect the 330-ohm resistor from the positive rail on your breadboard to a row in the center.
- LED: Connect the long leg of the LED to the same row as the resistor and the short leg to the ground rail (you can use extra wires if your LED doesn't quite reach).
- You're done! Plug your Arduino into the USB port on your computer.
Reference Schematic
Software
- Getting started: Open the Arduino program (it should open automatically once your Arduino is plugged in) and create a new sketch. If you need reference, check out some of the example programs, especially Basics>>Blink.
- Initialize variables: You'll only need one variable for this program: the pin powering your LED. Declare an int ledPin = 10 to store this value.
- Setup: In your first required method, set your LED pin to be output using pinMode(ledPin, OUTPUT).
- Turning the LED on: To turn the LED steadily on, include the line digitalWrite(ledPin, HIGH) in your loop method.
- Blinking the LED: To blink the LED, we're going to use the delay method. Leave the same line that you had to turn the LED on, but after it, write delay(500). This will pause the program for 500 milliseconds. Then write digitalWrite(ledPin,LOW) to turn the light off again. Include another delay(500) so the light won't immediately turn back on again.
- Running the program: With your Arduino connected to the computer, press the right arrow button in the top of your sketch to upload it to the Arduino. The LED should start blinking on the breadboard. Congratulations! You've written your first Arduino program!
- Experiment: What else can you do with this program? Can you change the length of time it blinks? What about blinking out SOS - three short blinks and three long? What if you used multiple lights to blink at the same time? The sky's the limit!
Reference Code
Next: Homemade Jeopardy -->