You are on page 1of 7

UG 106: Praxis I

Undergraduate Program
Handout: Arduino Tutorial “Getting Started”

September 2012 Semester
Asian Institute of Technology
Instructors: Waqar Shahid, Matthew N. Dailey

Arduino “Getting Started” Tutorial
Introduction: This tutorial will introduce you to the Arduino board and how to use it. We will also learn
some basics required to implement the equivalent of the “Hello World” program on the Arduino board. The
hardware version of “Hello World” is to make an LED (Light Emitting Diode) blink, instead of printing a
message (since we have no terminal to print to).
Credits: Thanks to Pham Huy Nguyen for pointers to Arduino tutorials.

What is Arduino?
The Arduino is a sophisticated single-board computer that can be programmed to sense and control the
physical world around us. It can be used as a dedicated computer for industrial automation or to control a
robot. It can take input from a variety of sensors connected to its input pins. It can process the information
locally or can send data to another computer for remote computation. The processed information can then
be used to make decisions and/or control motors or other actuators connected to the board’s output pins.

The processing unit on the Arduino is the ATmega328 microcontroller integrated circuit. It uses input and
output ports/pins to communicate with the outside world. Some of the microcontroller’s inputs and outputs
are connected to peripherals and other electronic components on the board itself, and others are available
for use as sensor inputs or output to other devices. The microcontroller can be programmed using an open
source programming platform based on the C programming language and a “wiring” language that is very
easy to use.

(a) Front

(b) Back

Figure 1: Snap-Shot of Arduino Board UNO R3
A summary of the board’s specifications follows:


