Book description
Want to create devices that interact with the physical world? This cookbook is perfect for anyone who wants to experiment with the popular Arduino microcontroller and programming environment. You’ll find more than 200 tips and techniques for building a variety of objects and prototypes such as IoT solutions, environmental monitors, location and position-aware systems, and products that can respond to touch, sound, heat, and light.
Updated for the Arduino 1.8 release, the recipes in this third edition include practical examples and guidance to help you begin, expand, and enhance your projects right away—whether you’re an engineer, designer, artist, student, or hobbyist.
- Get up to speed on the Arduino board and essential software concepts quickly
- Learn basic techniques for reading digital and analog signals
- Use Arduino with a variety of popular input devices and sensors
- Drive visual displays, generate sound, and control several types of motors
- Connect Arduino to wired and wireless networks
- Learn techniques for handling time delays and time measurement
- Apply advanced coding and memory-handling techniques
Publisher resources
Table of contents
-
Preface
- Who This Book Is For
- How This Book Is Organized
- What Was Left Out
- Code Style (About the Code)
- Arduino Platform Release Notes
- Notes on the Third Edition
- Conventions Used in This Book
- Using Code Examples
- O’Reilly Online Learning
- How to Contact Us
- Acknowledgments for the Second Edition (Michael Margolis)
- Acknowledgments for the Third Edition (Brian Jepson)
-
Getting Started
- 1.0 Introduction
- 1.1 Installing the Integrated Development Environment (IDE)
- 1.2 Setting Up the Arduino Board
- 1.3 Using the Integrated Development Environment to Prepare an Arduino Sketch
- 1.4 Uploading and Running the Blink Sketch
- 1.5 Creating and Saving a Sketch
- 1.6 An Easy First Arduino Project
- 1.7 Using Arduino with Boards Not Included in the Standard Distribution
- 1.8 Using a 32-Bit Arduino (or Compatible)
-
Arduino Programming
- 2.0 Introduction
- 2.1 A Typical Arduino Sketch
- 2.2 Using Simple Primitive Types (Variables)
- 2.3 Using Floating-Point Numbers
- 2.4 Working with Groups of Values
- 2.5 Using Arduino String Functionality
- 2.6 Using C Character Strings
- 2.7 Splitting Comma-Separated Text into Groups
- 2.8 Converting a Number to a String
- 2.9 Converting a String to a Number
- 2.10 Structuring Your Code into Functional Blocks
- 2.11 Returning More than One Value from a Function
- 2.12 Taking Actions Based on Conditions
- 2.13 Repeating a Sequence of Statements
- 2.14 Repeating Statements with a Counter
- 2.15 Breaking Out of Loops
- 2.16 Taking a Variety of Actions Based on a Single Variable
- 2.17 Comparing Character and Numeric Values
- 2.18 Comparing Strings
- 2.19 Performing Logical Comparisons
- 2.20 Performing Bitwise Operations
- 2.21 Combining Operations and Assignment
-
Mathematical Operations
- 3.0 Introduction
- 3.1 Adding, Subtracting, Multiplying, and Dividing
- 3.2 Incrementing and Decrementing Values
- 3.3 Finding the Remainder After Dividing Two Values
- 3.4 Determining the Absolute Value
- 3.5 Constraining a Number to a Range of Values
- 3.6 Finding the Minimum or Maximum of Some Values
- 3.7 Raising a Number to a Power
- 3.8 Taking the Square Root
- 3.9 Rounding Floating-Point Numbers Up and Down
- 3.10 Using Trigonometric Functions
- 3.11 Generating Random Numbers
- 3.12 Setting and Reading Bits
- 3.13 Shifting Bits
- 3.14 Extracting High and Low Bytes in an int or long
- 3.15 Forming an int or long from High and Low Bytes
-
Serial Communications
- 4.0 Introduction
- 4.1 Sending Information from Arduino to Your Computer
- 4.2 Sending Formatted Text and Numeric Data from Arduino
- 4.3 Receiving Serial Data in Arduino
- 4.4 Sending Multiple Text Fields from Arduino in a Single Message
- 4.5 Receiving Multiple Text Fields in a Single Message in Arduino
- 4.6 Sending Binary Data from Arduino
- 4.7 Receiving Binary Data from Arduino on a Computer
- 4.8 Sending Binary Values from Processing to Arduino
- 4.9 Sending the Values of Multiple Arduino Pins
- 4.10 Logging Arduino Data to a File on Your Computer
- 4.11 Sending Data to More than One Serial Device
- 4.12 Receiving Serial Data from More than One Serial Device
- 4.13 Using Arduino with the Raspberry Pi
-
Simple Digital and Analog Input
- 5.0 Introduction
- 5.1 Using a Switch
- 5.2 Using a Switch Without External Resistors
- 5.3 Reliably Detect (Debounce) When a Switch Is Pressed
- 5.4 Determining How Long a Switch Is Pressed
- 5.5 Reading a Keypad
- 5.6 Reading Analog Values
- 5.7 Changing the Range of Values
- 5.8 Reading More than Six Analog Inputs
- 5.9 Measuring Voltages Up to 5V
- 5.10 Responding to Changes in Voltage
- 5.11 Measuring Voltages More than 5V (Voltage Dividers)
-
Getting Input from Sensors
- 6.0 Introduction
- 6.1 You Want an Arduino with Many Built-in Sensors
- 6.2 Detecting Movement
- 6.3 Detecting Light
- 6.4 Detecting Motion of Living Things
- 6.5 Measuring Distance
- 6.6 Measuring Distance Precisely
- 6.7 Detecting Vibration
- 6.8 Detecting Sound
- 6.9 Measuring Temperature
- 6.10 Reading RFID (NFC) Tags
- 6.11 Tracking Rotary Movement
- 6.12 Tracking Rotary Movement in a Busy Sketch with Interrupts
- 6.13 Using a Mouse
- 6.14 Getting Location from a GPS
- 6.15 Detecting Rotation Using a Gyroscope
- 6.16 Detecting Direction
- 6.17 Reading Acceleration
-
Visual Output
- 7.0 Introduction
- 7.1 Connecting and Using LEDs
- 7.2 Adjusting the Brightness of an LED
- 7.3 Driving High-Power LEDs
- 7.4 Adjusting the Color of an LED
- 7.5 Controlling Lots of Color LEDs
- 7.6 Sequencing Multiple LEDs: Creating a Bar Graph
- 7.7 Sequencing Multiple LEDs: Making a Chase Sequence
- 7.8 Controlling an LED Matrix Using Multiplexing
- 7.9 Displaying Images on an LED Matrix
- 7.10 Controlling a Matrix of LEDs: Charlieplexing
- 7.11 Driving a 7-Segment LED Display
- 7.12 Driving Multidigit, 7-Segment LED Displays: Multiplexing
- 7.13 Driving Multidigit, 7-Segment LED Displays with the Fewest Pins
- 7.14 Controlling an Array of LEDs by Using MAX72xx Shift Registers
- 7.15 Increasing the Number of Analog Outputs Using PWM Extender Chips
- 7.16 Using an Analog Panel Meter as a Display
-
Physical Output
- 8.0 Introduction
- 8.1 Controlling Rotational Position with a Servo
- 8.2 Controlling Servo Rotation with a Potentiometer or Sensor
- 8.3 Controlling the Speed of Continuous Rotation Servos
- 8.4 Controlling Servos Using Computer Commands
- 8.5 Driving a Brushless Motor (Using a Hobby Speed Controller)
- 8.6 Controlling Solenoids and Relays
- 8.7 Making an Object Vibrate
- 8.8 Driving a Brushed Motor Using a Transistor
- 8.9 Controlling the Direction of a Brushed Motor with an H-Bridge
- 8.10 Controlling the Direction and Speed of a Brushed Motor with an H-Bridge
- 8.11 Using Sensors to Control the Direction and Speed of Brushed Motors
- 8.12 Driving a Bipolar Stepper Motor
- 8.13 Driving a Bipolar Stepper Motor (Using the EasyDriver Board)
- 8.14 Driving a Unipolar Stepper Motor with the ULN2003A Driver Chip
- Audio Output
- Remotely Controlling External Devices
-
Using Displays
- 11.0 Introduction
- 11.1 Connecting and Using a Text LCD Display
- 11.2 Formatting Text
- 11.3 Turning the Cursor and Display On or Off
- 11.4 Scrolling Text
- 11.5 Displaying Special Symbols
- 11.6 Creating Custom Characters
- 11.7 Displaying Symbols Larger than a Single Character
- 11.8 Displaying Pixels Smaller than a Single Character
- 11.9 Selecting a Graphical LCD Display
- 11.10 Control a Full-Color LCD Display
- 11.11 Control a Monochrome OLED Display
- Using Time and Dates
- Communicating Using I2C and SPI
-
Simple Wireless Communication
- 14.0 Introduction
- 14.1 Sending Messages Using Low-Cost Wireless Modules
- 14.2 Connecting Arduino over a ZigBee or 802.15.4 Network
- 14.3 Sending a Message to a Particular XBee
- 14.4 Sending Sensor Data Between XBees
- 14.5 Activating an Actuator Connected to an XBee
- 14.6 Communicating with Classic Bluetooth Devices
- 14.7 Communicating with Bluetooth Low Energy Devices
-
WiFi and Ethernet
- 15.0 Introduction
- 15.1 Connecting to an Ethernet Network
- 15.2 Obtaining Your IP Address Automatically
- 15.3 Sending and Receiving Simple Messages (UDP)
- 15.4 Use an Arduino with Built-in WiFi
- 15.5 Connect to WiFi with Low-Cost Modules
- 15.6 Extracting Data from a Web Response
- 15.7 Requesting Data from a Web Server Using XML
- 15.8 Setting Up an Arduino to Be a Web Server
- 15.9 Handling Incoming Web Requests
- 15.10 Handling Incoming Requests for Specific Pages
- 15.11 Using HTML to Format Web Server Responses
- 15.12 Requesting Web Data Using Forms (POST)
- 15.13 Serving Web Pages Containing Large Amounts of Data
- 15.14 Sending Twitter Messages
- 15.15 Exchanging Data for the Internet of Things
- 15.16 Publishing Data to an MQTT Broker
- 15.17 Subscribing to Data on an MQTT Broker
- 15.18 Getting the Time from an Internet Time Server
- Using, Modifying, and Creating Libraries
-
Advanced Coding and Memory Handling
- 17.0 Introduction
- 17.1 Understanding the Arduino Build Process
- 17.2 Determining the Amount of Free and Used RAM
- 17.3 Storing and Retrieving Numeric Values in Program Memory
- 17.4 Storing and Retrieving Strings in Program Memory
- 17.5 Using #define and const Instead of Integers
- 17.6 Using Conditional Compilations
-
Using the Controller Chip Hardware
- 18.0 Introduction
- 18.1 Storing Data in Permanent EEPROM Memory
- 18.2 Take Action Automatically When a Pin State Changes
- 18.3 Perform Periodic Actions
- 18.4 Setting Timer Pulse Width and Duration
- 18.5 Creating a Pulse Generator
- 18.6 Changing a Timer’s PWM Frequency
- 18.7 Counting Pulses
- 18.8 Measuring Pulses More Accurately
- 18.9 Measuring Analog Values Quickly
- 18.10 Reducing Battery Drain
- 18.11 Setting Digital Pins Quickly
- 18.12 Uploading Sketches Using a Programmer
- 18.13 Replacing the Arduino Bootloader
- 18.14 Move the Mouse Cursor on a PC or Mac
- Electronic Components
- Using Schematic Diagrams and Datasheets
- Building and Connecting the Circuit
- Tips on Troubleshooting Software Problems
- Tips on Troubleshooting Hardware Problems
- Digital and Analog Pins
- ASCII and Extended Character Sets
- Index
- About the Authors
Product information
- Title: Arduino Cookbook, 3rd Edition
- Author(s):
- Release date: April 2020
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491903520
You might also like
book
Exploring Arduino, 2nd Edition
The bestselling beginner Arduino guide, updated with new projects! Exploring Arduino makes electrical engineering and embedded …
book
Getting Started With Arduino, 4th Edition
Arduino is the open source electronics prototyping platform that has taken the Maker Movement by storm. …
book
Raspberry Pi Cookbook, 3rd Edition
With millions of new users and several new models, the Raspberry Pi ecosystem continues to expand—along …
book
Raspberry Pi Cookbook, 4th Edition
If you've started to work with Raspberry Pi, you know that Raspberry Pi's capabilities are continually …