Introduction to Arduino

Submitted by james on
Generic UNO clone

This is a brief introduction to the Arduino hardware and software platforms. When someone mentions "Arduino" in conversation, the word can mean a number of things:

  1. Arduino® is the name of a company and trademarked brand producing electronics hardware and software. Arduino hardware devices are somewhat unusual in that the designs are "open source", meaning other companies can freely produce their own devices based on the same designs.
  2. An Arduino device is often simply called an Arduino ("My project uses an Arduino"), although each model also has a more specific name.
  3. You develop software for your Arduino devices using the Arduino IDE software and associated code libraries.
  4. 'Arduino' can also refer to the whole ecosystem surrounding all of this hardware and software. ("Have you considered Arduino for this?")
  5. For many hobbyists and students, what Arduino really represents is a stepping stone from the world of computers into the world of electronics.

The hardware

There are a variety of Arduino devices, or boards, perhaps the most common being the Uno, the Nano, and the Mega 2560. Although their specs vary, they all serve essentially the same purpose. On each board is a microcontroller with a primitive CPU and tiny amount of memory, and several pins for input and output. Also present is a USB port for power and communication with a computer, and sometimes a jack to connect power when USB is not being used.

The software

There are three main types of software related to Arduino: The bootloader, the integrated development environment (IDE), and code libraries.

The Arduino bootloader is a tiny bit of code that is preloaded on the microcontroller, enabling it to be programmed over the USB port. It is possible to overwrite the bootloader with your own code, but then you will have to use specialized hardware (called an in-system programmer, or ISP) to program it. Interestingly, you can program an Arduino board to act as as an ISP to program other chips.

The Arduino IDE is a desktop application that provides an easy path to get started writing code for your device. Although it is a reasonably capable application, it lacks much of the functionality found in other code editors and IDEs such as Eclipse or Visual Studio. As you write more advanced code, you may find that the Arduino IDE no longer meets your needs. Fortunately, other IDEs can be made to work with Arduino.

The Arduino libraries are a collection of pre-written code for functionality such as controlling motors, reading and writing data, and communicating with other devices. A number of standard library capabilities are included with the Arduino IDE, and many more have been made freely available by third-party developers.

Your first program

The simplest Arduino program looks like the following:

void setup()
{
}

void loop()
{
}

What we have done here is define two functions, one named setup and one named loop. These are two special functions that are automatically called (or executed) after the Arduino device starts up.

Now let's get familiar with some terminology that will recur throughout this text. If you have already done some programming in a "C-like" language, this will all be review, so feel free to skip to the next section.

The void indicates that the function doesn't return any value to its caller. Later we will write functions that return numbers, strings of text, or other values. In those cases, void will be replaced with the appropriate data type.

After the function name are two parentheses, ( and ). This is where we would describe the function's parameters. Parameters declare the types of data that the function expects to receive when it is called. Each parameter also has a name that allows us to work with the data within the function. The two functions above do not have any parameters, so the parentheses are empty.

Finally, anything that we write between the opening and closing braces, { and }, is the code that will run when each function is called. As you can see, there is no code between the braces, so this program does nothing!

Although you will find many code examples throughout this text, it will be immensely helpful if you already have some skill with programming, especially using a language similar to C or C++.