LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using The Output Ports
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using The Output Ports
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
Laboratory Exercise 1
Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports
Objectives:
Materials:
1 – Personal Computer
Access the Arduino website at www.arduino.cc and download the newest version of the IDE from
the Download page (see Figure 1-1).
After completing the download, unzip it. Inside, you’ll find the Arduino IDE. New versions of the
Windows IDE are available as an installer that you can download and run, instead of downloading
a ZIP file.
PREPARED AND EDITED BY: ENGR. LESTER DAVE PELIAS & ENGR. JOMEL AVENIDO 1
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports.docx
COMPUTER ENGINEERING DEPARTMENT
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
PREPARED AND EDITED BY: ENGR. LESTER DAVE PELIAS & ENGR. JOMEL AVENIDO 2
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports.docx
COMPUTER ENGINEERING DEPARTMENT
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
Now that you have the IDE downloaded and ready to run, you can connect the Arduino to your
computer via USB, as shown in Figure 1-3. Mac and Linux machines install the drivers (mostly)
automatically.
If you are using OS X, the first time you plug in an Uno or a Mega 2560, you will get a notification
that a new network device has been added. Click the Network Preferences button. In the new
window, click Apply. Even though the board will appear as “Not Configured” in the network
device list, it will be ready to use. Now, quit System Preferences.
If you are using a modern Arduino on a Windows computer, you will probably need to install
drivers. You can skip the following directions if you are not using a Windows computer that needs
to have drivers installed. If you installed the IDE using the Windows installer, then these steps have
been completed for you. If you downloaded the ZIP on your Windows machine, then you will need
to follow the directions shown next.
PREPARED AND EDITED BY: ENGR. LESTER DAVE PELIAS & ENGR. JOMEL AVENIDO 3
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports.docx
COMPUTER ENGINEERING DEPARTMENT
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
On your Windows computer, follow these steps to install the drivers (instructions adapted from the
Arduino.cc website):
4. Look under Ports (COM and LPT) for the Arduino that you connected.
7. Select the appropriate driver from the drivers’ directory of the Arduino IDE that you just
downloaded (not the FTDI drivers directory).
Now, launch the Arduino IDE. You’re ready to load your first program onto your Arduino. To ensure
that everything is working as expected, you’ll load the Blink example program, which will blink the
onboard LED. Most Arduinos have an LED connected to pin 13. Navigate to File -> Examples ->
Basic, and click the Blink program. This opens a new IDE window with the Blink program already
written for you.
PREPARED AND EDITED BY: ENGR. LESTER DAVE PELIAS & ENGR. JOMEL AVENIDO 4
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports.docx
COMPUTER ENGINEERING DEPARTMENT
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
Take a moment to deconstruct the Blink program so that you understand the basic structure of
programs written for the Arduino. Consider Figure 1-4. The numbered callouts shown in the figure
correspond to the following list.
PREPARED AND EDITED BY: ENGR. LESTER DAVE PELIAS & ENGR. JOMEL AVENIDO 5
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports.docx
COMPUTER ENGINEERING DEPARTMENT
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
Line 1. This is a multiline comment. Comments are important for documenting your code.
Everything you write between these symbols will not be compiled or even seen by your Arduino.
Multiline comments start with /* and end with */. Multiline comments are generally used when you
have to say a lot (like the description of this program).
Line 9, 13, 15, 19… . This is a single-line comment. When you put // on any line, the compiler ignores
all text after that symbol on the same line. This is great for annotating specific lines of code or for
“commenting out” a particular line of code that you believe might be causing problems.
Line 11. This code is a variable declaration. A variable is a place in the Arduino’s memory that
holds information. Variables have different types. In this case, it’s of type int, which means it will
hold an integer. In this case, an integer variable called led is being set to the value of 13, the pin
that the LED is connected to on the Arduino Uno. Throughout the rest of the program, we can
simply use led whenever we want to control pin 13. Setting variables is useful because you can
just change this one line if you hook up your LED to a different I/O pin later on; the rest of the code
will still work as expected.
Line 14. void setup() is one of two functions that must be included in every Arduino program. A
function is a piece of code that does a specific task. Code within the curly braces of the setup()
function is executed once at the start of the program. This is useful for one-time settings, such as
setting the direction of pins, initializing communication interfaces, and so on.
Line 16. The Arduino’s digital pins can function as input or outputs. To configure their direction, use
the command pinMode(). This command takes two arguments. An argument gives commands
information on how they should operate. Arguments are placed inside the parentheses following
a command. The first argument to pinMode determines which pin is having its direction set.
Because you defined the led variable earlier in the program, you are telling the command that
you want to set the direction of pin 13. The second argument sets the direction of the pin: INPUT
or OUTPUT. Pins are inputs by default, so you need to explicitly set them to outputs if you want them
to function as outputs. Because you want to light an LED, you have set the led pin to an output
(current is flowing out of the I/O pin). Note that you have to do this only one time. It will then
function as an output for the rest of the program, or until you change it to an input.
Line 20. The second required function in all Arduino programs is void loop(). The contents of the
loop function repeat forever as long as the Arduino is on. If you want your Arduino to do something
once at boot only, you still need to include the loop function, but you can leave it empty.
Line 21, 23. digitalWrite() is used to set the state of an output pin. It can set the pin to either 5V or
0V. When an LED and resistor is connected to a pin, setting it to 5V will enable you to light up the
LED. (You learn more about this in the next chapter.) The first argument to digitalWrite() is the pin
you want to control. The second argument is the value you want to set
it to, either HIGH (5V) or LOW (0V). The pin remains in this state until it is changed in the code.
Line 22, 24. The delay() function accepts one argument: a delay time in milliseconds. When calling
delay(), the Arduino stops doing anything for the amount of time specified. In this case, you are
delaying the program for 1000ms, or 1 second. This results in the LED staying on for 1 second before
you execute the next command.
Line 23. Here, digitalWrite() is used to turn the LED off, by setting the pin state to LOW.
PREPARED AND EDITED BY: ENGR. LESTER DAVE PELIAS & ENGR. JOMEL AVENIDO 6
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports.docx
COMPUTER ENGINEERING DEPARTMENT
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
Line 24. Again, we delay for 1 second to keep the LED in the off state before the loop repeats and
switches to the on state again.
3. Save this file with a filename “Test101”. Compile and Upload the Sketch. Observe the result.
You should see a blinking LED.
4. Place the LED from 2 -13 and then change the “1” in your code from “2-13” one at a time.
This is to verify that each port is working properly. Make sure that when you change your
code, you “verify” it and “upload” to the Arduino UNO R3 board.
5. Now, connect seven LEDs with a 330-ohmn resistor each to the ports 1-7 as shown below.
6. Change your code such that it is like what is shown below. What happens to your LEDs?
Are they blinking one after another every one second?
PREPARED AND EDITED BY: ENGR. LESTER DAVE PELIAS & ENGR. JOMEL AVENIDO 7
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports.docx
COMPUTER ENGINEERING DEPARTMENT
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
Activity 3:
1. Revise activity 2 #5 which perform running LED. (ex. From LED 1 to 7 and 7 to 1)
2. Make the LEDs blink alternately, i.e. all even port numbers will blink at the same time and
all odd port numbers will blink at the same time but alternately. Blinking interval is 500ms.
3. Binary counter from 0 – 63 the loop again.
Documentation:
1. In a separate short bond paper, provide a snapshot of each circuit per activity and their
codes.
2. Attach as well a short video clip for each activity that shows their working.
3. Upload and submit all requirements to LMS.
a. Documents should be in pdf format
Note: Make sure each file (videos, documents…) is less than 128MB
PREPARED AND EDITED BY: ENGR. LESTER DAVE PELIAS & ENGR. JOMEL AVENIDO 8
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports.docx
COMPUTER ENGINEERING DEPARTMENT
COLLEGE OF ENGINEERING
NOTRE DAME UNIVERSITY
COTABATO CITY, 9600
PHILIPPINES
References:
www.arduino.cc/en/Guide/Environment
www.atmel.com/images/doc8161.pdf
Jeremy Blum, Exploring Arduino Tools and Technique for Engineering Wizardy
Score Sheet
Date Performed
As you complete all exercises of the laboratory, ask for the Instructor’s Signature and have him/her
rate your work. If you ever get stuck, please ask your laboratory instructor or the in-charge for
assistance.
PREPARED AND EDITED BY: ENGR. LESTER DAVE PELIAS & ENGR. JOMEL AVENIDO 9
LabExer1 - Arduino UNO R3 Board, IDE Familiarization and Using the Output Ports.docx