Transcript Document

Arduino Project 1 - Introduction to Arduino Programming
Name ________________________________________________________ Score _________
In this laboratory project you will learn how to program the Arduino series of microcontrollers
using the Arduino IDE and associated development tools.
Introduction: The Arduino IDE and other support tools and tutorials are available at
http://www.arduino.cc. As noted on their home page,
Arduino is an open-source electronics prototyping platform based on flexible, easyto-use hardware and software. It's intended for artists, designers, hobbyists and
anyone interested in creating interactive objects or environments.
Arduino can sense the environment by receiving input from a variety of sensors and can
affect its surroundings by controlling lights, motors, and other actuators. The
microcontroller on the board is programmed using the Arduino programming language
(based on Wiring) and the Arduino development environment (based on Processing).
Arduino projects can be stand-alone or they can communicate with software running on a
computer (e.g. Flash, Processing, MaxMSP).
Setup: Go to the download page of the arduino.cc Website to find step-by-step instructions
for installing Arduino 1.0.5 (or the latest IDE for Arduino Uno) on Windows, Mac OS or Linux.
Choose the tools for your platform and complete the installation process.
Connect the Arduino to the host computer using a standard a-type USB cable. You may need
to manually install the drivers (in Device Manager for Windows) from the Arduino folder in
C:\Program Files or wherever the installer has placed it.
Make sure you have selected the correct COM port for the Arduino (usually the larger one
listed under Tools\Serial Port on the IDE.
Verify
Upload
New
Navigate to File\Open\Examples\01.Basics\Blink\ and open the file blink.ino.
Verify and Upload this program to your Arduino. (Check to see if there are any errors listed in
the message panel and the bottom of the IDE main view.
1. Is the yellow-orange LED on the Arduino blinking? ______________________________
Find the lines of code that are causing this LED to blink. Change the amount of delay
between blinks, recompile and upload.
2. Did the blink rate change as expected? _________________________________________
Fix any errors and make sure this program is being uploaded and executed correctly before
continuing.
int led = 13;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
Notice the three sections of the program.
There is a global initializations section, the
setup( ) and the loop( ) which is the main body
of the program. The loop( ) is repeated
indefinitely while the processor is powered.
//
//
//
//
turn
wait
turn
wait
LED
for
LED
for
on (HIGH voltage level)
a second
off by making voltage LOW
a second
Next load the program ASCIITable found in the Communications folder under File\Open\Examples.
Compile and upload this program. To see its operation you will need to open the Serial Monitor
under the Tools menu. Review the streamlined version of this program below:
int thisByte = 33;
void setup() {
Serial.begin(9600);
Serial.println("ASCII Table ~ Character Map");
}
void loop()
{
Serial.write(thisByte);
Serial.print(", dec: ");
Serial.print(thisByte);
Serial.print(", hex: ");
Serial.print(thisByte, HEX);
Serial.print(", oct: ");
Serial.print(thisByte, OCT);
Serial.print(", bin: ");
Serial.println(thisByte, BIN);
if(thisByte == 126)
{
while(true) {continue;}
}
thisByte++;
}
The int variable called thisByte is initially set equal to 33 which corresponds to the (!) character
in ASCII code. In the setup( ) a serial communication is established at 9600 baud between the
Arduino and the host computer. The Serial.XXX methods send data to the Serial Monitor to be
displayed.
3. What is the difference between the Serial.write( ) and the Serial.print( ) methods? ________
___________________________________________________________________________
4. Since the loop( ) method repeats indefinitely, why does the Serial Monitor display stop after
displaying the tilde (~) ?
_______________________________________________________
___________________________________________________________________________
Program: Write your own Arduino program that displays all 8-bit binary values on the Serial
Monitor. You may submit your source code in hardcopy attached to this handout.