Introduction - Sams Teach Yourself Arduino Programming in 24 Hours (2015)

Sams Teach Yourself Arduino Programming in 24 Hours (2015)

Introduction

Since being introduced in 2005 as a student project, the Arduino microcontroller has quickly become a favorite of both hobbyists and professionals. It’s a popular platform for creating many different types of automated systems—from monitoring water levels in house plants to controlling high-level robotic systems. These days you can find an Arduino behind lots of different electronic systems.

To control the Arduino, you need to know the Arduino programming language. The Arduino programming language derives from the C programming language, with some added features unique to the Arduino environment. However, beginners sometimes find the C programming somewhat tricky to navigate.

Programming the Arduino

The goal of this book is to help guide both hobbyists and students through using the Arduino programming language on an Arduino system. You don’t need any programming experience to benefit from this book; I walk through all the necessary steps to get your Arduino programs up and running.

Image Part I, “The Arduino Programming Environment,” starts things out by walking through the core Arduino system and demonstrating the process of creating an Arduino program (called a sketch):

Hour 1, “Introduction to the Arduino,” shows the different Arduino models currently available and describes how each differs.

Hour 2, “Creating an Arduino Programming Environment,” shows how to load the Arduino IDE on a workstation and how to connect your Arduino to your workstation to get your sketches running on your Arduino.

Hour 3, “Using the Arduino IDE,” walks through all the features available to you in the IDE.

Hour 4, “Creating an Arduino Program,” demonstrates the steps to build an Arduino circuit, design a sketch to control the circuit, and upload the sketch to the Arduino to run the circuit.

Image Part II, “The C Programming Language,” takes an in-depth look at the features of the C programming language that you need to know to write your Arduino sketches:

Hour 5, “Learning the Basics of C,” shows you how to use variables and math operators in C to manage data and implement formulas in your Arduino sketches.

Hour 6, “Structured Commands,” shows how to add logic to your sketches.

Hour 7, “Programming Loops,” demonstrates the different ways the Arduino language allows you to iterate through data, minimizing the amount of code you need to write.

Hour 8, “Working with Strings,” introduces the concept of storing and working with text values in your Arduino sketches.

Hour 9, “Implementing Data Structures,” walks through more complicated ways of handling data in sketches.

Hour 10, “Creating Functions,” provides useful tips to help minimize the amount of repeating code in your sketches.

Hour 11, “Pointing to Data,” introduces the complex topic of using pointers in the C language and shows how you can leverage their use in your sketches.

Hour 12, “Storing Data,” walks you through how to use the EEPROM storage available in the Arduino to store data between sketch runs.

Hour 13, “Using Libraries,” finishes the in-depth C language discussion by showing how to use prebuilt libraries in your sketches and how to create your own.

Image Part III, “Arduino Applications,” walks through the details for using your Arduino in different application environments:

Hour 14, “Working with Digital Interfaces,” shows how to read digital sensor values and use those values in your sketch and how to output digital values.

Hour 15, “Interfacing with Analog Devices,” shows how to read analog sensor values and how to use pulse width modulation to emulate an analog output voltage.

Hour 16, “Adding Interrupts,” demonstrates how to use asynchronous programming techniques in your Arduino sketches while monitoring sensors.

Hour 17, “Communicating with Devices,” covers the different communications protocols built in to the Arduino, including SPI and I2C.

Hour 18, “Using Sensors,” takes a closer look at the different types of analog and digital sensors the Arduino supports and how to handle them in your sketches.

Hour 19, “Working with Motors,” walks through how to control different types of motors from your Arduino sketch.

Hour 20, “Using an LCD,” provides instructions on how to utilize digital displays to output data from your sketch.

Hour 21, “Working with the Ethernet Shield,” discusses how to connect your Arduino to a network.

Hour 22, “Implementing Advanced Ethernet Programs,” demonstrates how to provide sensor data to remote network clients and how to control the Arduino from a remote client.

Hour 23, “Handling Files,” shows how to use SD card interfaces found on some Arduino shields to store data for long term.

Hour 24, “Prototyping Projects,” walks you through the process of creating a complete Arduino project, from design to implementation.

Who Should Read This Book?

This book is aimed at readers interested in getting the most out of their Arduino system by writing their own Arduino sketches, including these three groups:

Image Students interested in an inexpensive way to learn electronics and programming

Image Hobbyists interested in monitoring and controlling digital or analog circuits

Image Professionals looking for an inexpensive platform to use for application deployment

If you are reading this book, you are not necessarily new to programming, but you may be new to the Arduino environment and need a quick reference guide.

Conventions Used in This Book

To make your life easier, this book includes various features and conventions that help you get the most out of this book and out of your Arduino:

Steps—Throughout the book, I’ve broken many coding tasks into easy-to-follow step-by-step procedures.

Things you type—Whenever I suggest that you type something, what you type appears in a bold font.

Filenames, folder names, and code—These things appear in a monospace font.

Commands—Commands and their syntax use bold.

Menu commands—I use the following style for all application menu commands: Menu, Command, where Menu is the name of the menu you pull down and Command is the name of the command you select. Here’s an example: File, Open. This means you select the File menu and then select the Open command.

This book also uses the following boxes to draw your attention to important or interesting information:


By The Way

By the Way boxes present asides that give you more information about the current topic. These tidbits provide extra insights that offer better understanding of the task.



Did You Know?

Did You Know? boxes call your attention to suggestions, solutions, or shortcuts that are often hidden, undocumented, or just extra useful.



Watch Out!

Watch Out! boxes provide cautions or warnings about actions or mistakes that bring about data loss or other serious consequences.