or. 1024 different values).Microcontroller Operating Voltage Input Voltage (recommended) Input Voltage (limits) Digital I/O Pins Analog Input Pins DC Current per I/O Pin DC Current for 3. ❼ Serial: pin-0 and pin-1 can be configured to be used receiving and transmitting serial data to peripheral device or computer. or a desktop power supply. ❼ 5V: This pin outputs a regulated 5V from the regulator on the board.3V pins bypasses the regulator. the USB connector (5V). ❼ LED: An SMD-LED is connected to pin-13 of the µC. you can use a battery. pin-6. Maximum current draw is 50 mA. 2 . Generally. pin-11 (MOSI). ❼ GND: The ground pin or the negative terminal of your board. if supplying voltage via the power jack. pin-5. Some of the pins on Arduino UNO board can also be used for other specialized function. By default they measure from ground to 5 volts. ❼ Reset: To reset the micro-controller. pin-13 (SCK) pins can be configured for serial communication using SPI protocol. ❼ TWI: pin-A4 (SDA) and pin-A5 (SCL) pin support TWI communication. the LED is on. For the external power supply. or the VIN pin of the board (7-12V).3V supply generated by the on-board regulator.5 KB is used by the bootloader 2 KB (ATmega328) 1 KB (ATmega328) 16 MHz Powering the Arduino Board The board can be powered through the USB connector or through an external power supply. The power pins on the board are: ❼ VIN: The input voltage pin for Arduino for external power source.3V Pin Flash Memory SRAM EEPROM Clock Speed ATmega328 5V 7–12V 6–20V 14 (of which 6 provide PWM output) 6 40 mA 50 mA 32 KB (ATmega328) of which 0. access it through this pin. pin-10. When the pin has logic-high. Supplying voltage via the 5V or 3. By default the reference voltage is from 0 5 Volts. ❼ SPI: pin-10 (SS). A couple of other pins on the board are: ❼ AREF: Reference voltage for analog input. USB power is sufficient for blinking LEDS and other applications where the total current required is small. Each analog input pin provides 10 bits of resolution (i. and when it is logic-low it is off. Input and Output: There are 14 digital pins/ports on the Arduino UNO. The board can be supplied with power either from the DC power jack (7–12V). ❼ External Interrupts: pin-2 and pin-3 can configured as external interrupt. and can damage your board. you should not wire a battery or power supply directly to this pin! ❼ 3V3: A 3. pin-9. There are 6 analog input pins/ports. an AC-DC adapter with an appropriate output voltage. They all operate at 5V and can be used for input or output. labeled A0 through A5. ❼ PWM: pin-3. Each pin can give or receive approximately 40mA of current. pin-12 (MISO).e. You can supply voltage through this pin. pin-11 can be configured as Pulse width modulation (PWM) outputs.

The programming platform enables you to write and edit your program in wiring-language.structure. if you want to play with the hardware./arduino shell script on your terminal and it will open the Arduino platform on your machine. one is the setup() function. I prefer Ubundu (Linux) operating system. It can also upload your program using the same software. ❼ http://arduino. Go to http://arduino. The Arduino programs can be categorized in 3 which allows to upload new code to it without the use of an external hardware For The µC on the Arduino UNO comes with a pre-burned boot-loader. The basic structure of the programming language is Instead of using a physical “Reset” button the Arduino Uno is designed in a way that allows it to be reset by software running on a connected computer. which is the preparation part. It is the to choose and download the compressed packaged based on your Operating System. It can cross compile your code for ATmega328. Run . 6. The other is the loop() function which is the execution Software The Arduino Uno can be programmed with the open-source Arduino software. ❼ http://arduino. 5. For details on programming please refer to http://arduino. Based on your operating system selection a zipped file will be downloaded on your machine. 3.Further details and Schematics of the open-source board is available at ❼ http://arduino. 2. 3 . Open a new Terminal in Linux and go to the folder you unzipped. It will always contain 2 parts/functions. values and functions. compile and upload your program for Arduino board. Therefore a simple sketch of your program will look like as: void setup() { \\statements here } void loop() { \\statements here } Arduino Software Platform Installation We now go through a step-by-step instruction to install Arduino programming platform on our laptop and to communicate it with the Arduino UNO R3. 4.pdf. Unzip the file in a folder. For me. Connect one end of Arduino board USB cable with your machine You are now ready to write. 1.

A program will be opened in a separate window and will look like as follows: /* Blink Turns on an LED on for one second. The resistor is there to control the current in the LED. repeatedly. Referring to the installation of the Arduino software. reprinted from Beginning to Android with Arduino You can connect the circuit as shown in the Figure 4a.4b. File-Examples-Basics-Blink. Figure 2: Equipment and Components Required. */ // Pin 13 has an LED connected on most Arduino boards.Blinking LED For this program we need the hardware given as follows: 1.“Hello World”. Now. Jumper (connecting wires) 4. 4 . you will see the Arduino IDE as shown in the Figure 5. Resistor Identifying the positive and the negative terminal of the LED is important before implementing the circuit. Arduino UNO R3 2. once you run the shell script in Ubuntu or the open the executable in Windows. then off for one second. The Blinking LED program is part of the public domain examples program as given on th arduino website. Bread-board 3. You can see that the LED is connected to pin-13 and to ground via 220Ω resistor. You can directly open the program from menu on the top left corner by following the hierarchy. Light emitting diode (LED) 5. you are ready to write your code to program ATmega328. This example code is in the public domain. Figure 3 shows the table to identify the value of resistor without the use of a multi-meter.

5 .htm (a) Schematics generated by Fritzing-0.7b (b) Circuit Diagram generated by Fritzing-0. // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output.7b Figure 4: Circuit and Schematics for Blinking LED // give it a name: int led = 3: Resistor Coloring Code. OUTPUT). pinMode(led. reprinted from http://www.

// turn the LED on (HIGH is the voltage level) delay(1000).10Ω resistor and some more connecting wires. the board will automatically get a reset and after a few second will start blinking your LED. We need 1 digital on-off switch and 1. LOW). If there is no errors. We will also make use of the 5V input pin of the board and pin-2 as digital input pin.Figure 5: Arduino IDE for cross-platform compilation } // the loop routine runs over and over again forever: void loop() { digitalWrite(led. then press cntrl-U to upload the compiled program on your µC Flash memory. // wait for a second digitalWrite(led. Figure 6: Figure generated by Fritzing. 6 . the next assignment is to implement a digital switch using the board. once the program is uploaded successfully. HIGH). // turn the LED off by making the voltage LOW delay(1000). // wait for a second } Press cntrl-R to compile the code. As told earlier. taken from Exercise Now.

❼ Beginning Android ADK with Arduino by Mario Bohmer ❼ ❼ www. Use the if statement to check the condition of the digital switch or if the digital input pin is the LED should not blink. Use the function pinMode() to declare the mode of ❼ http://arduino. Use digitalRead() function to check the condition of the pin-2. ❼ ❼ http://arduino.Connect the circuit as shown in figure 7 . Brian W. If the input is HIGH then ”Blink” the LED. References ❼ http://arduino. ❼ ”Arduino Programming Notebook” by .pdf.