means the pin will output 5 volts until further notice, and the LED connected
to the pin will light up.
The program then calls
delay
and waits for 500 milliseconds doing nothing.
During this pause, pin 13 remains in
HIGH
state, and the LED continues to
burn. The LED is eventually turned off when we set the pin’s state back to
LOW
using
digitalWrite
again. We wait another 500 milliseconds, and then the
loop
function ends. The Arduino starts it again, and the LED blinks.
In the next section, you’ll learn how to bring the program to life and transfer
it to the Arduino.
Compiling and Uploading Programs
Before you compile and upload a program to the Arduino, you have to config-
ure two things in the IDE: the type of Arduino you’re using and the serial port
your Arduino is connected to. Since Arduino 1.6.0, the IDE tries to identify
all Arduino boards that are connected to your computer automatically. This
feature works quite well, but it also fails sometimes. So, you need to learn
how to determine the type of your Arduino board and the name of the serial
port it is connected to.
Identifying the Arduino type is easy, because it is printed on the board. Pop-
ular types are Uno, Duemilanove, Diecimila, Nano, Mega, Mini, NG, BT, Lily-
Pad, Pro, or Pro Mini. In some cases, you also have to check what microcon-
troller your Arduino uses—most have an ATmega328. You can find the
microcontroller type printed on the microcontroller itself. When you have
identified the exact type of your Arduino, choose it from the Tools > Board
menu.
Now you have to choose the serial port your Arduino is connected to from the
Tools > Serial Port menu. On Mac OS X, the name of the serial port usually
starts with
/dev/tty.usbserial
or
/dev/tty.usbmodem
. (On my MacBook Pro, it’s
/dev/tty.usbmodem24321
.) On Linux systems, it should be
/dev/ttyUSB0
,
/dev/ttyUSB1
,
or something similar, depending on the number of USB ports your computer
has.
On Windows systems, you have to use the Device Manager to find out the
right serial port. In the Device Manager, look for USB Serial Port below the
Ports (COM & LPT) menu entry. (See Installing the Drivers for Current Arduino
Boards, on page 11) Usually the port is named COM1, COM2, or something
similar.
report erratum • discuss
Compiling and Uploading Programs • 19
www.it-ebooks.info