Embedded: Designing & Programming using Arduino
ARDUINOCOMPILER
Table of Contents
Table of Contents................................................................................................................................................ 1
Arduino Compiler............................................................................................................................................... 2
1. Introduction.....................................................................................................................................2
2. Software:..........................................................................................................................................3
3. Why Arduino?..................................................................................................................................4
4. Working in Arduino:.........................................................................................................................4
ARDUINO COMPILER
1. INTRODUCTION
Arduino is a tool for making computers that can sense
and control more of the physical world than your
desktop computer. It's an open-source physical
computing platform based on a simple microcontroller
board, and a development environment for writing
software for the board.
Page 1
Embedded: Designing & Programming using Arduino
Arduino can be used to develop interactive objects, taking inputs from a variety of switches or sensors, and
controlling a variety of lights, motors, and other physical outputs. Arduino projects can be stand-alone, or
they can be communicating with software running on your computer (e.g. Flash, Processing, MAX-MSP.)
The boards can be assembled by hand or purchased preassembled; the open-source IDE can be
downloaded for free.
The Arduino programming language is an implementation of Wiring, a similar physical computing platform,
which is based on the Processing multimedia programming environment.
Arduino is a popular open-source single-board microcontroller, descendant of the open-source Wiring
platform designed to make the process of using electronics in multidisciplinary projects more accessible.
The hardware consists of a simple open hardware design for the Arduino board with an Atmel
AVR processor and on-board input/output support. The software consists of a standard programming
language compiler and the boot loader that runs on the board.
Arduino hardware is programmed using a Wiring-based language (syntax and libraries), similar to C++ with
some slight simplifications and modifications, and a Processing-based integrated development
environment
2. SOFTWARE:
The Arduino IDE is a cross-platform application written in Java,
and is derived from the IDE for the Processing programming
language and the Wiring project. It is designed to introduce
programming to artists and other newcomers unfamiliar with
software development. It includes a code editor with features
such as syntax highlighting, brace matching, and automatic
indentation, and is also capable of compiling and uploading
programs to the board with a single click. There is typically no
need to edit make files or run programs on a command-line
Page 2
Embedded: Designing & Programming using Arduino
interface. Although building on command-line is possible if required with some third-party tools such
as Ino.
The Arduino IDE comes with a C/C++ library called "Wiring" (from the project of the same name), which
makes many common input/output operations much easier. Arduino programs are written in C/C++,
although users only need define two functions to make a run-able program:
setup () – a function run once at the start of a program that can initialize settings
loop() – a function called repeatedly until the board powers of
A typical first program for a microcontroller simply blinks an LED on and of. In the Arduino
environment, the user might write a program like this:
#define LED_PIN 13
void setup () {
pinMode (LED_PIN, OUTPUT); // enable pin 13 for digital output
}
void loop () {
digitalWrite (LED_PIN, HIGH); // turn on the LED
delay (1000); // wait one second (1000 milliseconds)
digitalWrite (LED_PIN, LOW); // turn of the LED
delay (1000); // wait one second
}
3. WHY ARDUINO?
There are many other microcontrollers and microcontroller platforms available for physical computing.
Parallax Basic Stamp, and many others ofer similar functionality. All of these tools take the messy details
of microcontroller programming and wrap it up in an easy-to-use package. Arduino also simplifies the
process of working with microcontrollers, but it ofers some advantage for teachers, students, and
interested amateurs over other systems:
Inexpensive - Arduino boards are relatively inexpensive compared to other microcontroller platforms. The
least expensive version of the Arduino module can be assembled by hand, and even the pre-assembled
Arduino modules cost less than $50
Cross-platform - The Arduino software runs on Windows, Macintosh OSX, and Linux operating systems.
Most microcontroller systems are limited to Windows.
Page 3
Embedded: Designing & Programming using Arduino
Simple, clear programming environment - The Arduino programming environment is easy-to-use for
beginners, yet flexible enough for advanced users to take advantage of as well. For teachers, it's
conveniently based on the Processing programming environment, so students learning to program in that
environment will be familiar with the look and feel of Arduino
Open source and extensible software- The Arduino software and is published as open source tools,
available for extension by experienced programmers. The language can be expanded through C++ libraries,
and people wanting to understand the technical details can make the leap from Arduino to the AVR C
programming language on which it's based. Similarly, you can add AVR- C
code directly into your Arduino programs if you want to.
Open source and extensible hardware - The Arduino is based on
Atmel's ATMEGA8 and ATMEGA168microcontrollers. The plans for the
modules are published under a Creative Commons license, so
experienced circuit designers can make their own version of the
module, extending it and improving it. Even relatively inexperienced
users can build the breadboard version of the module in order to understand how it works and save
money.
Arduino Environment
4. WORKING IN ARDUINO:
The Arduino development environment contains a text editor for writing
code, a message area, a text console, a toolbar with buttons for common
functions, and a series of menus. Software written using Arduino is called
sketches. It has features for cutting/pasting and for searching/replacing text. The message area gives feedback
while saving and exporting and also displays errors. The console displays text output by the Arduino
environment including complete error messages and other information. Now let us install the Arduino into our
system and start working with it.
Follow the following steps to install the Arduino in your computer/laptop:
Step1. Install the FTDI driver provided in the CD given to you. To install it simply, unzip the FTDI file and install
the driver. It may take from few seconds to even minutes to install depending on the computer and operating
systems.
Step2. Open the “Arduino-022” folder and click on the Arduino icon. A window will appear as shown here.
Step3. Click on Tools from menu bar and select the board, and then select the board as “ Arduino NG or older /
ATMEGA 168”.
Page 4
Embedded: Designing & Programming using Arduino
Note: Please note that this option can be changed depending on the hardware used by the user. This is just an
example of the board which is based on Arduino NG based on ATMEGA 168; hence we have selected this
option.
Step4. Connect the device with the computer using USB cable. Now we have to select the serial port on which
the board will communicate with the computer. Go to Tools->Serial Port->COM X. Here the ‘x, varies from
computer to computer. See the image.
Note: It is very confusing to select the proper com port. We can check it by inserting and removing the USB
cable, the new com generated by inserting the cable should be selected. Although, the Arduino selects the
com port automatically, but sometimes we have to select the ports manually. The proper board
has to be selected manually only.
The code which goes inside the microcontroller is known as ‘HEX’ code. This code is generated by
compilers. The process of loading the code into the (flash memory of) microcontrollers is known as
‘Burning’ the microcontroller.
There are several methods of burning microcontroller like using ‘ISP’ method, using ‘High Voltage
Programming’ using ‘Boot-loaders’ etc. Each method has its own merits and demerits.
T he easiest way of programming is by using ‘Boot-loaders’. Boot-loaders are small programs residing
inside the flash of the microcontrollers. The Boot-loaders can burn the program by any interfacing
technique. For example in our system, the Boot-loader is there to program the device using serial port (UART).
The board supports both, ISP programming (ISP Header is there on the board) and UART programming method
(using USB interface). To program using UART interface make sure the device is Boot loaded. The Arduino
works on UART interfaced programming.
Let us explain more about environment of Arduino. There is a menu bar on the top of the window. All the lists
in here are self explanatory. We will seldom use these lists. Below menu bar, there is a tool bar frequently used
in the environment. The icons of tool bar are explained here.
Verify: It is used to verify the code, if there is any syntax error
then it gets highlighted. If there is no error, then Selecting the board
compilation is done.
Stop: It is used to stop the verification at any time.
New: Used to create a new workspace, but current
workspace will be closed.
Open: It is used to save any saved sketch.
Save: Use to save the current sketch.
Page 5
Embedded: Designing & Programming using Arduino
Upload: Used to upload the sketch into the microcontroller.
Any error, warning or notification can be shown in dark black window of the IDE.
The development board provided contains all these connections. Hence we never need to make any such
connections unless otherwise stated. For each program described further may have diferent circuit. The
circuits are shown if necessary. Now let us start programming. Open the Arduino environment; select the
proper com port and board as described earlier. Now, try to compile this code given in figure, it will produce no
error. Because it is complete.
There are two functions here:
1. void setup()
2. void loop()
Before discussing about these, let us know what the ‘function’ is. Function is nothing but a group of statements
under a single name. All these statements are assumed to be executed at once. All the functions start with an
opening parentheses (‘{‘) and terminates closing parentheses (‘}’). With and More discussion about ‘function’
is described later in the tutorial.
All the lines written under void setup () function will execute only once as the program starts. Hence
everything written under this function will execute only once.
All the programs written under void loop () function will keep on executing as long as the system is kept on as
this function keeps on executing continuously.
Page 6