- •Acknowledgments
- •Preface
- •Who Should Read This Book
- •What’s in This Book
- •Arduino Uno and the Arduino Platform
- •Code Examples and Conventions
- •Online Resources
- •The Parts You Need
- •Starter Packs
- •Complete Parts List
- •1. Welcome to the Arduino
- •What You Need
- •What Exactly Is an Arduino?
- •Exploring the Arduino Board
- •Installing the Arduino IDE
- •Meeting the Arduino IDE
- •Hello, World!
- •Compiling and Uploading Programs
- •What If It Doesn’t Work?
- •Exercises
- •2. Creating Bigger Projects with the Arduino
- •What You Need
- •Managing Projects and Sketches
- •Changing Preferences
- •Using Serial Ports
- •What If It Doesn’t Work?
- •Exercises
- •3. Building Binary Dice
- •What You Need
- •Working with Breadboards
- •Using an LED on a Breadboard
- •First Version of a Binary Die
- •Working with Buttons
- •Adding Your Own Button
- •Building a Dice Game
- •What If It Doesn’t Work?
- •Exercises
- •4. Building a Morse Code Generator Library
- •What You Need
- •Learning the Basics of Morse Code
- •Building a Morse Code Generator
- •Fleshing Out the Morse Code Generator’s Interface
- •Outputting Morse Code Symbols
- •Installing and Using the Telegraph Class
- •Publishing Your Own Library
- •What If It Doesn’t Work?
- •Exercises
- •5. Sensing the World Around Us
- •What You Need
- •Measuring Distances with an Ultrasonic Sensor
- •Increasing Precision Using Floating-Point Numbers
- •Increasing Precision Using a Temperature Sensor
- •Creating Your Own Dashboard
- •What If It Doesn’t Work?
- •Exercises
- •What You Need
- •Wiring Up the Accelerometer
- •Bringing Your Accelerometer to Life
- •Finding and Polishing Edge Values
- •Building Your Own Game Controller
- •More Projects
- •What If It Doesn’t Work?
- •Exercises
- •7. Writing a Game for the Motion-Sensing Game Controller
- •Writing a GameController Class
- •Creating the Game
- •What If It Doesn’t Work?
- •Exercises
- •8. Generating Video Signals with an Arduino
- •What You Need
- •How Analog Video Works
- •Building a Digital-to-Analog Converter (DAC)
- •Connecting the Arduino to Your TV Set
- •Using the TVout Library
- •Building a TV Thermometer
- •Working with Graphics in TVout
- •What If It Doesn’t Work?
- •Exercises
- •9. Tinkering with the Wii Nunchuk
- •What You Need
- •Wiring a Wii Nunchuk
- •Talking to a Nunchuk
- •Building a Nunchuk Class
- •Using Our Nunchuk Class
- •Creating Your Own Video Game Console
- •Creating Your Own Video Game
- •What If It Doesn’t Work?
- •Exercises
- •10. Networking with Arduino
- •What You Need
- •Using Your PC to Transfer Sensor Data to the Internet
- •Registering an Application with Twitter
- •Tweeting Messages with Processing
- •Communicating Over Networks Using an Ethernet Shield
- •Using DHCP and DNS
- •What If It Doesn’t Work?
- •Exercises
- •11. Creating a Burglar Alarm with Email Notification
- •What You Need
- •Emailing from the Command Line
- •Emailing Directly from an Arduino
- •Detecting Motion Using a Passive Infrared Sensor
- •Bringing It All Together
- •What If It Doesn’t Work?
- •Exercises
- •What You Need
- •Understanding Infrared Remote Controls
- •Grabbing Remote Control Codes
- •Cloning a Remote
- •Controlling Infrared Devices Remotely with Your Browser
- •Building an Infrared Proxy
- •What If It Doesn’t Work?
- •Exercises
- •13. Controlling Motors with Arduino
- •What You Need
- •Introducing Motors
- •First Steps with a Servo Motor
- •Building a Blaminatr
- •What If It Doesn’t Work?
- •Exercises
- •Current, Voltage, and Resistance
- •Electrical Circuits
- •Learning How to Use a Wire Cutter
- •Learning How to Solder
- •Learning How to Desolder
- •The Arduino Programming Language
- •Bit Operations
- •Learning More About Serial Communication
- •Serial Communication Using Various Languages
- •What Are Google Chrome Apps?
- •Creating a Minimal Chrome App
- •Starting the Chrome App
- •Exploring the Chrome Serial API
- •Writing a SerialDevice Class
- •Index
Chapter 1. Welcome to the Arduino • 10
All of these pins are connected to a microcontroller, which combines a CPU with some peripheral functions, such as IO channels. Many different types of microcontrollers are available, but the majority of Arduinos usually come with an ATmega328, an 8-bit microcontroller produced by a company named Atmel. Still there are Arduino models—for example, the Arduino Mega or the Arduino Due—that use more powerful microcontrollers.
Although modern computers load programs from a hard drive, microcontrollers usually have to be programmed. That means you have to load your software into the microcontroller via a cable, and once the program has been uploaded, it stays in the microcontroller until it gets overwritten with a new program. Whenever you supply power to the Arduino, the program currently stored in its microcontroller gets executed automatically. Sometimes you want the Arduino to start right from the beginning. With the reset button on the right side of the board, you can do that. If you press it, everything gets reinitialized, and the program stored in the microcontroller starts again. (We’ll use it in
First Version of a Binary Die, on page 45.)
On most Arduino boards you’ll also find a couple of LEDs. You’ll learn more about them in Hello, World!, on page 16.
Installing the Arduino IDE
To make it as easy as possible to get started with the Arduino, the developers have created a simple but useful integrated development environment (IDE). It runs on many different operating systems. Before you can create your first projects, you have to install it.
Important note: at the time of this writing, two different versions of the IDE are available (1.0.6 and 1.6.0).8 Chances are good that the 1.0.x branch of the Arduino IDE will no longer be maintained in the future. So, you should use 1.6.x where possible and use 1.0.x only if you need to use libraries that don’t work on 1.6.x yet. The following instructions refer to the 1.6.0 version.
Installing the Arduino IDE on Windows
The Arduino IDE runs on all the latest versions of Microsoft Windows, such as Windows 8.1 and Windows 7. The software comes in two flavors: as a Windows installer or as a self-contained zip archive. Check the Arduino’s download page9 for the latest version of either one.
8.There’s even one more for the Arduino Galileo at https://communities.intel.com/docs/DOC-22226.
9.http://arduino.cc/en/Main/Software
report erratum • discuss
Installing the Arduino IDE • 11
If you have administrative privileges on your machine, use the installer because it installs not only the IDE, but also all the drivers you need. In this case you usually don’t need anything else and can use the IDE right away.
If you don’t have administrative privileges, download the zip archive and extract it to a location of your choice. Before you first start the IDE, you must install drivers for the Arduino’s USB port. This process depends on the Arduino board you’re using and on your flavor of Windows.
Installing the Drivers for Current Arduino Boards
To install drivers for recent boards, such as the Arduino Uno, plug the Arduino into a USB port first to start the automatic driver installation process. This process will likely fail, and you’ll have to open the system Control Panel and start the Device Manager. (You can find it under System and Security.)10 In the
Ports (COM & LPT) section, you’ll probably find an entry named
Arduino Uno (COMxx).
If you can’t find that entry, search for Unknown Device in the
Other Devices menu—Figure 3,
Sometimes the Arduino isn't recognized, on page 12.
Right-click the entry belonging to the Arduino board and choose Update Driver Software. Select the Browse My Computer for Driver Software option. Go to the drivers folder of the archive you’ve extracted and select the arduino.inf file. (See Figure 4, The content of the drivers folder, on page 12.) In older versions of the IDE the file was named Arduino Uno.inf.
After you’ve installed the driver, you can start the Arduino IDE and work with the board. (If you’re running Windows 8.x, you have to disable some protection mechanisms before you install the driver.)11
10.http://windows.microsoft.com/en-us/windows/open-device-manager#1TC=windows-7
11.https://learn.sparkfun.com/tutorials/installing-arduino-ide/windows
report erratum • discuss
Chapter 1. Welcome to the Arduino • 12
Figure 3—Sometimes the Arduino isn’t recognized.
Figure 4—The content of the drivers folder
report erratum • discuss
Installing the Arduino IDE • 13
Installing the Drivers for Older Arduino Boards
Driver installation for older boards like the Duemilanove, Diecimila, or Nano is a bit different. Still, you have to plug in the board first.
On Windows Vista, driver installation usually happens automatically. Lean back and watch the hardware wizard’s messages pass by until it says you can use the newly installed USB hardware.
Windows 8.x, Windows 7, and Windows XP may not find the drivers on Microsoft’s update sites automatically. Sooner or later, the hardware wizard asks you for the path to the right drivers after you have told it to skip automatic driver installation from the Internet. Depending on your Arduino board, you have to point it to the right location in the Arduino installation directo- ry—that is the drivers/FTDI USB Drivers directory.
After the drivers have been installed, you can start the Arduino executable from the archive’s main directory by double-clicking it.
Please note that the USB drivers don’t change as often as the Arduino IDE. Whenever you install a new version of the IDE, check whether you have to install new drivers, too. Usually it isn’t necessary.
Installing the Arduino IDE on Mac OS X
The Arduino IDE is available as a zip file for Mac OS X.12 The IDE depends on the Java Virtual Machine, and at the time of this writing it’s available for Java 6 (recommended) and Java 7 (experimental). Download it, double-click it, and drag the Arduino icon to your Applications folder. If you hadn’t installed Java already, Mac OS X will ask you for permission to install it.
If you’re using an Arduino Uno or an Arduino Mega 2560, you are done and can start the IDE. Before you can use the IDE with an older Arduino, such as the Duemilanove, Diecimila, or Nano, you have to install drivers for the Arduino’s serial port. You can find the latest version online.13 Download the package for your platform (it usually has a name such as FTDIUSBSerialDriver_10_4_10_5_10_6.mpkg), double-click it, and follow the installation instructions on the screen.
When installing a new version of the Arduino IDE, you usually don’t have to install the drivers again (only when more recent drivers are available).
12.http://arduino.cc/en/Main/Software
13.http://www.ftdichip.com/Drivers/VCP.htm
report erratum • discuss