Arduino is an open source microcontroller system. The system is designed to be easy to learn, easy to use, flexible, and fast to develop with. Microcontrollers are little computers that do specific jobs, such as taking input from switches and sensors and then deciding whether to turn on a light or ring a bell. They're widely used in portable devices, including the types you might want to use in a wireless sensor network. Here is how the Arduino project describes itself on its website:
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 micro-controller 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).
You can build the boards by hand or purchase them preassembled; you can download the software for free.
External microcontrollers bring several important advantages to a wireless project, including:
While the basic XBee radios can be a source of sensor data or a trigger for local output, they cannot be programmed to perform logical information processing. If your sensor or device needs local decision-making, you will almost certainly want to add a microcontroller to handle those processes.
Additional input/output lines
Series 2 XBee hardware comes with 10 digital input/output lines, four of which can be configured for analog (variable) input. While using an XBee, you can configure the basic Arduino to use up to 17 digital input/output lines, six of which can take analog input while six others offer hardware support for analog output. If you have extensive input or output needs, an external microcontroller may be just the thing.
It is generally much easier to deploy and test a solution using a simple, high-level development system like Arduino. Even if you just want to do simple input/output on the XBee module, adding an external microcontroller will probably save you time as you try out your initial idea. If everything pans out, you can always slim your project down later.
Lots of connection options
With the help of an Arduino, your XBee can drive large motors, interact with GPS modules, drive LCD display screens, store data in local memory banks, and interact directly with the Internet via WiFi or your mobile phone. Working together, the possibilities are limitless.
Here is how to get ready to work with the Arduino microcontroller system.
Downloading the software
To program the Arduino, use an open source application that runs on your computer. The application is known as the IDE (or integrated development environment) and you can download it for free directly from the Arduino website's software area. There are versions available for Macintosh, Windows, and Linux. Download the appropriate version for your computer. You will find a basic guide to getting started at http://arduino.cc/en/Guide/HomePage.
Using the Arduino IDE
The Arduino IDE is split into three areas. The blue area at the top of the window features a toolbar of buttons that control program behavior. The white area in the middle is where you enter and modify code. The black section at the bottom of the window is where status messages appear, and where you should look for error messages that can help you debug your code.
As described in the online Arduino guide, the toolbar buttons perform the following functions:
Selecting the board and port
To connect to your Arduino board, you must plug it into your computer using a USB A-to-B-style cable. Next, select the model of your Arduino board from the Board menu. Finally, select your serial port from the Serial menu. On Windows computers, the serial port will be one of the COM ports. On Macintosh, the serial port will have a name that includes
usbserial, followed by some identifying letters and numbers. Once you've selected your board type and port, you're ready to do some programming!
The Arduino language is based on C/C++ and as such it shares a specific set of structures that have been simplified for people new to programming. A simple program might look something like this:
A basic program begins with statements that declare the names, types, and initial values for named containers that are used throughout the program, also known as global variables. Next comes a section that begins with
void setup(). Everything between the curly braces for this section is code that runs only once, right after the Arduino is powered up or reset. Typically this section contains procedures that get the Arduino board ready to do its work, like initializing pins, setting up serial ports, and anything else that needs to happen only once, on startup. Finally, there's a section that starts with
void loop(). The code contained in the loop section, between its curly braces, runs constantly. In the example above, this code will turn on an LED light, wait a moment, then turn it off and wait a moment. That's one blink of a blinking light. As soon as the first blink is complete, the loop code runs again, meaning the light will blink on and off indefinitely. Sometimes there will be other sections following the loop. These describe additional functions that are typically called from the main loop, but also could be called from setup or by each other.
For full information on getting started with Arduino programming, take a look at the longer explanation at http://arduino.cc/en/Tutorial/Foundations and the many examples that can be downloaded from http://arduino.cc/en/Tutorial/HomePage. You will find the complete language reference at http://arduino.cc/en/Reference/HomePage. These resources are also available from the Help menu in the Arduino IDE.