Chapter 2. Making the Sketch Do Your Bidding

2.0. Introduction

Though much of an Arduino project will involve integrating the Arduino board with supporting hardware, you need to be able to tell the board what to do with the rest of your project. This chapter introduces core elements of Arduino programming, showing nonprogrammers how to use common language constructs and providing an overview of the language syntax for readers who are not familiar with C or C++, the language being used.

Since making the examples interesting requires making Arduino do something, the recipes use physical capabilities of the board that are explained in detail in later chapters. If any of the code in this chapter is not clear, feel free to jump forward, particularly to Chapter 4 for more on serial output and Chapter 5 for more on using digital and analog pins. You don’t need to understand all the code in the examples, though, to see how to perform the specific capabilities that are the focus of the recipes. Here are some of the more common functions used in the examples that are covered in the next few chapters:

Serial.println(value);

Prints the value to the Serial Monitor on your computer; see Recipe 4.1

pinMode(pin, mode);

Configures a digital pin to read (input) or write (output) a digital value; see the introduction to Chapter 5

digitalRead(pin);

Reads a digital value (HIGH or LOW) on a pin set for input; see Recipe 5.1

digitalWrite(pin, value);

Writes the digital value (HIGH or LOW) to a pin set for output; ...

Get Arduino Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.