Learn Arduino! Lesson-1.

Overview

In this lesson, you will learn how to program your Arduino to make the Arduino’s built-in LED blink.

Parts

learn_arduino_uno_r3_web

 

Arduino Uno R3

The ‘L’ LED

The Arduino has rows of connectors along both sides that are used to connect to electronic devices and plug-in ‘shields’ that allow the Arduino to do more. However, the Arduino also has a single LED that you can control from your sketches. This LED is built onto the Arduino board and is often referred to as the ‘L’ LED as this is how it is labelled on the board.

The position of this LED is circled in red on the pictures of the Arduino Uno and Leonardo below.

learn_arduino_uno_r3_L_circled

Loading the ‘Blink’ Example

You may find that your Arduino board’s ‘L’ LED already blinks when you connect it to a USB plug. This is because Arduino boards are generally shipped with the ‘Blink’ sketch pre-installed. In this lesson, we will reprogram the Arduino with our own Blink sketch and then change the rate at which it blinks. In Lesson 0, you setup your Arduino IDE and made sure that you could find the right serial port for it to connect to your Arduino board. The time has now come to put that connection to the test and program your Arduino 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

sketch-2

When the sketch window opens, enlarge it so that you can see the whole of the sketch in the window.

sketch-3

Saving a Copy of ‘Blink’

The example sketches included with the Arduino IDE are ‘read-only’. That is, you can upload them to an Arduino board, but if you change them, you cannot save them as the same file. We are going to change this sketch, so, the first thing you need to do is save your own copy that you can change however you like.
From the File menu on the Arduino IDE select the option ‘Save As..’ and then save the sketch with the name ‘MyBlink’.

sketch-4You have saved your copy of ‘Blink’ in your sketchbook. This means that if you ever want to find it again, you can just open it using the File → Sketchbook menu option.

sketch-5

Uploading Blink to the Board

Attach your Arduino board to your computer with the USB cable and check that the ‘Board Type’ and ‘Serial Port’ are set correctly. You may need to refer back to Lesson 0.

The Arduino IDE will show you the current settings for board at the bottom of the window.

sketch-6

Click on the ‘Upload’ button. The second button from the left on the toolbar.

sketch-7If you watch the status area of the IDE, you will see a progress bar and a series of messages. At first it will say ‘Compiling Sketch..’. This converts the sketch into a format suitable for uploading to the board.

sketch-8

Next, the status will change to ‘Uploading’. At this point, the LEDs on the Arduino should start to flicker as the sketch is transferred.

sketch-9

Finally, the status will change to ‘Done’.

sketch-10

The other message tells us that the sketch is using 1,084 bytes of the 32,256 bytes available. After the ‘Compiling Sketch..’ stage you could get the following error message:

sketch-11

The clue is at the top here, it probably means that your board is not connected at all, or the drivers have not been installed (if necessary) or that the wrong serial port is selected.
If you get this, go back to Lesson 0 and check your installation.
Once the upload has completed, the board should restart and start blinking.

 

Leave a Reply

Your email address will not be published. Required fields are marked *