Cover by Michael Margolis

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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, shows nonprogrammers how to use common language constructs, and provides an overview of the language syntax for readers who are not familiar with C or C++, the language that Arduino uses.

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 Arduino IDE’s Serial Monitor so you can view Arduino’s output 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 ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required