You are on page 1of 4

EE 260 Lab 1

Introduction to the Arduino


Arduino is an open-source single-board microcontroller, designed to make the process of using
electronics in multidisciplinary projects more accessible. The hardware consists of a simple open
hardware board with an Atmel AVR processor. It has on-board analog and digital input/output
support. The software consists of a standard programming language compiler and the boot loader
that runs on the board. Knowledge of the Arduino gives a tangible application of Embedded
systems.
Lab Objective
The objective of this lab is to explore the basic capabilities of the Arduino and its
programming structure.

Lab Background
1. Basic Computer Skills. Student should be comfortable starting applications, opening,
closing and saving files, cutting and pasting text, and locating files/folders.
2. Basic Programming Skills. Student should be familiar with creating simple programs
in C/C++ as well as working in a programming development environment.
3. Overview of the Arduino. Student should have a basic knowledge of the components
and capabilities of the Arduino board (Uno—R3).

Laboratory Pre-Exercise
1. Review the tutorial video:

http://www.youtube.com/watch?v=s3TxkUo1jNg
2. Review the basic programming structure for ANSI C and Arduino programs
3. Familiarize yourself with the EduShield Schematic
The Programming Structure of the ANSI C
In any kind of C programming, a program is comprised primarily of
subroutines. The ANSI C program structure is shown below.

EE 260 Lab 1 Introduction to the Arduino page 1 of 4


Every ANSI C program follows this structure, even the most simple. In the
simple cases, some of the parts might be missing. Indeed, the simplest program
in ANSI C is shown. In this case, there are no declarations, no subroutines etc.
Main() {}

The Programming Structure of the Arduino C


For the Arduino, we have a structure similar to that shown above, but we always
have at least two subroutines. The minimal Arduino program is shown below.

We set that both the setup and loop routines are required. Both of these
are functions that return nothing.
The Basic Blink Program
A most basic Arduino program is given as an example. It is the Blink
program shown.

We note that comments can used either by using // that comments the rest of
that line, or using /* ... */ for a multi-line comment.
EE 260 Lab 1 Introduction to the Arduino page 2 of 4
This program introduces three new commands that are specific to the Arduino.
pinMode(pin,mode). This configures a pin to be either an input or
ouput. The value of pin can be 0-13, and mode can be either INPUT or
OUTPUT.

digitalWrite(pin,value). Outputs a High or Low to the specified


pin.. The value of pin can be 0-13, and value can be either HIGH or LOW.

delay(value). This causes the program to be suspended for the duration


In addition, other commands will be useful for the lab.
analogRead(pin). This reads the analog voltage on pin. The value of pin can be
0-5, and the value returned will be a 10 bit number (from 0 to 1023).

analogWrite(pin,value). Outputs a PWM signal to the specified pin. The


value of pin can be 3,5,5,9,10, or 11, and value can be an integer from 0-255.

map(value,low-in,high-in,low-out,high-out). For an integer with value, value,


in the range from low-in to high-in, the value returned is in the range from
low-out to high-out. This is used to map signals from some input range, which
is not the same as the output range to be converted.

constrain(value,low,high). For an integer with value, value, the function


returns a value in the range from low to high.

Students are encouraged to read the online documentation about these commands
for further information.

Laboratory Project
The objective of this lab is to get a simple exposure to the Arduino by exploring its
basic capabilities and its programming structure. This will be done by creating a
Night-Light function using the Arduino and the EduShield.

1. Move the (red) jumper on the EduShield so that the RGB LED is used.

2. Create code that creates a Night-Indicator function. The Night-Indicator


function is such that as the light hitting the photocell on the EduShield is
diminished, the color of the RGB LED shifts from red to green. Full light gives a

EE 260 Lab 1 Introduction to the Arduino page 3 of 4


3. Move the jumper on the EduShield so that the other LEDs are used.

4. Create code that causes each of the LEDs in sequence to light for 1/3 of a second and
pause for 1/2 second, then repeat once all four have lit.

Laboratory Report
Your report should explain what you have done, and how you have gone about doing it for
each part. Indicate anything special that you did.
Your report should include the following:
For each program document the intended purpose of the program and its approach at the
beginning of the program.
For each program, provide a comment for each line of code.
Explain in detail anything that might not be obvious to the reader so that they can
understand what you are doing.

The EduShield Connection Diagram

EE 260 Lab 1 Introduction to the Arduino page 4 of 4

You might also like