0% found this document useful (0 votes)
82 views5 pages

Lab 1: Blink Blink

This document provides instructions for a basic Arduino lesson to make an LED blink on and off. It introduces the Arduino software and environment, explains how to upload a blink sketch to the board, and discusses the key components of an Arduino sketch like comments, variables, procedures and function calls. It then prompts the user to modify the delay times and observe the effects on the blinking light pattern.

Uploaded by

Boo Boyolq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views5 pages

Lab 1: Blink Blink

This document provides instructions for a basic Arduino lesson to make an LED blink on and off. It introduces the Arduino software and environment, explains how to upload a blink sketch to the board, and discusses the key components of an Arduino sketch like comments, variables, procedures and function calls. It then prompts the user to modify the delay times and observe the effects on the blinking light pattern.

Uploaded by

Boo Boyolq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab1- Blink Blink

Lab 1: Blink Blink


Introduction
!
It is finally time to make your Arduino do something! We're going to start with the classic
hello world! of electronics, a blinking light.This lesson will basically get you up and running using
the Arduino software and uploading a sketch to the Arduino board. Once you've completed this
step we can continue to the really exciting stuff, which is when we start writing our own sketches!
These instructions mostly show Windows software. Except when indicated, the software (should
be) identical on all platforms.

background
!
Start up the Arduino software and open the Blink example sketch, in menu
File>Examples>01.Basics>Blink. The sketch itself is in the text input area of the Arduino
software. Sketches are written in text, just like a document. When you select Compile/Verify from
the menu, the Arduino software looks over the document and translates it to Arduino-machinelanguage - which is not human-readable but is easy for the Arduino to understand. Sketches
themselves are written in C, which is a programming language that is very popular and powerful. It
takes a bit of getting used to but we will go through these examples slowly.
COMMENTS

Lets examine this sketch in detail starting with the first section:
/*
* Blink
*
* The basic Arduino example. Turns on an LED on for one second,
* then off for one second, and so on... We use pin 13 because,
* depending on your Arduino board, it has either a built-in LED
* or a built-in resistor so that you need only an LED.
*
* http://www.arduino.cc/en/Tutorial/Blink
*/
!
This is a comment, it is text that is not used by the Arduino, its only there to help humans
like us understand whats going on. You can tell if something is a comment because there is a /* at
the beginning and a */ at the end. Anything between the /* and */ is ignored by the Arduino. In this
example the person who wrote the comment decided to make it look pretty and add *'s down the
side but this isn't necessary. Comments are very useful and I strongly encourage every sketch you
make have a comment in the beginning with information like who wrote it, when you wrote it and
what its supposed to do.
VARIABLES

Lets look at the next line:


int ledPin = 13;

// LED connected to digital pin 13

!
This is the first line of actual instruction code. It is also extremely unlike English (or any
other human language). The first part we can easily understand is the part to the right, which is
also a comment. Turns out if you want to make a small comment, you can use // as well as /* */. //
is often used for short, one line comments. The rest of the line, the stuff before the //, is what is
called a statement, which is basically like a computerized sentence. Much like human sentences
end with a . (period), all computer sentences end with a ; (semicolon)
Microprocessor and Embedded Computer Systems!

Page 1 of 5

Lab1- Blink Blink

PROCEDURES

Lets move on to the next section


void setup()
// run once, when the sketch starts
{
pinMode(ledPin, OUTPUT);
// sets the digital pin as output
}
OK we've got two comments, each starting with //. We understand comments already so lets skip
that. We also see in the middle there is a statement, we know its a statement because it ends with
a ; (semicolon) however there's a whole bunch more stuff before and after it. This bunch of code is
an example of a procedure, a procedure is a collection of statements, its used to group statements
together so that we can refer to them all with one name. Its just like a procedure that we use to
perform a task step by step.
return value

procdure name

{input value}

{statement}

void

setup

()

{ pinMode(ledPin, OUTPUT); }

Looking at the procedure, we see that it is named setup and it has no input values and it returns
void. Now you're probably asking yourself "what is void?" Well thats a computer-scientist way of
saying nothing. That is, this procedure doesn't return anything. (That doesn't mean it doesn't do
anything, just that it doesn't have a tangible number or whatever, to show when its complete)
void setup()
// run once, when the sketch starts
There is one statement in this procedure,
pinMode(ledPin, OUTPUT);
// sets the digital pin as output
We'll return to this statement in detail later, suffice to say it is a way of telling the Arduino what we
would like to do with one of the physical pins on the main processor chip.
Procedure calls
We're onto the next bunch of text.
void loop()
// run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000);
// waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000);
// waits for a second
}
Using our now well-honed technique we recognize that the text to the right is all comments. We
also recognize another procedure, this one called loop which also has no inputs or output. This
procedure has multiple statements, one after the other.
We're going to skip the first statement for now and go straight to statement #2.
The second and fourth statements are the same, and have something to do with a delay. This
statement says "Dear Arduino. Stop what you're doing for a short amount of time. Thanks!"
To do this, the statement performs a procedure call. (We will use the phrasing calls a procedure).
Basically, we want the Arduino to take a break but don't quite know how to do it, lucky for us,
someone else wrote a procedure called delay which we can call upon to do the work for us.
SPECIAL PROCEDURES - SETUP() AND LOOP()

I do want to mention quickly here that the two procedures we've mentioned so far are extra-special
in that when the Arduino first wakes up after being reset, it always does whats in the setup
procedure first. Then it does whatever is in the loop procedure over and over and over...forever! Or
at least until you turn it off.
Microprocessor and Embedded Computer Systems!

Page 2 of 5

Lab1- Blink Blink

Materials List
1 Assembled Arduino board

2 USB Cable. Standard A-B cable is


required

Procedures
Now It's time to make some changes. In your Arduino software, change the number in the delay
procedure calls to 500 (from 1000) as shown
void loop()
// run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(500);
// waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(500);
// waits for a second
}
If you try to save the sketch, you'll get the warning that it's read-only.

Not a big deal, you can save it under a new name, such as MyBlink
Microprocessor and Embedded Computer Systems!

Page 3 of 5

Lab1- Blink Blink

Compile/Verify the sketch and Upload it.

Once the Arduino has been updated with the new sketch you should see a faster-blinking light than
before. If the LED is not blinking faster, check:
Did you make the changes to the delay procedure call to make it 500?
Did the compile/verify complete successfully? (should look like the screenshot above)
Did the upload complete successfully? (should look like the screenshot above)

Microprocessor and Embedded Computer Systems!

Page 4 of 5

Lab1- Blink Blink

Exercises
Now it time for you to make modifications to the sketch and experiment with different delay values
Exercise 1.
Modify the code so that the light is on for 100 msec and off for 900 msec
Exercise 2.
Modify the code so that the light is on for 50 msec and off for 50 msec. What happens?
Exercise 3.
Modify the code so that the light is on for 10 ms and off for 10 ms. What happens?
Now pick up the Arduino and gently wave it back and forth, in a dark room. What happens?
What do you think is happening here?

Microprocessor and Embedded Computer Systems!

Page 5 of 5

You might also like