INTRODUCTION

Arduino interface boards provide a low-cost, easy-to-use technology to create microcontroller-based projects. With a little electronics, you can make your Arduino do all sorts of things, from controlling lights in an art installation to managing the power on a solar energy system.

There are many project-based books that show you how to connect things to your Arduino, including 30 Arduino Projects for the Evil Genius by this author. However, the focus of this book is on programming the Arduino.

This book will explain how to make programming the Arduino simple and enjoyable, avoiding the difficulties of uncooperative code that so often afflict a project. You will be taken through the process of programming the Arduino step by step, starting with the basics of the C programming language that Arduinos use.


So, What Is Arduino?

Arduino is a small microcontroller board with a universal serial bus (USB) plug to connect to your computer and a number of connection sockets that can be wired to external electronics such as motors, relays, light sensors, laser diodes, loudspeakers, microphones, and more. They can be powered either through the USB connection from the computer, from a 9V battery, or from a power supply. They can be controlled from the computer or programmed by the computer and then disconnected and allowed to work independently.

The board design is open source. This means that anyone is allowed to make Arduino-compatible boards. This competition has led to low costs for the boards and all sorts of variations on the “standard” boards.

The basic boards are supplemented by accessory shield boards that can be plugged on top of the Arduino board.

The software for programming your Arduino is easy to use and also freely available for Windows, Mac, and Linux computers.


What Will I Need?

This is a book intended for beginners, but it is also intended to be useful to those who have used Arduino for a while and want to learn more about programming the Arduino or gain a better understanding of the fundamentals. As such, this book concentrates on the use of the Arduino Uno board; however, almost all of the code will work unmodified on all the Arduino models and variants.

You do not need to have any programming experience or a technical background, and the book’s exercises do not require any soldering. All you need is the desire to make something.

If you want to make the most of the book and try out some of the experiments, then it is useful to have the following on hand:

♦ A few lengths of solid core wire

♦ A cheap digital multimeter

Both are readily available for a few dollars from a hobby electronics store or online retailer such as Adafruit or Sparkfun. You will of course also need an Arduino Uno board.

If you want to go a step further and experiment with displays and network connections, then you will need to buy shields that are available from online stores. See Chapters 9 and 10 for details.


Using This Book

This book is structured to get you started in a really simple way and gradually build on what you have learned. You may, however, find yourself skipping or skimming some of the early chapters as you find the right level to enter the book.

The book is organized into the following chapters:

Chapter 1: This Is Arduino An introduction to the Arduino hardware, this chapter describes what it is capable of and the various types of Arduino boards that are available.

Chapter 2: Getting Started Here you conduct your first experiments with your Arduino board: installing the software, powering it up, and uploading your first sketch.

Chapter 3: C Language Basics This chapter covers the basics of the C language; for complete programming beginners, the chapter also serves as an introduction to programming in general.

Chapter 4: Functions This chapter explains the key concept of using and writing functions in Arduino sketches. These sketches are demonstrated throughout with runnable code examples.

Chapter 5: Arrays and Strings Here you learn how to make and use data structures that are more advanced than simple integer variables. A Morse code example project is slowly developed to illustrate the concepts being explained.

Chapter 6: Input and Output You learn how to use the digital and analog inputs and outputs on the Arduino in your programs. A multimeter will be useful to show you what is happening on the Arduino’s input/output connections.

Chapter 7: The Standard Arduino Library This chapter explains how to make use of the standard Arduino functions that come in the Arduino’s standard library.

Chapter 8: Data Storage Here you learn how to write sketches that can save data in electrically erasable read-only memory (EEPROM) and make use of the Arduino’s built-in flash memory.

Chapter 9: Displays In this chapter, you learn how to interface an Arduino with displays and to make a simple USB message board.

Chapter 10: Arduino Internet of Things Programming You learn how to make the Arduino behave like a Web server and communicate with the Internet using services such as dweet and IFTTT.

Chapter 11: C++ and Libraries You go beyond C, looking at adding object orientation and writing your own Arduino libraries.


Resources

This book is supported by an accompanying website:

www.arduinobook.com

There you will find all the source code used in this book as well as other resources, such as errata.