Interested in Arduino? Control your first LED!
Here’s an easy tutorial for programming an Arduino to blink an LED:
First take your Arduino microcontroller (I used an Uno), and connect it to your laptop via USB. Ensure that you have the “Arduino IDE” installed on your laptop or pc. This is the easiest way to get sketches, or programs to run on your Arduino. Hopefully your Arduino’s drivers will be installed when you plug it in via the USB cable, if not search the web and try to find a solution. Several solutions are available on and can easily be found with a Google search such as “site:arduino.cc driver installation“.
Next open the Arduino IDE, and click file -> examples -> basics -> blink.
This will load up a new IDE window that contains some descriptive text and a block of code:
Blink
Turns on an LED on for one second, then off for one second, repeatedly.Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you’re unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation at http://arduino.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
|
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
|
If yours looks the same or similar, go to tools -> board in your new IDE window and ensure that the correct board is selected. Afterwards, go to tools -> port and pick the highest port available. This will ensure that all of the conditions are met to match that of the example sketch.
Finally, click the little arrow that says “upload” on the top left of your IDE. This will copy the program into your Arduino’s memory. Once the program is uploaded it will automatically run causing the “L” labeled LED on the Arduino board to blink on and off occasionally.
Next up, I will be covering how to edit this code in order to blink Morse code messages.
Trackbacks & Pingbacks
[…] my first Arduino “blinking lights” tutorial, I explained how to get a sketch up and running and point some instructions at the Uno’s #13 […]
[…] Previously, I covered how to get your first sketch on an Arduino running – and how to blink off and on the board’s “L” labeled LED light. […]
Leave a Reply
Want to join the discussion?Feel free to contribute!