1Getting Started with Arduino

This project covers everything you need to get your Arduino up and running! We’ll introduce the hardware, show you how to install the programming environment, and help you make sure everything works by loading a simple program. At the end, you should have your own blinking light and the excitement to move on. Let’s go!

MATERIALS TO GATHER

You’ll need the following hardware (shown inFigure 1-1) to complete this project:

• One SparkFun RedBoard (DEV-13975), Arduino Uno (DEV-11021), or any other Arduino-compatible board

• One USB Mini-B cable (CAB-11301 or your board’s USB cable)

• One LED (COM-09590, or COM-12062 for a pack of 20)

FIGURE 1-1:Required components

ABOUT THE ARDUINO

AnArduino(pronounced är·də’wēn·ō or “arr-dween-oh!”) is a small programmable device that can add smarts to nonintelligent things. You can use an Arduino to run robots, create LED art, and even act as a handheld gaming console. In this section, we’ll go into more detail on what the Arduino is and how it can change the way you think about the world around you.

An Accessible Hardware Platform

An Arduino is like a small computer. You can program it using very simple instructions, and you can power it with just a few AA batteries. What makes an Arduino really different from a regular computer is that it uses amicrocontroller, rather than a CPU, to process information and take action. This small chip acts as the brains of your project, and it can receive input from sensors (like light detectors, temperature sensors, or buttons) and output signals to control LEDs, motors,buzzers, and more. An Arduino board like the one inFigure 1-2has all of the supporting components and circuitry to make a micro-controller work.

FIGURE 1-2:The Arduino Uno is an open source, programmable electronics platform for hobbyists.

The programming language used for the Arduino is essentially a version of C/C++. The programming environment is theArduino IDE (integrated development environment). The team that developed it bundled it with many prewritten functions and libraries to simplify the process of writing code to interface with hardware. For example, these libraries take the multiple lines of code required to turn on an LED and simplify them into a single instruction!

About the SparkFun RedBoard

There are many officially Arduino-branded boards, but since the platform isopen source(meaning the source hardware design and software are available for anyone to look at and modify), there are also many Arduino derivatives, clones, and compatible boards. The board designs are all licensed under a Creative Commons Attribution Share-Alike license, and the Arduino FAQ (https://www.arduino.cc/en/Main/FAQ) states that anyone is “free to use and adapt [these designs] for your own needs without asking permission or paying a fee.” Derivative boards work with the same programming environment as an official Arduino, but often the hardware has been tweaked or modified in some way.

The SparkFun RedBoard, pictured inFigure 1-3, is an Arduino-compatible derivative board. It is based on the Arduino Uno design but has a more stable USB interface and uses a USB mini connector instead of the Type-A connector. Otherwise, it is exactly the same as the Uno, with the same size and shape.

The RedBoard is the go-to Arduino board here at SparkFun and has a few key components that you’ll need to know in order to navigate the first few chapters of this book. We have labeled each term for you inFigure 1-3.

ATmega328 microcontrollerThe square black chip in the middle of the board. It is the brain of the Arduino.

Header pinsThe tiny metal legs on the microcontroller, which let you read input and send output. They are accessible through the four sets of black headers on either side of the Arduino. They are numbered and labeled for specific uses. The pins you’ll care about most are those labeledDigital(0–13),Analog In(A0–A5), andPower.

Mini-USB portThis is how you send code to and communicate with the Arduino. You can also power your board using the USB port for most applications in this book. If an external power supply is needed, we’ll be sure to point it out.

Power LEDThis LED is an indicator to show that the Arduino is powered on. If you ever have a short circuit on your board or a bad power connection, this indicator will not turn on.

TX/RX LEDsThese LEDs blink when data, such as code or numbers, is being passed back and forth between your Arduino and your laptop.

Onboard LED 13A debug light. If you’re plugging your Arduino in for the first time, LED 13 should blink once per second. It’s connected to pin 13 on the Arduino.

External power jackA barrel jack port next to the USB port. The Arduino takes 5 V of power, though you can safely supply the Arduino a voltage between 7 and 15 V without damaging your board. A chip on the Arduino scales this input voltage down to 5 V for the electronics and circuitry to work properly.

Like all Arduino-compatible boards, you’ll program the RedBoard with the Arduino IDE.

INSTALLING THE ARDUINO IDE AND DRIVERS

You should install the Arduino IDE before plugging your RedBoard into the USB port for the first time. To install the Arduino IDE, go tohttp://www.arduino.cc/download/. Select the appropriate version for your computer’s operating system, and click the link to download (Figure 1-4). You’ll be asked whether you’d like to make a contribution; the development and maintenance of the Arduino IDE rely on the help and contributions of the community that uses it.

NOTE

If you’ve already plugged in your board, that’s not a problem—you may just need to restart your computer after the installation is complete for the drivers to work properly.

FIGURE 1-4:You can use the online IDE or download the latest version for your operating system.

Even if you already have the IDE installed, we recommend downloading and installing the latest version. The Arduino IDE is continuously being updated and improved, and it’s best to have the newest release. The examples in this book use IDE versions 1.8.1 and later.

NOTE

If you like to be on the bleeding edge of software, the Arduino Downloads page also provides nightly builds that preview the next release. For this book, however, we recommend using the latest stable release.

The Arduino website also provides an online platform called Arduino Create, which includes a web-based code editor. It allows you to program your device through your web browser and share and view projects with others online. As of the writing of this book, it is supported only on Windows and OS X.

Whether you choose to use Arduino Create or the downloaded IDE, follow the directions online to run the installation process.

Installing on Windows

If you’re working on a Windows PC, we recommend downloading the Windows Installer version of Arduino. Download this file, open it, and clickRun. This will bring up the Installation Options dialog (Figure 1-5).

FIGURE 1-5:Installation Options dialog for Arduino. Make sure that USB drivers are selected!

Check theInstall Arduino softwarebox along with the other options, or you’ll have to install the drivers separately. Then, tell the installer where you’d like to install Arduino (we recommend accepting the default directory), and clickInstall.

Once you begin the installation process, have a snack or a cup of coffee, because it could take a few minutes to complete. Depending on your version of Windows, you might again be asked if you want to install drivers and if Arduino LLC is trusted, as pictured inFigure 1-6.