Blink
In this lesson, you will learn how to program your UNO R3 controller board to blink the Arduino’s built-in LED, and how to download programs by basic steps.
Last updated
In this lesson, you will learn how to program your UNO R3 controller board to blink the Arduino’s built-in LED, and how to download programs by basic steps.
Last updated
1 x UNO R3
The UNO R3 board has rows of connectors along both sides that are used to connect to several electronic devices and plug-in 'shields' that extends its capability.
It also has a single LED that you can control from your sketches. This LED is built onto the UNO R3 board and is often referred to as the 'L' LED as this is how it is labelled on the board.
You may find that your UNO R3 board's 'L' LED already blinks when you connect it to a USB plug. This is because the boards are generally shipped with the 'Blink' sketch pre-installed.
In this lesson, we will reprogram the UNO R3 board with our own Blink sketch and then change the rate at which it blinks.
In Lesson 1, you set up your Arduino IDE and made sure that you could find the right serial port for it to connect to your UNO R3 board. The time has now come to put that connection to the test and program your UNO R3 board.
The Arduino IDE includes a large collection of example sketches that you can load up and use. This includes an example sketch for making the 'L' LED blink.
Load the 'Blink' sketch that you will find in the IDE's menu system under File > Examples > 01.Basics
To Upload the code you need to select the board model Arduino Uno
The upload code function also needs to select the board port number. Our computer displays the port number of arduino as: "COM9 Arduino / Genuino Uno", yours may be another serial port number.
Note: A correct COM port should be COMX (arduino) XXX), which is certified by the standard.
Note that a huge part of this sketch is composed of comments. These are not actual program instructions; rather, they just explain how the program works. They are there for your benefit. Everything between /* and */ at the top of the sketch is a block comment; it explains what the sketch is for.
Single line comments start with // and everything up until the end of that line is considered a comment.
The first line of code is:
As the comment above it explains, this is giving a name to the pin that the LED is attached to. This is 13 on most Arduinos, including the UNO and Leonardo.
Next, we have the 'setup' function. Again, as the comment says, this is executed when the reset button is pressed. It is also executed whenever the board resets for any reason, such as power first being applied to it, or after a sketch has been uploaded.
Every Arduino sketch must have a 'setup' function, and the place where you might want to add instructions of your own is between the { and the }.
In this case, there is just one command there, which, as the comment states tells the Arduino board that we are going to use the LED pin as an output.
It is also mandatory for a sketch to have a 'loop' function. Unlike the 'setup' function that only runs once, after a reset, the 'loop' function will, after it has finished running its commands, immediately start again.
This delay period is in milliseconds, so if you want the LED to blink twice as fast, change the value from 1000 to 200. This would then pause for half a second each delay rather than a whole second.
Upload the sketch again and you should see the LED start to blink more quickly.
After downloading the program, you can see that the little light connected to 13 ports is flashing faster.
And we're done.
Click the validate button to check the program syntax for errors.
Click the upload button and download the program to UNO R3.
The upload is complete and the LED is already flashing faster.