Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Freshman Seminar Arduino Lab

This lab will teach you a little about basic electronics circuits and how to use a
small computer to control lights and make music. The small computer is called an
Arduino.
Plug in USB cable here.
Plug the other end
into the PC.

CPU Chip – computer


“brain”—ATmega 328 chip.

Breadboard connections will be explained in class.

1. Using the Arduino Software


Now we are ready to look at the software. Open the Arduino program by doubleclicking on the

icon on the Desktop.

Check that Tools->Board is set to either “Arduino Uno”

Check that Tools->Serial Port is set to a port like “COM7.”

Check that one end of the USB cable is plugged into the Arduino and the other end into
your laptop..

Open the first example program, called Blink as follows:

1
Go to the File menu and then scroll down to Examples, over to 1.0 Basics, and then select
the Blink program.

In the dialog box which opens, select Libraries at the left, then the subdirectoriesin turn:
Documents, Arduino, Blink. Finally select the program, Blink or Blink.ino. (It will have
an Arduino icon next to the name.)

1. Blink Program
This will load the Blink program, which will make the light emitting diode (LED), which you
connected to Pin 13, turn on for a second and then turn off for a second. Read the program and
see if it makes sense. If not, please ask! The part inside setup is executed once, at the beginning.
It initializes pin 13 to be an output pin. The part inside loop executes over and over again,
forever, or until the Arduino is reset or reprogrammed. It turns the LED on (sends a high voltage
out to pin 13), waits 1000 mS=1 sec, turns the LED off (sends a low voltage out to pin 13), and
waits 1000 mS.

To load this program into the Arduino, put your mouse over the button which looks like a right
arrow. You will see the white word “Upload.” Click this Upload button. You should see the
program say “Uploading” followed by a message about the number of bytes (>1000) uploaded
into the Arduino.

Then the program should start running and blinking the LED!

How to connect additional LEDs to the


Arduino. The longer pin on the LED should
be connected to the positive end of the circuit
(i.e., the Arduino pin). To connect another
LED, be sure to put a 330 resistor in series
with the LED (to limit the current through the
LED so it doesn’t burn up), as shown in the
series circuit to the left. Because this is a
series circuit and the same current goes
through both the LED and resistor, the
positions of the LED and the resistor can be
swapped in this circuit without changing its
operation. Connect each LED to a different
output pin. Modify the program to make the
chosen pin into an output pin. Then tell the
program to turn this pin on or off.

2
2. TriColor LED

Now let’s try using a tricolor LED, which has 3 LEDs (Red, Green, Blue, i.e., RGB) all inside
the same package.

Piezobuzzer (left), which you will need to


connect to your breadboard (see below for
directions on how to do this)
Tricolor LED (right), common cathode type,
i.e., he ground pins for all of the LEDs are
connected together. The longest pin is the
common pin which should be connected to
the Arduino ground pin. From left to right, the
pins are B, G, common, R.
Here is the circuit diagram for connecting the tricolot LED to the Arduino.

You will need to connect three


resistors (each 330) between the
specified Arduino pins and the three
colored LEDs, as shown in the
diagram. The resistors will reduce
the current through the LEDs so that
they don’t burn up.

Then open the program TriColorLED using the same procedure as before.

Read the program. The part inside loop calls 2 subroutines: mainColors, and showSpectrum.

mainColors turns on the different colors in turn, each for a second:

red, green, blue, then yellow, cyan, purple, and finally white.

showSpectrum changes the intensity (brightness) of the LED and steps through all of the colors
of the rainbow.

Upload the program into the Arduino. Enjoy the colors! You can try to modify this program also.

3
3. Making Music!

Put the piezobuzzer into your breadboard.


Make sure that it’s two pins are connected
into 2 different vertical rows (if the
breadboard is horizontal, like this photo or
the on page 1). Note where the positive
connection is. You need to connect the +
connection to Pin 9 on the Arduino, and the
other pin to ground.

Download Program Blink from Class Smartsite under Resources.

Download the 2 music programs, Song1 and Melody from the Class Smartsite under Resources,
Arduino Programs.

We can try 2 different music programs. Each plays a different melody. Open each program in
turn, upload each, and listen to the melody it produces. Now try to modify one of the programs to
play a different melody!

A. First try Song1.This program has 2 arrays to keep track of the notes. The notes array lists
the names of the notes, with a space to indicate a rest (i.e., no tone). The array beats lists
the durations for each note, with 1 meaning quarter note, 2 meaning half note, etc. The
duration of the rests must be specified also. The subroutine frequency takes the name of
the note as an argument and returns the frequency. The song only plays once, but you can
play it again by pushing the Reset button on the Arduino.
B. Then try Melody. This program works in a completely different way. The note
frequencies are specified in the file “pitches.h,” which must be in the same directory as
Melody.ino. A preprocessor substitutes the frequencies for the names of the notes before
the program is compiled. Then the compiler takes the code and makes the executable
program which you upload. Pitches.h defines 8 octaves of note frequencies, together with
sharps, so you can play any note which would occur on a piano keyboard. You specify
the sequence of notes in the array melody, and the lengths of the notes in the array
noteDurations, where 4 = quarter note, 8 = eighth note, etc.

You might also like