100% found this document useful (5 votes)
104 views

PDF Exploring Arduino: Tools and Techniques For Engineering Wizardry Jeremy Blum Download

Exploring

Uploaded by

tsibesbelezi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
104 views

PDF Exploring Arduino: Tools and Techniques For Engineering Wizardry Jeremy Blum Download

Exploring

Uploaded by

tsibesbelezi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Download the full version of the textbook now at textbookfull.

com

Exploring Arduino: Tools and Techniques for


Engineering Wizardry Jeremy Blum

https://textbookfull.com/product/exploring-
arduino-tools-and-techniques-for-engineering-
wizardry-jeremy-blum/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Exploring BeagleBone Tools and Techniques for Building


with Embedded Linux 2nd Edition Derek Molloy

https://textbookfull.com/product/exploring-beaglebone-tools-and-
techniques-for-building-with-embedded-linux-2nd-edition-derek-molloy/

textbookfull.com

Coulson and Richardson’s Chemical Engineering, Fourth


Edition: Volume 3A: Chemical and Biochemical Reactors and
Reaction Engineering R. Ravi
https://textbookfull.com/product/coulson-and-richardsons-chemical-
engineering-fourth-edition-volume-3a-chemical-and-biochemical-
reactors-and-reaction-engineering-r-ravi/
textbookfull.com

Building Arduino PLCs: The essential techniques you need


to develop Arduino-based PLCs 1st Edition Pradeeka
Seneviratne (Auth.)
https://textbookfull.com/product/building-arduino-plcs-the-essential-
techniques-you-need-to-develop-arduino-based-plcs-1st-edition-
pradeeka-seneviratne-auth/
textbookfull.com

Ruin Me Twin Falls Academy 1 1st Edition Angel James Arlo


Arrow James Angel

https://textbookfull.com/product/ruin-me-twin-falls-academy-1-1st-
edition-angel-james-arlo-arrow-james-angel/

textbookfull.com
The Centre of City Wind Environment and Spatial Morphology
Junyan Yang

https://textbookfull.com/product/the-centre-of-city-wind-environment-
and-spatial-morphology-junyan-yang/

textbookfull.com

Foundations of Economic Psychology A Behavioral and


Mathematical Approach Kazuhisa Takemura

https://textbookfull.com/product/foundations-of-economic-psychology-a-
behavioral-and-mathematical-approach-kazuhisa-takemura/

textbookfull.com

Analysis and Synthesis of Compliant Parallel Mechanisms


Screw Theory Approach Chen Qiu

https://textbookfull.com/product/analysis-and-synthesis-of-compliant-
parallel-mechanisms-screw-theory-approach-chen-qiu/

textbookfull.com

The Ultimate Keto Air Fryer Cookbook 100 Low Carb High Fat
Recipes 1st Edition Wendy Polisi

https://textbookfull.com/product/the-ultimate-keto-air-fryer-
cookbook-100-low-carb-high-fat-recipes-1st-edition-wendy-polisi/

textbookfull.com

Big Data Analytics with Java 1st Edition Rajat Mehta

https://textbookfull.com/product/big-data-analytics-with-java-1st-
edition-rajat-mehta/

textbookfull.com
Homestyle Vietnamese Cooking Nongkran Daks

https://textbookfull.com/product/homestyle-vietnamese-cooking-
nongkran-daks/

textbookfull.com
EXPLORING
ARDUINO ®
EXPLORING
ARDUINO ®

Tools and Techniques


for Engineering
Wizardry
Second Edition
Jeremy Blum
Exploring Arduino®: Tools and Techniques for Engineering Wizardry
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2020 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-119-40537-5
ISBN: 978-1-119-40535-1 (ebk)
ISBN: 978-1-119-40530-6 (ebk)
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108
of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization
through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-
6008, or online at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties
with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties,
including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended
by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation.
This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other
professional services. If professional assistance is required, the services of a competent professional person should be
sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization
or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that
the author or the publisher endorses the information the organization or website may provide or recommendations
it may make. Further, readers should be aware that Internet websites listed in this work may have changed or
disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the
United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with
standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media
such as a CD or DVD that is not included in the version you purchased, you may download this material at http://
booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2019948860
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or
its affiliates, in the United States and other countries, and may not be used without written permission. Arduino is a
registered trademark of Arduino AG Corporation. All other trademarks are the property of their respective owners.
John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
To Leah, for helping me to see every
challenge as an opportunity.
About the Author
J eremy Blum is currently the director of engineering at Shaper (shapertools.com),
where he is using computer vision to reinvent the way people use handheld power
tools. Prior to joining Shaper, Jeremy was a lead electrical architect/engineer for con-
fidential products at Google [x], including Google Glass.
Jeremy received his master’s and bachelor’s degrees in Electrical and Computer Engi-
neering from Cornell University. At Cornell, he co-founded and led Cornell University
Sustainable Design, he launched a first-of-its-kind entrepreneurial co-working space
for students, and he conducted robotics and machine learning research.
Jeremy has designed prosthetic hands, fiber-optic LED lighting systems, home-­
automation systems, 3D printers and scanners, self-assembling robots, wearable
­computing platforms, augmented reality devices, and learning robots. His work has
been featured in international conferences, peer-reviewed journals, and popular media
outlets such as Discovery Channel, the Wall Street Journal, and Popular Science maga-
zine. Forbes magazine named him to their annual “30 Under 30” list in recognition of
his work that has "helped America make things and get stuff done." He is the co-author
of several patents in the fields of wearable computing and augmented reality fabrication.
When not building products, Jeremy is teaching. His written and video tutorials
have been utilized by millions of people to learn electrical engineering and embedded
software design. His book, Exploring Arduino, has been translated into multiple lan-
guages and is used as an engineering textbook around the world, including at his alma
mater, Cornell. Jeremy’s passion is using engineering to improve people’s lives, and
giving people the tools they need to do the same. You can learn more about Jeremy at
his website, jeremyblum.com.

About the Technical Editor


D r. Derek Molloy is an associate professor in the Faculty of Engineering and Com-
puting’s School of Electronic Engineering at Dublin City University, Ireland. He
lectures at undergraduate and postgraduate levels in object-oriented programming with
embedded systems, digital and analog electronics, and connected embedded systems.
His research contributions have largely been in the fields of computer and machine
vision, embedded systems, 3D graphics/visualization, and e-learning. Derek produces
viii About the Technical Editor

a popular YouTube video series that has introduced millions of people to embedded
Linux and digital electronics topics. In 2013, he launched a personal web/blog site that
is visited by thousands of people every day and that integrates his YouTube videos with
support materials, source code, and user discussion. He has published other books in
this Wiley mini-series: Exploring BeagleBone in 2015, followed in 2016 by Exploring
Raspberry Pi. The second edition of Exploring BeagleBone was released earlier this year.
You can learn more about Derek, his work, and his other publications at his personal
website, derekmolloy.ie.
Acknowledgments
I n the several years since the first edition of this book was released, I’ve received
so many notes from readers who have told me about the many ways that they’ve
learned from Exploring Arduino. I’ve also received plenty of constructive criticism—
little things that I can adjust to improve the book’s utility. I’ve taken all these comments
to heart and have tracked them carefully over the past few years. It is my intention to
make this second edition even more useful than the first, while still maintaining the
approachability that many readers told me that they appreciated. So, THANK YOU
to everybody who has given me feedback about the first edition of Exploring Arduino!
Second, I must extend my thanks again to Wiley. They’ve been amazing partners
through this journey, and I’m glad to have them to continue to see this book through
to a second edition. In particular, I’d like to thank Jim Minatel, Adaobi Obi Tulton, Dr.
Derek Molloy, Marylouise Wiack, and Athiyappan Lalith Kumar.
Thanks also to the wonderful folks at Adafruit, who have collaborated with me on
ensuring that parts kits are easy to obtain for this book. Adafruit contributes heavily
to the open source hardware and software communities, and I certainly would not be
the engineer that I am today without their excellent products and guides.
Back when I wrote the first edition of Exploring Arduino, I was still getting my mas-
ter’s degree. I’ve long since graduated, but now I’ve got my work at Shaper to focus on.
I owe a big thanks to all my co-workers both at Shaper and at Google (my previous
employer) for always encouraging me, and for building awesome hardware with me!
I want to give a special shout-out to my professors at Cornell, especially Professor
François Guimbretière, who taught the course where I was first introduced to Arduino.
He has since used the first edition of this book as a textbook for that course, and it
makes me so happy to know that I’ve been able to give back to Cornell in that capacity.
Finally, I want to thank my parents, my brother, my wife, and my friends for putting
up with me, and for always encouraging me. I feel so fortunate to have such wonderful
people in my life.
Contents at a Glance
Introduction ���������������������������������������������������������������������������������������������������� xxv

PART I Arduino Engineering Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  1


1 Getting Started and Understanding the Arduino Landscape. . . . . . . . . . . . 3

2 Digital Inputs, Outputs, and Pulse-Width Modulation. . . . . . . . . . . . . . . . . 23

3 Interfacing with Analog Sensors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

PART II Interfacing with Your Environment. . . . . . . . . . . . . . . . . . . . . . . . .  67


4 Using Transistors and Driving DC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

5 Driving Stepper and Servo Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

6 Making Sounds and Music . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

7 USB Serial Communication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

8 Emulating USB Devices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

9 Shift Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

PART III Communication Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  199


10 The I2C Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
11 The SPI Bus and Third-Party Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
12 Interfacing with Liquid Crystal Displays. . . . . . . . . . . . . . . . . . . . . . . . . . . . 247

PART IV Digging Deeper and Combining Functions. . . . . . . . . . . . . . . . .  273


13 Interrupts and Other Special Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
14 Data Logging with SD Cards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
xii Contents at a Glance

PART V Going Wireless. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  337


15 Wireless RF Communications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
16 Bluetooth Connectivity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
17 Wi-Fi and the Cloud. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Appendix A: Deciphering Datasheets and Schematics. . . . . . . . . . . . . . . . 451

Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  461
Contents
Introduction ���������������������������������������������������������������������������������������������������� xxv

PART I Arduino Engineering Basics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  1


1 Getting Started and Understanding the Arduino Landscape. . . . . . . . . . . . 3
Exploring the Arduino Ecosystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  4
Arduino Functionality. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  5
The Microcontroller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  7
Programming Interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  8
Input/Output: GPIO, ADCs, and Communication Busses. . . . . . . . . . . . . . . . .  9
Power. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  9
Arduino Boards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  11
Creating Your First Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  15
Downloading and Installing the Arduino IDE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  16
Running the IDE and Connecting to the Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . .  17
Breaking Down Your First Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  18
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  21

2 Digital Inputs, Outputs, and Pulse-Width Modulation. . . . . . . . . . . . . . . . . 23


Digital Outputs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Wiring Up an LED and Using Breadboards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Working with Breadboards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  24
Wiring LEDs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Programming Digital Outputs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  29
Using For Loops. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Pulse-Width Modulation with analogWrite().. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Reading Digital Inputs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Reading Digital Inputs with Pull-Down Resistors . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Working with “Bouncy” Buttons. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Building a Controllable RGB LED Nightlight. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  42
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
xiv Contents

3 Interfacing with Analog Sensors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47


Understanding Analog and Digital Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Comparing Analog and Digital Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Converting an Analog Signal to Digital. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Reading Analog Sensors with the Arduino: analogRead(). . . . . . . . . . . . . . . . . . . . . . . . 51
Reading a Potentiometer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  51
Using Analog Sensors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Using Variable Resistors to Make Your Own Analog Sensors. . . . . . . . . . . . . . . . . . . . 60
Using Resistive Voltage Dividers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  61
Using Analog Inputs to Control Analog Outputs. . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

PART II Interfacing with Your Environment. . . . . . . . . . . . . . . . . . . . . . . . .  67


4 Using Transistors and Driving DC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Driving DC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Handling High-Current Inductive Loads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  71
Using Transistors as Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Using Protection Diodes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Using a Secondary Power Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  74
Wiring the Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  74
Controlling Motor Speed with PWM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  76
Using an H-Bridge to Control DC Motor Direction. . . . . . . . . . . . . . . . . . . . . . . . . .  78
Building an H-Bridge Circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Operating an H-Bridge Circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Building a Roving Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Choosing the Robot Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Selecting a Motor and Gearbox. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Powering Your Robot. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Constructing the Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Writing the Robot Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  92
Bringing It Together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  97
Contents xv

5 Driving Stepper and Servo Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99


Driving Servo Motors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Understanding the Difference between Continuous Rotation and
Standard Servos. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  100
Understanding Servo Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Controlling a Servo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Building a Sweeping Distance Sensor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  105
Understanding and Driving Stepper Motors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
How Bipolar Stepper Motors Work. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  111
Making Your Stepper Move. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  113
Building a “One-Minute Chronograph”. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  117
Wiring and Building the Chronograph. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  117
Programming the Chronograph. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  119
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  124

6 Making Sounds and Music . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125


Understanding How Speakers Work. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  126
The Properties of Sound. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  126
How a Speaker Produces Sound. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Using tone() to Make Sounds. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  129
Including a Definition File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  129
Wiring the Speaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Making Sound Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Using Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Making Note and Duration Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  134
Completing the Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  134
Understanding the Limitations of the tone() Function. . . . . . . . . . . . . . . . . . . . . 136
Building a Micro Piano. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  139

7 USB Serial Communication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141


Understanding the Arduino’s Serial Communication Capabilities. . . . . . . . . . . . . . .  142
Arduino Boards with an Internal or External FTDI or Silicon
Labs USB-to-Serial Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
xvi Contents

Arduino Boards with a Secondary USB-Capable ATmega MCU


Emulating a Serial Converter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  146
Arduino Boards with a Single USB-Capable MCU . . . . . . . . . . . . . . . . . . . . . . . . .  147
Arduino Boards with USB-Host Capabilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  147
Listening to the Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Using print Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Using Special Characters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Changing Data Type Representations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  152
Talking to the Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Configuring the Arduino IDE’s Serial Monitor to Send Command Strings . . . .  152
Reading Incoming Data from a Computer or Other Serial Device. . . . . . . . . . . 153
Telling the Arduino to Echo Incoming Data. . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Understanding the Differences between Chars and Ints. . . . . . . . . . . . . . . 154
Sending Single Characters to Control an LED. . . . . . . . . . . . . . . . . . . . . . . . . 156
Sending Lists of Values to Control an RGB LED. . . . . . . . . . . . . . . . . . . . . . . . 158
Talking to a Desktop App. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  161
Installing Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  162
Controlling a Processing Sketch from Your Arduino. . . . . . . . . . . . . . . . . . . . . . . 163
Sending Data from Processing to Your Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  169

8 Emulating USB Devices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171


Emulating a Keyboard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Typing Data into the Computer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  173
Commanding Your Computer to Do Your Bidding. . . . . . . . . . . . . . . . . . . . . . . . .  177
Emulating a Mouse. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  178
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

9 Shift Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183


Understanding Shift Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Sending Parallel and Serial Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Working with the 74HC595 Shift Register. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Understanding the Shift Register pin Functions . . . . . . . . . . . . . . . . . . . . . . 186
Understanding How the Shift Register Works . . . . . . . . . . . . . . . . . . . . . . . . 187
Contents xvii

Shifting Serial Data from the Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189


Converting Between Binary and Decimal Formats. . . . . . . . . . . . . . . . . . . . . . . .  192
Controlling Light Animations with a Shift Register. . . . . . . . . . . . . . . . . . . . . . . . . . . .  192
Building a “Light Rider”. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  192
Responding to Inputs with an LED Bar Graph. . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  197

PART III Communication Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  199


10 The I2C Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
History of the I2C Bus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
I2C Hardware Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Communication Scheme and ID Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Hardware Requirements and Pull-Up Resistors. . . . . . . . . . . . . . . . . . . . . . . . . . .  206
Communicating with an I2C Temperature Probe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Setting Up the Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Referencing the Datasheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  210
Writing the Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  212
Combining Shift Registers, Serial Communication, and I2C Communications. . . . .  214
Building the Hardware for a Temperature Monitoring System. . . . . . . . . . . . . .  214
Modifying the Embedded Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  215
Writing the Processing Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  218
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

11 The SPI Bus and Third-Party Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223


Overview of the SPI Bus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  224
SPI Hardware and Communication Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Hardware Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .225
Communication Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Comparing SPI to I2C and UART. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Communicating with an SPI Accelerometer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
What Is an Accelerometer?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  229
Gathering Information from the Datasheet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Setting Up the Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
xviii Contents

Writing the Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  235


Installing the Adafruit Sensor Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Leveraging the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Creating an Audiovisual Instrument Using a 3-Axis Accelerometer. . . . . . . . . . . . . 241
Setting Up the Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Modifying the Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246

12 Interfacing with Liquid Crystal Displays. . . . . . . . . . . . . . . . . . . . . . . . . . . . 247


Setting Up the LCD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Using the LiquidCrystal Library to Write to the LCD. . . . . . . . . . . . . . . . . . . . . . . . . . .  251
Adding Text to the Display. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Creating Special Characters and Animations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Building a Personal Thermostat. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Setting Up the Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Displaying Data on the LCD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  261
Adjusting the Set Point with a Button. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Adding an Audible Warning and a Fan. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  265
Bringing It All Together: The Complete Program. . . . . . . . . . . . . . . . . . . . . . . . . .  266
Taking This Project to the Next Level. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271

PART IV Digging Deeper and Combining Functions. . . . . . . . . . . . . . . . .  273


13 Interrupts and Other Special Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Using Hardware Interrupts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  276
Knowing the Tradeoffs Between Polling and Interrupting . . . . . . . . . . . . . . . . . 277
Ease of Implementation (Software). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  277
Ease of Implementation (Hardware). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Multitasking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  278
Acquisition Accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Understanding the Arduino Hardware Interrupt Capabilities. . . . . . . . . . . . . . .278
Contents xix

Building and Testing a Hardware-Debounced Button Interrupt Circuit. . . . . . 279


Creating a Hardware-Debouncing Circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Assembling the Complete Test Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Writing the Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Using Timer Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Understanding Timer Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Getting the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Executing Two Tasks Simultaneously(ish). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Building an Interrupt-Driven Sound Machine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Sound Machine Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Sound Machine Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294

14 Data Logging with SD Cards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295


Getting Ready for Data Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Formatting Data with CSV Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  297
Preparing an SD Card for Data Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Formatting Your SD Card Using a Windows PC. . . . . . . . . . . . . . . . . . . . . . . .  298
Formatting Your SD Card Using Mac OS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Formatting Your SD Card Using Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Interfacing the Arduino with an SD Card. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
SD Card Shields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
SD Card SPI Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Writing to an SD Card. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Reading from an SD Card. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  312
Real-Time Clocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  317
Understanding Real-Time Clocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  317
Communicating with a Real-Time Clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  317
Using the RTC Arduino Third-Party Library. . . . . . . . . . . . . . . . . . . . . . . . . . .  318
Using a Real-Time Clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  319
Installing the RTC and SD Card Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . .  319
Updating the Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
xx Contents

Building an Entrance Logger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327


Logger Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  328
Logger Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Data Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335

PART V Going Wireless. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  337


15 Wireless RF Communications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
The Electromagnetic Spectrum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
The Spectrum. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
How Your RF Link Will Send and Receive Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Receiving Key Presses with the RF Link. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Connecting Your Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Programming Your Receiver. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Making a Wireless Doorbell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Wiring the Receiver. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Programming the Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
The Start of Your Smart Home—Controlling a Lamp. . . . . . . . . . . . . . . . . . . . . . . . . . 354
Your Home’s AC Power. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
How a Relay Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Programming the Relay Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Hooking up Your Lamp and Relay to the Arduino. . . . . . . . . . . . . . . . . . . . . . . . . 360
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361

16 Bluetooth Connectivity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363


Demystifying Bluetooth. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Bluetooth Standards and Versions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Bluetooth Profiles and BTLE GATT Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Communication between Your Arduino and Your Phone. . . . . . . . . . . . . . . . . . . . . . 366
Reading a Sensor over BTLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Adding Support for Third-Party Boards to the Arduino IDE. . . . . . . . . . . . . 367
Installing the BTLE Module Library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Programming the Feather Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Contents xxi

Connecting Your Smartphone to Your BTLE Transmitter . . . . . . . . . . . . . . . 377


Sending Commands from Your Phone over BTLE. . . . . . . . . . . . . . . . . . . . . . . . . 379
Parsing Command Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Commanding Your BTLE Device with Natural Language. . . . . . . . . . . . . . . . 384
Controlling an AC Lamp with Bluetooth. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
How Your Phone “Pairs” to BTLE Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Writing the Proximity Control Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Pairing Your Phone. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Pairing an Android Phone. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Pairing an iPhone. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Make Your Lamp React to Your Presence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397

17 Wi-Fi and the Cloud. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399


The Web, the Arduino, and You . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
Networking Lingo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
The Internet vs. the World Wide Web vs. the Cloud. . . . . . . . . . . . . . . . . . . .  401
IP Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Network Address Translation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
MAC Address. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
HTML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  402
HTTP and HTTPS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
GET/POST. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
DHCP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
DNS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
Clients and Servers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
Your Wi-Fi–Enabled Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Controlling Your Arduino from the Web. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Setting Up the I/O Control Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .404
Preparing the Arduino IDE for Use with the Feather Board. . . . . . . . . . . . . . . . .406
Ensuring the Wi-Fi Library Is Matched to the Wi-Fi Module’s Firmware . . . . . . 407
Checking the WINC1500’s Firmware Version. . . . . . . . . . . . . . . . . . . . . . . . . . 408
Updating the WINC1500’s Firmware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
xxii Contents

Writing an Arduino Server Sketch. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408


Connecting to the Network and Retrieving an IP Address via DHCP . . . . . 409
Writing the Code for a Bare-Minimum Web Server. . . . . . . . . . . . . . . . . . . .  412
Controlling Your Arduino from Inside and Outside Your Local Network. . . . . .  423
Controlling Your Arduino over the Local Network. . . . . . . . . . . . . . . . . . . . . 423
Using Port Forwarding to Control Your Arduino from Anywhere. . . . . . . . 425
Interfacing with Web APIs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  427
Using a Weather API. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Creating an Account with the API Service Provider. . . . . . . . . . . . . . . . . . . . 429
Understanding How APIs Are Structured . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
JSON-Formatted Data and Your Arduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Fetching and Parsing Weather Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Getting the Local Temperature from the Web on Your Arduino . . . . . . . . . 433
Completing the Live Temperature Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Wiring up the LED Readout Display. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Driving the Display with Temperature Data . . . . . . . . . . . . . . . . . . . . . . . . . . 443
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449

Appendix A: Deciphering Datasheets and Schematics. . . . . . . . . . . . . . . . 451

Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  461
Figure Credits
A ll images, icons, and marks as displayed in Figure 3-7 and Figure 10-3 are owned
by Analog Devices, Inc. (ADI), copyright © 2019. All Rights Reserved. These
images, icons, and marks are reproduced with permission by ADI. No unauthorized
reproduction, distribution, or usage is permitted without ADI’s written consent.
This book contains copyrighted material of Microchip Technology Incorporated
replicated with permission. All rights reserved. No further replications may be made
without Microchip Technology Inc.’s prior written consent.
Atmel, AVR, ICSP, and In-Circuit Serial Programming are trademarks or registered
trademarks of Microchip Technology Inc.
Arm and Cortex are trademarks or registered trademarks of Arm Limited (or its
subsidiaries) in the United States and/or elsewhere. The related technology may be
protected by any or all of patents, copyrights, designs, and trade secrets.
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Introduction
W hen the first edition of this book came out in 2013, I opened it with the follow-
ing greeting:

You have excellent timing. As I often like to say, “We’re living in the future.”
I think I backed myself into a corner with that introduction, because if 2013 was
“the future,” then I’m not quite sure what to call the present! The far future? The
future-future? My point is, the march of progress has been swift, and the possibilities
for what you can do with even a cursory knowledge of embedded electronics and soft-
ware continue to expand every day.
Since the first edition of this book was released, electronics and software have
continued to become increasingly accessible with every passing day. In 2013, I was
hesitant to include a chapter about connecting your hardware projects to the internet
because the process for doing so was still quite fussy. The “Internet of Things” (IoT) was
just an emerging nerdy buzzword in 2013. Now, it’s a key part of the global vernacular.
It seems like every product for sale nowadays contains a microcontroller. Everything
is “smart” and most of those things also feature phone or web connectivity. I bet you
didn’t think you’d be buying a Bluetooth-enabled toothbrush back when “Bluetooth”
just referred to people talking to themselves through their wireless cellphone headsets.
Considering all this, I felt it was time to release a new edition of Exploring Arduino.
This second edition expands upon everything that was covered in the first edition. It
updates all the projects with new challenges and details, clarifies questions that people
had from the first edition, and adds a plethora of new content, including a lot more
details on wireless connectivity, new Arduino hardware, changes to the Arduino eco-
system and software, and more.

Why Arduino?
With the tools available to you today, many of which you’ll learn about in this book,
you have the opportunity and the ability to bend the physical world to your whim. Until
very recently, it has not been possible for someone to pick up a microcontroller and use
it to control their world within minutes. A microcontroller is a programmable integrated
circuit (IC) that gives you the power to define the operation of complex mechanical,
electrical, and software systems using relatively simple commands. The possibilities are
endless, and the Arduino microcontroller platform will become your new favorite tool
as you explore the world of electronics, programming, human-computer interaction,
xxvi Introduction

art, control systems, and more. Throughout the course of this book, you’ll use the
Arduino to do everything from detecting motion to creating wireless control systems
to communicating over the internet.
Whether you are completely new to any kind of engineering or are a seasoned veteran
looking to get started with embedded systems design, the Arduino is a great place to
start. Are you looking for a general reference for Arduino development? This book is
perfect for you, too. It walks you through a number of separate projects, but you’ll also
find it easy to return to the book for code snippets, best practices, system schematics,
and more. The electrical engineering, systems design, and programming practices that
you’ll learn while reading this book are widely applicable beyond the Arduino platform
and will prepare you to take on an array of engineering projects, whether they use the
Arduino or some other platform.

Who This Book Is For


This book is for Arduino enthusiasts of all experience levels. Chapters build upon
each other, utilizing concepts and project components from previous chapters to
develop more complex ideas. But don’t worry. Whenever you face new, complex ideas,
a cross-reference reminds you where you first encountered any relevant building-block
concepts so that you can easily refresh your memory.
This book assumes that you have little or no previous experience working with
programming or electrical engineering. Using feedback from readers of the first edition
of this book, I’ve taken special care to be very detailed in my explanation of the more
confusing topics you may encounter. To effectively support readers of various experi-
ence levels, the book features several optional sections and sidebars, or short excerpts,
that explain a particular concept in greater detail. Although these sidebars are not
necessary for you to gain a good understanding of how to use the Arduino, they do
provide a closer look at technical topics for the more curious reader.

What You’ll Learn in This Book


This book is not a recipe book. If you want to follow step-by-step instructions that tell
you exactly how to build a particular project without actually explaining why you are
doing what you are doing, this book is not for you. You can think of this book as an
introduction to electrical engineering, computer science, product design, and high-level
thinking using the Arduino as a vehicle to help you experience these concepts in a
hands-on manner.
When building hardware components of the Arduino projects demonstrated in this
book, you’ll learn not just how to wire things together, but also how to read schematics,
Introduction xxvii

why particular parts are used for particular functions, and how to read datasheets that
will allow you to choose appropriate parts to build your own projects. When writing
software, I provide complete program code, but you will first be stepped through sev-
eral iterative processes to create the final program. This will help to reinforce specific
program functions, good code-formatting practices, and algorithmic understanding.
This book will teach physics concepts, algorithms, digital design principles, and
Arduino-specific programming concepts. It is my hope that working through the pro-
jects in this book will not just make you a well-versed Arduino developer, but also give
you the skills you need to develop more-complex electrical systems, and to pursue
engineering endeavors in other fields, and with different platforms.

Features Used in This Book


The following features and icons are used in this book to help draw your attention to
some of the most important or useful information in the book:

WARNING Be sure to take heed when you see one of these asides. They appear
when particular steps could cause damage to your electronics if performed incorrectly.

TIP These asides contain quick hints about how to perform the task at hand more
easily and effectively.

NOTE These asides contain additional information that may be of importance to


you, including links to videos and online material that will make it easier to follow
along with the development of a particular project.

SAMPLE HEADING
These asides go into additional depth about the current topic or a related topic.

Getting the Parts


In preparing the projects outlined in this book, I’ve taken special care to use compo-
nents that are readily available through a variety of retailers, both in the United States
and internationally. I’ve also partnered with Adafruit (adafruit.com), a popular retailer
xxviii Introduction

of hobbyist electrical components. You can purchase all the components required for
completing the projects in this book from Adafruit. A convenient listing of Adafruit
parts for each chapter is available at exploringarduino.com/kits.
At the beginning of each chapter, you’ll find a detailed list of parts that you need
to complete that chapter—all of these parts are available from many sources. The
companion website for this book, www.wiley.com/go/exploringarduino2e, also provides
links to multiple sources where you can find the parts for each chapter.

What You’ll Need


In addition to the actual parts that you’ll use to build your Arduino projects, there are
a few other tools and materials that you’ll need on your Arduino adventures. Most
importantly, you’ll need a computer that is compatible with the Arduino integrated
development environment (IDE) (Mac OS X 10.7 Lion or newer, Windows XP or later,
or a Linux distro). I will provide instructions for all operating systems when warranted.
Arduino now also has an entirely web-based editor, but this book will generally
focus on the desktop IDE. All the instructions for the desktop software generally apply
to the online IDE as well. The first version of this book was read by people all over
the world, representing a wide range of internet speeds and reliability. To ensure that
Arduino remains easily accessible to all, I’ll mostly provide instructions that use the
offline IDE, as constant internet access isn’t always an option for everybody.
You may also want some additional tools that will be used throughout the book to
debug and assemble hardware. These tools are not only necessary to complete the pro-
jects in this book. As you develop your electrical engineering skillset, they will come
in handy for other projects, too. I recommend the following:

◼◼ A soldering iron and solder (Note: A few shields and microcontroller boards used
in the final chapters of this book may be sold with some soldering required—this
usually involves easy soldering of thru-hole pins to a circuit board.)
◼◼ A multimeter (This will be useful for debugging concepts within this book, but
is not required.)
◼◼ A set of small screwdrivers
◼◼ Tweezers
◼◼ Wire cutters and wire strippers
◼◼ A hot glue gun
◼◼ A magnifying glass (Electronics are small, and sometimes it’s necessary to read
the tiny, laser-etched markings on integrated circuits in order to look up their
datasheets online.)
Introduction xxix

Source Code and Digital Content


The primary companion site for this book is exploringarduino.com, and it is main-
tained by the author. You will find code downloads for each chapter on this site (along
with videos, links, and other useful materials). Note that both 1st edition and 2nd edition
content is available at this URL—ensure that you are visiting the pages for this
edition of the book. Digital content for the first edition is located at exploringarduino
.com/content1/ . . . and digital content for the second edition of this book is located
at exploringarduino.com/content2/ . . . . The website clearly differentiates between
content for the two editions of the book and is easy to navigate.
Wiley also maintains a repository of digital content that accompanies this book at
wiley.com/go/exploringarduino2e. You can also search for the book at wiley.com by
ISBN (the ISBN for this book is 9781119405375) to find links to book resources.
The code for this book is hosted on GitHub.com (a popular platform for sharing open
source software). Throughout each chapter, you can find references to the names of code
files as needed in listing titles and text. Each chapter’s code packages will be linked from
exploringarduino.com and wiley.com. You can download the code as a compressed ZIP
archive from either source. After you download the code, just decompress it with an appro-
priate decompression tool—all operating systems have one built in. You can also pull
code directly from this book’s GitHub repository (which is linked from exploringarduino
.com) if you are comfortable working with Git-based version control.

NOTE Because many books have similar titles, you may find it easiest to search
by ISBN; this book’s ISBN is 9781119405375.

NOTE Some URLs (especially the ones that I don’t control) may change or be
very long. To make it easier to type in long URLs that I may reference throughout
the book, I will list a “shortened URL” using my personal domain name shortener:
blum.fyi. For example, blum.fyi/jarvis redirects to a longer URL on my website
about a project called “JARVIS.”

Errata
We make every effort to ensure that there are no errors in the text or in the code. How-
ever, no one is perfect, and mistakes do occur. If you find an error in this book, such as
a spelling mistake or faulty piece of code, we would be grateful for your feedback. By
Random documents with unrelated
content Scribd suggests to you:
“So you’re one of Seth Bard’s curses, eh?” he said, at length, in a
preoccupied tone, with his back still turned to Mauney. “Been
fighting?”
“No, doctor, I ran a nail in my hand,” he replied, with a smile.
Horne shuffled a pace to his left to transfer his keen attention to
another bookbinding, which so completely absorbed him that
Mauney was sure he had forgotten his patient. After what seemed
five minutes, Horne turned about and, going to his desk, plumped
himself down into a swivel-chair. His eye-brows nearly touched the
line of his hair as his black eyes stole to the corner of his lids in a sly
study of his patient.
“Nail eh? Rusty?”
Mauney commenced undoing the bandage.
“Hip! Hip!” admonished Horne. “I didn’t tell you to take that off.
Wait till I tell you, young fellow. Lots of time. Rusty?”
“Yes, doctor.”
“Come in here!”
Horne jumped up and went into the surgery. He quickly cut away
the crude bandage and merely glanced at the wound.
“Soreness go up your arm, young fellow?”
“Yes, a little bit.”
“Uh—Hum!”
Horne clasped his arms behind his back and stamped dramatically
up and down the surgery, rattling the instruments in their glass case
by the wall. Suddenly he faced Mauney.
“How would you like to lose your arm, young man?” he asked
seriously.
“I’d hate to.”
“Then I’m going to open up that wound freely,” he said, walking
toward the instrument case. “Do you want to take chloroform?”
“No—I think I can stand it.”
Home selected a knife and pulling a hair out of his head tried its
edge.
“She’s sharp—damned sharp!” he remarked, dropping the
instrument into a basin of solution. “You think you can stand it, eh?
Remember, I offered you chloroform.”
Presently he picked the knife out of the basin.
“Come here, you. Put your hand in that solution. Hold it there a
minute. Does it nip?”
Mauney nodded.
“Well, let it nip. Now take your hand out. Stand up straight. Hold it
out here.”
Horne pressed the blade deeply into the tissues, then withdrew it.
Looking up into his patient’s face:
“Did you feel it?”
“Just a little, Doctor,” said Mauney, biting his lip.
“Don’t you faint, Bard!”
“I’m not going to.”
“Yes you are!”
“I am not!” insisted Mauney as the color returned to his face.
While the doctor put on a fresh dressing his manner altered. He
whistled a snatch of a country dance.
“You look like your mother, boy,” he said more gently. “I looked
after your poor mother. You were just a young gaffer then. She was
a very fine woman. She was too damned good for your old man. I’ve
told Seth that before now.”
“Will this need to be dressed again?” Mauney asked, as they later
stood in the waiting room.
“Yes. On Saturday.”
Horne’s attention was drawn to the figure of a woman
approaching the office.
“Hello!” he said softly. “Surely Sarah Tenent isn’t sick. I’ll bet she’s
peddling bills for the revival services.”
The bell rang.
“All right, come in, Mrs. Tenent.”
“How do you do, doctor?” she said, very deferentially, as she
entered.
“Just about as I choose, Mrs. Tenent,” he replied coldly, watching
her minutely.
She took a large white paper notice from a pile on her arm.
“Will you serve the Lord,” she asked with great soberness, “by
hanging this in your office, doctor?”
He glanced over it and read aloud, very hurriedly: “Revival
Services, Beulah Church, commencing Sunday. Rev. Francis Tooker
and Rev. Archibald Gainford, successful evangelists, will assist the
new pastor, Rev. Edmund Tough. Special Singing. Come.”
He passed it back to her and shook his head.
“No, no—not here, I’d never hang it here. I have patients who are
not of thy fold, Mrs. Tenent. My function is to cure the sick. That
sign would make some of them sicker. No, no.”
The woman left the office in silent disapproval of Horne’s attitude.
Mauney put on his hat and was leaving the office, when the doctor
appeared in the door behind him.
“Hold on, young chap!” he commanded. “Wait you! Didn’t I see
you driving into the village with a young lady?”
“I didn’t think you noticed us,” laughed Mauney.
“Who was she?”
“Miss Byrne. She teaches at the Brick School.”
“Yes, yes. Of course she does. Fine young lady,” he said, studying
Mauney with much lifting of his brows and pouting of his lips. “But
you’re too young, Bard. Why don’t you get somebody your own
age?”
“Oh,” Mauney said quickly, while his face flushed; “She’s probably
got a beau. It isn’t me, anyway, doctor.”
Horne, greatly amused at the emotional perturbation of his
patient, chuckled, while his black eyes sparkled.
“Get along with you, Bard!” he said, “Get along home with you
and don’t forget to come up on Saturday, mind!”
The revival meetings became the talk of the countryside. Beulah,
composed for the most part of retired farmers, had unusual leisure
in which to think—a leisure captured by the glamor of religion, which
was the strongest local influence. Although the village was a century
old it had preserved, with remarkable success, the puritanism of the
pioneer period, partly because it enjoyed so little touch with the
commercial energies of the nation at large, and partly because the
local churches had remained diligent in spiritual service. But in a
population so uniformly composed of idle folk, the general view-
point lay itself open to become biased. There was too much
emphasis on the ghostly estate and too little on the need of practical
endeavor. Beulah had forgotten long since that the Church must
have its lost world, else it becomes unnecessary, and to the average
citizen, lulled as he was by surfeit of beatific meditation, the board
sidewalks had begun to take on an aureate tinge, the houses, a
pearly lustre. The spiritual concern of the religiously eager Beulahite
had in it, unfortunately, no concept of national character, but was
pointed sharply at the individual. His sense of personal security was
only less unhealthy than his over-bearing interest in the soul welfare
of his neighbor. Saved by repeated redemptions himself, he
remained strangely skeptical of the validity of the phenomenon in
others. Hence, at fairly regular intervals, a general village
consciousness of sin developed, becoming insistently stronger until it
found its logical expression—the revival meeting.
Mauney, during the next week, listened to the religious talk of the
community with mild curiosity. Mrs. McBratney, the pious mother of
David, said to him one afternoon from the side of her buggy:
“I hope you’ll attend the revival meetings, Mauney. Your mother
would want you to go. We are praying for great things.
“I’ve been on my knees for the young people,” she continued,
“and I believe David has got conviction.”
Tears suddenly filled her eyes and her chin quivered with such
tremulous emotion as to embarrass Mauney, who could fancifully
imagine that David had been smitten by a plague.
“I believe he will be converted,” she managed to say, before her
voice broke into a sob, “and I pray the Lord will show you the light,
too, Mauney.”
He felt that perhaps it would have been good form to say “Thank
you,” for he was sure her intentions were sterling, but he resented
her reference to his mother, who seemed to him, in memory, a
creature too much of sunshine and peace to be associated with
anything so dolefully emotional.
He had never been a regular attendant at church. He remembered
having sat beside his mother many times in the auditorium listening
to unintelligible sermons and strenuous anthems. But from the day,
five years ago, when as a chief mourner he had sat blankly
stupefied, hearing comforting words that failed to comfort, and
music whose poignant solemnity froze him with horrid fear, he had
never been invited either by desire or family suggestion to return.
By the second week of the meetings David McBratney was
reported to have been converted. He had stopped coming to see
William as had been his custom. Neighbors said there could be no
doubting the genuineness of his reformation for he had ceased
chewing tobacco and was contemplating entry into the ministry of
the Church. During supper at the Bard farm on Saturday evening a
lull in the conversation was broken by a sarcastic laugh from William.
“Well, Dad, I guess they’ve got Dave,” he said. “Abe Lavanagh was
tellin’ me to-day that Dave has went forward every night this here
week. I never figured he’d get religion.”
Bard philosophically chewed on the idea as he peered at the lamp
through his narrow eyes.
“There is just two kinds of people,” he asserted at length. “The
fools and the damned fools. Now there’s a boy who’s got every
chance of inheriting his old man’s farm. And I’m tellin’ you, Bill, it’s a
purty good piece o’ land.”
“You bet.”
“Just about as good as is bein’ cultivated this side of Lockwood.
There ain’t a stone left in the fields, but what’s piled up in the
fences. William Henry has slaved this here thirty years—got the
mortgage cleaned up—and that barn o’ his, Bill, why you couldn’t
build it to-day for five thousand!”
“No, nor six, Dad.”
“Then look at the machinery the old man’s got. I’m tellin’ yuh
Dave ain’t goin’ to drop into nothing like that, agin. William Henry
must be seventy!”
“May be seventy-one, Dad.”
“Anyhow he ain’t goin’ to last a great while longer. If I was Dave
I’d forget this religion business. ’Taint goin’ to get him nowhere. Ain’t
that right, Snowball?”
The hired man, having finished supper, was sitting back drowsily,
but at the sound of his name he winked his eyes cautiously.
“I dunno,” he said, “I don’t never bother much about religion, so I
don’t!”
In Dr. Horne’s office that week the subject of the revival came up
while Mauney was having his hand dressed.
“Some queer people here in this one-horse town!” mused Horne.
“Do you remember George Pert who died a couple or three years
ago?”
“Lived down by the toll-gate?”
“That’s him. Lazy as twelve pigs. Use to lie abed till noon. Wife
kept a market garden. Never paid his doctor’s bills. Yes, sir! George
Pert! He got a cancer of the bowel, poor devil. Sick. Pretty far gone.
I went in one day and found preacher Squires sitting by the bed.
‘Well, Mr. Pert,’” (Horne’s voice assumed an amusing clerical
solemnity) “‘Are you trusting in the Lord?’ George nods his head.
‘Yes’ says he, ‘I’m so sartin o’ salvation, that if only one person in
Beulah is going to heaven I know it’s me!’
“They’re a nosey bunch, here!” Horne continued, as he wound a
bandage on Mauney’s hand. “Self-satisfied! Let your light so shine—
good! But don’t focus your light into a red-hot spot to burn out your
neighbor’s gizzard. Last night Steve Moran came into the office and
sat down. ‘Doctor’ says he, ‘I just came in to see if your feet were
resting on the Rock.’ Says I, ‘Steve, you blackguard, you owe me five
dollars from your wife’s last confinement, fifteen years ago. If you
don’t go to hell out o’ here, you’ll be resting in a long black box!’”
Mauney was surprised how much people talked about the revival.
Enthusiasts carried out from the meetings, by their words and
manner, an infectious fervor that directed the curious attention of
others to the thing that was happening night by night in the Beulah
church. Finally, on Sunday evening, he decided to see it for himself
and drove to town. The church sheds were filled to overflowing so
that he tied old Charlie to a fence post in the yard. Through the
colored windows he heard the voluminous roar of voices lifted in the
cadence of a hymn. The church was crowded. The vestry at the
entrance was full of waiting people and, through one of the doors
leading to the auditorium, he glimpsed a sea of heads. At the farther
end of the great room, in a low gallery, sat the choir, facing him, and
below them on the pulpit platform three preachers were seated in
red plush chairs. The seated congregation were singing an unfamiliar
hymn whose rhythm reminded him of march music he had heard
bands playing in Lockwood. Ushers were carrying in chairs to
accommodate the overflow.
David McBratney, carrying an armful of red hymn books touched
Mauney on the shoulder.
“Here’s a book,” he whispered, proffering one. “I’ll get you a seat
in a few minutes. Glad to see you here, Mauney.”
McBratney’s face glowed with a strange luminosity, puzzling to
Mauney, and his speech and manner were quickened by nervous
tension. Presently he led the way to a chair in the aisle.
At the end of a stanza one of the preachers jumped suddenly to
his feet and interrupted the organ.
“You’re not half singing!” he shouted angrily. “You can do better
than that. If you haven’t more voice than that, how do you expect
the Lord to hear your words of praise? Now, on the next stanza, let
yourself out. Ready!”
He raised both arms high above his head and, as the organ
commenced, brought them to his side with such force that he was
compelled to take a step forward to regain his balance. His words
had the effect he desired, for a deafening volume of sound rose and
fell quickly to the lilt of the march-music, suggesting to Mauney the
image of neatly-uniformed cadets with stiffened backs and even
steps, moving along Lockwood streets on a holiday.
When the hymn ended, a soft hand touched Mauney on the arm
and, looking to his right, he saw Jean Byrne seated in the end of the
oaken pew directly next to him. She was just letting her closed
hymnal drop into her lap.
“Glad to see you,” she whispered, guarding her lips with her
gloved hand.
One of the preachers rose slowly from his chair. He was a stout
man of fifty, mild-appearing and pleasant, with clean-shaven face
and grey hair. He walked forward to the edge of the carpeted
platform, rested his elbow on the side of the pulpit and raised his
face to gaze slowly over the quieting congregation. “My dear
friends,” he said in soft, silver tone, “I thank God for the hymn we
have just been singing. It has been indeed very inspiring. Brother
Tooker and myself have been in your little town for two weeks now,
and have grown so fond of the people that we view to-night’s
meeting with inevitable feelings of regret, because, so far as we can
see the divine guidance, it will be our last night with you. But we
have also feelings of hope, because we are praying that there may
be a great turning to God as a result of this meeting.”
As he paused to shift his weight slowly to his other foot and clasp
his hands behind his frock coat, the congregation was silent. Only
the sound of a horse stamping in the shed could be heard.
“During our fortnight with you,” he continued, “many souls have
been led to the Cross. We thank God for that. But there are many
more who are still living in sin—some of them are here to-night.”
As his glance shifted over the mass of upturned faces, Mauney
fancied he paused perceptibly as he looked his way.
“It is to you, who are in sin, that we bring a message of hope. You
have only to take God at his word, who sent His Son to save that
which was lost.”
“Amen!” came a vigorous response from an old man in the front
pew.
“You have only to believe on Him who is righteous and just to
forgive us our sins and to cleanse us from all unrighteousness.”
“Amen!” from near the back.
“Amen!” also, from the side, half-way up.
At this juncture a woman in the body of the auditorium burst
forth, in good voice, singing the first verse of “Though your sins be
as scarlet,” whereat the preacher indulgently acquiesced, and waved
for the congregation to join her. At the end of the first stanza he
raised his hand.
“The lesson for to-night is taken from the first chapter of the
beloved Mark.” As he carefully read the passage of scripture the
ushers were busy leading in more people, so that, when he finished,
the floor was entirely filled save for two narrow aisles, one on either
side, leading from the back to the altar railing.
The Reverend Francis Tooker, as he walked confidently forward,
was seen to be tall and thin, with a long, florid face and a great
mass of stiff, black hair. He raised his large, bony hand.
“Let every head be bowed!” he commanded, sharply.
After a short invocation he commenced his discourse. He dealt at
length with the experiences of the prodigal son, pictured in adequate
language the depths of profligacy to which he had sunk, stressed
the moment of his decision to return home, and waxed touchingly
eloquent over the reception which his father accorded him.
“And now, people,” he said more brusquely, as he slammed shut
the big pulpit Bible and ran his long fingers nervously through his
hair. “You’ve got a chance to do what that boy did. You’ve been
acting just the way he acted—don’t dare deny it! You’ve been
wallowing in the dirt with the pigs, and you’re all smeared up. What
are you going to do about it?”
The audience, keyed up to the former flow of his unfaltering
eloquence, were now mildly shocked by the informality of his
pointed question. He walked to the very edge of the platform while
his eyes grew savage and his face red.
“What are you going to do about it?” he shouted, clenching his
fists and half-squatting. Then, rising quickly, he hastened to the
other side of the pulpit. “Are you going to arise and go to your
Father? Or are you going to keep on mucking about with the pigs?
Don’t forget that for anyone of you this night may be your last. To-
night, perhaps you” (he pointed), “or you,” (he pointed again) “may
be required to face God. What are you going to do about it? Are you
going to die forgiven of your sins like a man, or are you going to
shut your ears to the word of God and die like any other pig?”
No sound interrupted the intense silence. No one moved. Even the
flickering lamps seemed to steady their illumination to a glaring,
yellow uniformity.
Suddenly his manner altered. Moving to a position behind the
pulpit he rested his elbows on the Bible and folded his hands
together out over the front edge of the book-rest, while his voice
assumed a quiet, conversational tone.
“Remember that on this night, the twentieth day of April, 1914,
you were given an opportunity to come out full-breasted for God. I
have discharged my duty. The rest remains for you to do. If you are
sorry for your sins, say so. If you regret the kind of life you’ve been
leading, confess it. Come out and get washed off clean. The
invitation is open. The altar awaits to receive you.”
As he pointed to the altar railing, his black eyes flashed
hypnotically.
“Those who have sinned, but are repentant and seek redemption,
please stand.”
For about ten seconds a great inertia possessed the seated
congregation. Then two men stood up near the front of the pews,
followed soon after by groups of both men and women in various
parts of the auditorium, until, at length, only a sporadic rising here
and there marked a new mood of hesitancy.
“While the choir sings,” the preacher said softly, “I will ask you to
steal away to the foot of the altar. The choir will please sing the first
two verses of ‘Come Ye Disconsolate,’ and you who have, by
standing, thus signified your desire for salvation, will move quietly
forward and kneel by the railing.”
As the slow, full chords of the hymn began the preacher’s voice
kept calling “Come away, Brother,” and the standing penitents sought
the narrow aisles and moved slowly forward to kneel with their
heads touching the oaken railing. The Rev. Archibald Gainford and
the Rev. Edmund Tough descended from the platform to the
crescent-shaped altar space and, bending down, spoke words of
comfort to the suppliants.
As the choir stopped and the organ notes faded, the exhorter
produced a silver watch and examined it, hurriedly.
“If we had more time,” he said, “how many more would like to
come forward? Please stand.”
A dozen or more rose to their feet.
“Well,” he said, with a smile, as he returned his watch to his
pocket, “we have plenty of time. Come out, brother!”
Caught by this subtle snare, many of the presumably wavering
individuals found it impossible to refuse his invitation, while a few
sat down again.
When the meeting eventually drew to a close, after a long hymn,
sung with the same exciting rhythm as the first one, Mauney rose
with the rest and moved impatiently toward the door, walking beside
Jean Byrne and talking to her of obvious matters. Her face, he
noticed, was flushed and her eyes shining with unusual brightness
from delicately moist lids, while her voice seemed husky and
uncertain. The auditorium emptied slowly. The steps leading down
from the front doorway to the walk presented the customary Sunday
night groups of village beaux waiting to accompany their
sweethearts home, or perhaps stroll with them through quiet,
moonlit streets.
Beulah village council, anxious to keep taxes at a minimum, had
never provided street-lighting, so that pedestrians, on dark nights,
carried lanterns, unless they were lovers, in which case they relied
either on moonlight or familiarity with the local geography.
Jean Byrne had come to the village in the buggy of Mr. and Mrs.
Fitch with whom she boarded on the Lantern Marsh road, but
Mauney, being alone, invited her to drive down with him. She
accepted and soon they were off together.
“I could have kicked over a pew in there to-night,” said Mauney at
length, tersely.
“I knew you wouldn’t like it,” she said. “Personally I think it’s very
unreal. Perhaps some people derive good from it, though.”
“Perhaps. But it hasn’t any connection with real life, Miss Byrne. I
can’t help feeling you’ve got to let the common daylight into things.”
“That’s good.”
“It’s easy enough to see how they get pulled into it,” he went on.
“There’s a sort of excitement about it. I don’t think one person by
himself could get so excited.”
“You mean there’s a mob consciousness?”
“Yes, exactly—a lot of minds rubbing each other, like.”
“I believe you’ve hit it, Mauney,” she said. “I never thought of it
like that before. How did you manage to think that out?”
“Well, I’ve always noticed, if I’m in a crowd, that it’s hard for me
to stay just as I am when I’m alone. Now, I hate people who are
always chirping like chipmunks—you’ll meet them at socials and
dances. They don’t say anything that matters and might better keep
their mouths shut. But if I get with them I’ll notice how it affects me,
for after I leave I feel sort of weak.”
“You must enjoy observing things like that, Mauney.”
“No, I don’t enjoy it,” he replied. “That’s just what I’m up against
the whole time at home. My father and brother and the hired girl
keep up an endless rattle of talk, all the time, about things that
aren’t important. I keep quiet on purpose because I don’t want to
talk about them.”
“What sort of things do they discuss?”
“Oh—the price of eggs, what somebody did with a certain horse,
who married so-and-so and who she was before she did it, and
whether the preacher’s wife is human, and then they’re always
teasing Snowball; but he isn’t such a fool as they think he is.”
For a moment Miss Byrne studied Mauney’s face, bright with
moonlight.
“Well, what kind of things do you think are important?” she asked.
“I mean what would you like to discuss, if you had your own way at
home?”
“I couldn’t say exactly,” he said, reflectively. “But I’m discontented
all the time, and feel ignorant. I want an education. I’m interested in
history, most.”
While she listened to his words, Miss Byrne was enjoying the
landscape as they drove slowly along. It was no new thing for her to
feel fresh attractions toward Mauney, but to-night, for some reason
that she did not seek, she felt uncomfortably warm toward him, and
presently her soft, gloved hand pressed his hand tenderly, and
remained holding it. It came as a surprise to him, and he glanced
quickly at her face, across which the sharp shadow of her hat
formed a line just above her lips. He could distinguish her eyes
turned away in the direction of the moonlit fields she was admiring,
and her pretty lips, vivid and tender, sent a strange thrill through his
body. Although he made no effort to draw away his hand, he disliked
the situation as something he could not grasp. Lying helplessly
captured, his fingers felt the heat of her hand. She had stopped
talking and he noticed her bosom moving as deeply as if she were
asleep, but more quickly. He had the same feeling, for an instant, as
in the meeting, of an outside power insidiously exciting his mind, but
noticed with a definite sense of relief that they were nearing Fitch’s
gate. In a moment he freed his hand from hers and pulled up the
horse.
“Mauney!”
She spoke his name in a low, unsteady voice and pressed her
hand against his arm. That she was not warning him of some
sudden obstacle in their way, was clear, for, on looking toward the
road, he saw nothing. When he turned to her, her hat was hiding her
bowed face and her hand was relaxing slowly—so very slowly—and
falling from his arm. The emotion that caused her breathing to be
broken by queer, jerky pauses mystified him.
“Are you ill, Miss Byrne?” he ventured to ask, and noticed that his
own voice was tremulous.
She shook her head slowly and began to climb out of the buggy.
“No, Mauney boy,” she replied softly. “I was just lonesome, I guess.
Goodnight!” He was puzzled. As he drove along he grew exceedingly
impatient. There were so many things, he thought, beyond his
comprehension.

CHAPTER III.
Mauney Meets Mrs. Day.
“A pretty woman is a welcome guest.”—Byron, “Beppo.”

When he reached home, Mauney found his father talking in the


kitchen with William Henry McBratney while the hired girl lay on the
sofa with the cat asleep on her bosom. His father, seated with his
socked feet resting on the stove damper and his chair tilted back,
looked up as he entered from the yard.
“Well,” he addressed him, “I hope to God you didn’t get it.”
“Get what?” asked Mauney, surprised at being noticed, and irked
by his father’s abrupt manner.
“You wasn’t in a place where you’d be likely to get a bottle of
whiskey, was you?” Bard quickly responded.
“Oh—you mean religion, Dad?”
Without further acknowledgment of Mauney’s presence than a
sarcastic motion of his head, Bard addressed his neighbor.
“I guess that’s about all he’d get up to Beulah church, ain’t it,
William Henry?”
“Yes, sir, that’s about the size of it, Seth!” admitted McBratney,
smacking the arm of the chair with his bony palm, as if one would
naturally expect to get a variety of commodities at Beulah church.
He possessed an evil, circular face, with gray hair falling untidily over
a low forehead. His long, thin legs seemed largest at the knee-joints
as he sat with difficulty in the low rocking-chair, and his long, brown
neck, with its prominent Adam’s apple, gave his small, ball-like head
an unreal appearance of detachment. When he spoke, in his high-
pitched, rasping voice, his Adam’s apple shifted up and down his
throat as if it were a concealed bucket bringing the words up from
his body.
“That’s about the size of it, I tell yuh!” he repeated. “And when
they get religion, Seth, why there ain’t no good tryin’ to drill any
reason into ’em!”
Mauney stood in the door leading to the former dining-room,
watching McBratney’s small eyes shine with wicked animation.
“As I was tellin’ yuh,” he went on, “the woman wouldn’t let up on
him, day ner night, pesterin’ the life out o’ the boy, goin’ into her
room there off the kitchen an prayin’ like she was tryin’ to ward off a
cyclone.”
He suddenly bent forward, so that his long hands nearly touched
the floor, suggesting to Mauney an enraged orang-outang looking
through the bars of his circus cage.
“An’ now that she’s got her way, what do you think?”
Bard knocked the bowl of his pipe against the edge of the stove.
“God only knows! What?” he said.
“Dave’s made up his mind to go preachin’!”
“I heard that,” admitted Bard with a sly smile. “I s’pose you’ll be
proud to have a son o’ yours called of the Lord, eh?”
“Called o’ nothing!” declared McBratney, hammering the chair arm
with his fist, then settling back, with much silent movement of his
Adam’s apple. “I’ve tried to reason with him, but his mind is stopped
workin’ or else it’s workin’ just a little bit too fast fer me. I think he’s
just framin’ an excuse to leave the farm.”
“Give him a few weeks, William Henry,” suggested Bard. “He may
get over this here frenzy o’ his. Dave always struck me as a purty
sharp lad an’ I reckon it’s only temporary, like.”
The hired girl looked up from her idle occupation of stroking the
cat’s fur.
“Many folks out to church, Maun?” she asked.
Bard, as though he resented her speaking to his son, made a
gesture toward the table.
“Here, Annie,” he said authoritatively, “Go cut up a loaf o’ bread
and set out a bowl of preserves. Me and William Henry is goin’ to
have a bite to eat.”
Up in his own room, Mauney later tried to read a small book Miss
Byrne had given him. It was a leather-bound copy of Thomas à
Kempis. He wondered why she had chosen such a gift, for the
subject matter was too cloistral. Tossing it aside, he picked up an
Ancient History she had recently loaned him and became absorbed
in it until he was able to forget some of the things that rankled in his
breast, among others, Jean Byrne’s peculiar manner in the buggy.
Lying with his head propped on a pillow he read until his eyes ached.
In fancy he lived in ancient palaces among courtiers and councillors,
saw the regalia of royal fêtes, through which came the sound of war
trumpets. He read of ambitious sculptors whose names were written
on the roster of deathless fame and saw steel engravings of their
work—headless, armless torsos, nicked and cracked by the ravage of
centuries. He saw conquerors leading stalwart armies, deciding the
fate of nations. The story held him to the last page and he saw that
the aspirations of a mighty nation were dead; the rising star of
ambition was quenched in its ascent; and only a vast pile of
melancholy tokens remained to interest scholars who delved with
spades. And he went to sleep in great wonderment as to what it all
signified.
A few days later he took the Ancient History to return it to Miss
Byrne. As he approached Fitch’s gate on foot, he heard Jean’s low
laughter, and on passing between the lilac hedges, saw her on the
front verandah with Mrs. Fitch.
“Good evening,” he said, “you both seem to be enjoying
yourselves.”
“Come and sit down, Mauney. Mrs. Fitch has just been convulsing
me with a story from real life,” she invited, her eyes red from
laughter. “What have you been doing to-day?”
“Oh, the same old stuff,” he replied, nodding slyly towards Mrs.
Fitch, busy with long, white knitting-needles. “I thought I’d stroll
over and hear the latest scandal.”
Mrs. Fitch was a woman of fifty, with scrupulously tidy grey hair, a
square jaw, silver spectacles and thin lips suggesting latent deviltry.
“Wal, Maun,” she said, without looking up from her rapidly-
interplying ivory-points, “we ain’t accurate scandal-mongers. Not the
kind that talk about folks for the sake of harmin’ them. But things do
strike us peculiar like, at times, and gives our livers a healthy shakin’
up. I’ve just been telling Miss Byrne about the young Hawkins brat.”
She paused and cast a sharp glance over the tops of her glasses.
“You know him?” she asked.
Mauney nodded and smiled, for it was common knowledge that
the son of Miss Lizzy Hawkins could not claim, with any degree of
accuracy, the paternal factor of respectability enjoyed by most
children.
“Wal,” she resumed, her eyes returning to the line of her knitting,
“young Hawkins was a-playin’ in the road out here after school.
Along comes William Henry McBratney drivin’ the old, grey horse. He
sees the Hawkins boy and he pulls up and he says, says ’e, ‘Where’s
your father, you young brat!’ Young Hawkins, of course, didn’t know
him—hasn’t brains enough to know anybody, but, after a minute of
heavy thinkin’ he looks up at McBratney and he says, says ’e, ‘Maw
told me, me father was down in South Americky workin’ on a steam
roller, but I heard her tellin’ me grandmother as how me father’s
name is William Henry McBratney!’”
Mauney laughed as Mrs. Fitch soberly glanced over her spectacles
again.
“And then,” she resumed, “old William Henry leans half out of his
buggy, waving his whip and shouting, without knowing as how he
had an audience: ‘Tell yer mother to keep her damned mouth shut,
you brat!’
“I guess it’s true enough,” she went on presently, pulling a string
of yarn from the revolving ball in her lap. “And then people talk
about Dave McBratney for getting converted. It was the best thing
he ever done! If I was a son of William Henry’s I’d get converted
before you could say Jack Robinson.”
Mauney had never so little enjoyed talking with Jean Byrne as to-
night. The episode of Sunday evening had left a distasteful flavor in
his mind, for, although he tried to forget it, the incident kept flashing
back upon his memory. He was left alone on the verandah with her
presently, and immediately felt an awkwardness, hard to overcome.
Hitherto, she had always been just his teacher. But to-night, dressed
in a yellow-flowered frock, with a pale yellow ribbon holding her dark
hair down on her brow, she had lost a quality of dignity. He noticed
also a hundred fine lights of tenderness in her eyes that he had
never seen before.
He talked with her a few minutes and gave back the history.
“Let me get you another book,” she said, starting toward the door.
“Please don’t bother—just now, Miss Byrne,” he said.
“Why not, Mauney?”
“I’m so busy I haven’t time to read,” he lied.
He thought afterward that in that moment when he refused to
accept her kindness she divined perfectly the underlying feeling. It
was his last conversation with Jean Byrne. He went home quite
sadly. There was no surfeit of comforts in that home of his, to be
sure, which could render him careless of helpful friendships: but,
although he felt the significance of refusing her offer, knowing it
meant the end of things between them, his sadness was over the
seeming weakness in her that had caused his dislike. He might not
have been so astonished at other women. But of Jean Byrne he had
expected differently.
His life in the Lantern Marsh thus robbed of one more brightness
became the more uninteresting. He felt the need of companionship.
Struggling through long days, of planting, sowing, and haying, he
forced back the tug of expanding desires that urged him to different
pursuits. In the evenings he would stand looking down the road that
led to Lockwood, wishing that he were travelling it never to return.
To Lockwood, to Merlton beyond, to the world. He dreamed of a
different life from his own, where people were gentle, where they
knew things and would be willing to teach him out of their
knowledge. But these dreams were folded to rest each night in
heavy sleep and the light of each morning found them dissipated. He
wanted books, but there was no library in Beulah. He had no money
of his own and knew the foolishness of asking his father for it.
At the end of June, Jean Byrne returned to her home in
Lockwood, and Mrs. Fitch remarked to him one day that she was not
coming back, but was going to be married in the autumn to a doctor
in her own town. Mrs. Fitch was curious, no doubt, to discover a
reason for Mauney’s never having come back to see her again.
“Miss Byrne was a good teacher, Maun,” she said, as they talked in
the Beulah post-office, “and I think she was powerful fond o’ you,
boy. She told me onct as how she expected you would some day
make your mark in the world.”
Mauney felt tears welling into his eyes and turned away from her
without further comment. He drove home blaming himself for having
been rude to Jean Byrne. Her confidence in him, expressed through
Mrs. Fitch, had come as sharp reward for his ingratitude. And yet,
was it his fault?
On a sultry July evening an unexpected break in the monotony of
his life occurred. He was sitting alone on the front steps of the farm-
house, having just come in from the fields, when his attention was
attracted by a cloud of dust on the Lockwood road. A motor car was
travelling rapidly along and as it drew near, slackened its speed.
When it stopped directly at the foot of the orchard he surmised the
people in it had paused for directions. A woman in the back seat
waved to him and he quickly responded.
They were all strangers, the man at the wheel and the two women
in the rear seat, although he felt there was something quite familiar
about the grey-haired woman sitting nearest him.
“Is this where the Bards live?” she asked a little nervously. She
was a small-bodied woman of perhaps fifty with very fine features,
and clear, blue eyes that smiled pleasantly through rimless
spectacles and the fawn motor veil that covered her face.
“Yes,” Mauney replied, gazing curiously at her, and then at the
others.
The man, chewing the end of an unlighted cigar, looked at the
house with a frown and then glancing backward said in a low tone:
“Well, suit yourself, Mary. You might regret it if you didn’t.”
The woman, presumably his wife, looked with an undecided
expression toward the house, as if she feared it.
“Is your name Bard, please?” she asked, raising her veil, and
minutely inspecting Mauney’s face.
“Yes,” he said, glancing again at the others.
“He looks the dead image of her!” the other woman remarked
prosaically to the man.
“And are you Mauney?” asked his interlocutor.
His brow was puckered with a dawning idea that soon caused his
face to brighten up.
“Are you my Aunt Mary?” he asked, eagerly.
“How did you know?”
He came nearer and took her extended hand.
“Mauney, this is your Uncle Neville, and this is your Uncle’s sister,
Jane Day. This must be quite an extraordinary surprise to you, isn’t
it?”
Mauney nodded.
“Aren’t you going to stay?” he asked. “When did you come to this
country?”
“We came about a week ago, Mauney. Your Uncle Neville is over
on business, and our headquarters are in Merlton. We motored all
the way from Merlton to-day just to see where—where you lived,
you know.”
“You must be tired. What time did you leave?”
“About seven this morning, but the country has been simply
beautiful, every inch of the way.”
“Come in. Put your car in the shed. I’ll go and tell my father.”
“Wait!” said his aunt. “Just let’s talk a moment. You’ve got a
brother, but I’ve forgotten his name.”
“William.”
“Of course—how stupid of me to forget! Did you ever receive a
letter I wrote you, Mauney, just after your mother died?”
“No, I don’t remember getting one,” he replied, with an expression
of curiosity.
“That’s strange. Apparently it went astray. But I always wondered
—but then I wrote you again, Mauney, about three years ago. Didn’t
you get that?”
He shook his head.
“Funny!” she said, looking toward her husband.
“There’s nothing funny about trans-Atlantic mails, my dear,” said
Mr. Neville Day, lighting his cigar. “It’s got well past the funny stage
with me.”
“And then I sent you a postcard once, I remember. Didn’t you
even get that, Mauney?”
“I don’t remember it.”
“Well, anyway, we’re here,” she said, with sudden decision. “And if
I don’t see him, I’ll always wish I had.”
“All right, Mary,” said Neville Day. “Now stick to that, my dear.
Would you mind telling your father there’s somebody here to see
him, Mauney?”
“Certainly,” Mauney agreed, turning to leave.
“Oh, wait!” called his aunt. “Wait a minute. You know I—I don’t
think I can see him, Neville. No, I can’t. I really cannot.”
The uncle smoked calmly, studying his finger-nails, while Mauney
stood riddled with curiosity.
“Come here, dear,” said his aunt. “Promise me not to mention us
to your father. We aren’t going in, and it’s—it’s so hard to explain
why we aren’t.”
Neville Day and Miss Jane Day got out of the car and walked
slowly along the edge of the road together. His aunt asked Mauney
to get in the rear seat and sit beside her. As she turned toward him,
he could see his mother’s likeness with startling vividness.
“Your mother used to write to me about you, Mauney,” she said.
“You were her favorite, I’m glad you’re such a big fellow. How old
are you?”
“Eighteen.”
“It’s terrible how the time goes. I suppose you’re happy and well
all the time—”
He gauged the expression in her eyes. He felt completely at home
with her. She looked so much like his mother that he wanted to
remain with her endlessly.
“Well, Aunt Mary,” he said slowly, “I’m not very happy, I’m afraid.”
“What’s wrong?” she asked sympathetically.
“I don’t know.”
“Does your father treat you all right?”
“I think he tries to, Aunt Mary, but since my mother died, I’ve
always been—dissatisfied. How long are you going to stay—I mean
here?”
“We’ll have to return to Lockwood—is that the name?”
He nodded.
“We’ll go back there for the night and return to Merlton, to-
morrow.”
“Why won’t you come in, and see my father?” he asked.
“Well you see, Mauney, it’s—it’s so late, you know.”
Her explanation was patently false, for he saw her face struggle to
remain composed, and then noticed a queer hardness come upon it.
“Do you know where the old Conyngham place is?” she asked.
“Sure. Over there!” he pointed to a field not far away.
“You knew about that, didn’t you?”
He shook his head and glanced with a puzzled expression toward
the old, dilapidated house that had always stood at the edge of his
father’s big corn field. It was uninhabited and partly obscured by
wild cucumber vines.
“I only knew it was called the old Conyngham place,” he said.
“When mother was alive, she used to go over there and keep
geraniums in boxes in the front windows, and our hired man—the
one we had before—lived there with his wife for quite a long time.”
“Well, your mother used to live there, Mauney,” his aunt said, “She
was looking after Uncle James. You see his wife had died and he
was old and sick with asthma.” She glanced toward the opposite side
of the road. “I suppose this bog-land here gave him the disease. He
was all alone and when we got his letter, your mother made up her
mind to come out and look after him. So she left Scotland when she
was just seventeen. She remained right with him to the last, and
certainly did not spare herself.”
“My mother never told me that,” Mauney interrupted.
“No. She wouldn’t tell you. But while she was looking after Uncle
James our own mother died in Carstairs and it was too far for her to
come home. Then I married Neville and, poor girl, she felt that all
her relatives were gone. So, after Uncle James died, she—she stayed
here, you see.”
“Married my father.”
“Yes, Mauney,” she said sadly. “Remember, dear boy, your mother
was the sweetest girl that—”
She hesitated, as if her interest in the farm house and the orchard
had suddenly usurped her attention.
“You’ve got quite a big farm, Mauney,” she said. “Are you going to
stay here and be a farmer, too?”
“I guess I’ll have to, Aunt Mary,” he smiled.
“I see.”
“But I’d like to get some education, some time.”
Her pretty, blue eyes wandered from his face to the figures of
Neville Day and his sister who were just turning about to come back
toward the car. For a moment her face became dreamy as if she
were mentally exploring the pleasant future. Then she took a card
from her purse and handed it to him.
“My address is on that, Mauney,” she said. “Please write to me
once in a while and let me know how you are getting along. We go
back to Scotland in another week. Dear me, you ought to be glad
you live in America.”
Soon her husband was beside the car.
“That land could all be reclaimed,” he said, wagging his thumb
toward the marsh. “It wouldn’t cost over two thousand, either.”
“Dollars?” asked Mrs. Day.
“No, pounds.”
“They don’t need to do that sort of thing,” stated Miss Day. “As it
is now, there’s plenty of tillable soil not under cultivation. I fancy
that it will be a long time before these farmers will find it necessary
to reclaim land.”
Day glanced at his watch.
“If you don’t mind, Mary,” he said, “it’s getting late and we’d better
try to make Lockwood before dark. How far is it, Mauney?”
“It’s just over twenty miles.”
They entered the car while Mauney stood on the road waiting to
say good-bye. Neville Day tossed away the stump of his cigar and
settled down behind the wheel, adjusting his motor-cap more
comfortably.
“Oh!” he said, turning to hand up a large parcel, done up in
wrapping paper. “You forgot the books.”
Mrs. Day laughed.
“Mauney,” she said, “I brought you three books, but I’m not going
to give them to you. They are just wild Indian stories of adventure.”
“Why did you buy that truck, my dear?” asked Day.
“Why, I really didn’t figure it out, Neville,” she laughed. “I
imagined Mauney about fourteen. But I’ll change them and send
them down.”
Mauney took the proffered hands of Day and his sister and then
his Aunt Mary’s. When his aunt was kissing him on the cheek, Neville
Day was clearing his throat and chewing at the end of a new cigar.
Soon the motor-car backed into the lane; then, with a sudden lurch
ahead, it snorted up the road, his aunt waving her hand in farewell.
Mauney watched it until it was engulfed in a dense cloud of dust and
the noise of its opened exhaust had quieted to a faint rumble. Then
he walked slowly up the lane toward the house.
By the kitchen door he encountered his father pumping himself a
tin ladleful of well water.
“Who was them people?” he demanded.
“Some tourists.”
“What’d they stop here for?”
“One of the women wanted to pick some blue weed by the side of
the road.”
“H’m! I wish to God she’d pick some of the blue weed out the
grain field,” he said. “Why did they turn around and go back?”
“They wanted to get to Lockwood before dark, I guess.”
Later in the evening, Mauney sat on the kitchen verandah lost in
thought. He leaned back in his tilted chair and rested his head on
the window-sill. Presently he fell asleep. He was awakened by a
sharp sensation on his chin.
“What’s the matter?” he asked, opening his eyes to see the hired
girl standing near him, smiling broadly.
“I just pulled one of them hairs out o’ your chin, Maun,” she
laughed. “When are yuh goin’ to start to shave ’em?”

CHAPTER IV
The Harvest Moon
“A rustic roughness”—Horace, Ep. Book I.

The story he had heard from his aunt, with its unexplained gaps,
filled Mauney’s mind for days. He wondered most about what she
had not told him. Her seemingly instinctive fear—or was it scorn?—
of meeting his father roused torturing curiosity. Probably his
mother’s letters had told her either plainly or in suggestive language
of her great unhappiness.
The motor-car visit haunted him. It was so unnatural, as though,
in a painful dream, he had beheld his own mother, whose features
were to remain before him in waking hours. Spectre-like out of the
unknown world she had come, to vanish immediately, leaving scant
comfort, herself immune from his ardent desire to detain her.
The incident was characteristic of life, as he was learning to know
it, for he gained cognizance of an enigmatical curse aimed at
whatever promised happiness. One whom even a few moments had
enshrined in his affections must tremble and disappear, as a delicate
bird, hovering for an instant, is driven away by a sight or smell.
Every aspiration of his existence was leashed to his father’s stolid
nature. He traced the deterring thongs, one by one, back to the
paternal influence. Some hidden action or some unrevealed quality
of his father’s had driven his aunt away in a dust-cloud. And the dust
which rose up to obscure her loved face was symbolic, for dust of a
kind was slowly settling upon the freshness of his own nature.
One evening his reverie of unhappiness was broken by a familiar
voice when, turning about, he beheld David McBratney trudging
along with a large, grey, telescope valise. In answer to his question,
McBratney replied that he was starting on foot for Lockwood, where
next morning he would take the train for Merlton to begin his
ministerial studies. He was walking because his father, suffering from
ill-humor, had refused him a horse. But evidently, there was no
martyrdom about the situation.
“He’s an old man,” Dave said, putting down his burden and wiping
his forehead with a big, red handkerchief, “and I didn’t like to start
no row.”
“Are you going for good?” Mauney asked, rising from the grass
and walking slowly to the edge of the road.
“Sure. I sold my three-year-old yesterday for a hundred, and
that’ll keep me for a while up to Merlton. I guess Dad will come
around after a while. But I reckon I’d just blow away, quiet like,
without causin’ too much commotion.”
“You’re a cheerful cuss, Dave,” Mauney said.
“You bet,” he laughed, as he turned to look back toward his home.
“I tell yuh, Maun, when a fellah gets sort o’ squared away with God
Almighty, why, he can’t be no other way. Some o’ the neighbors says
I’m makin’ a big mistake to leave the farm. But that farm ain’t
nothin’ to me now. Maybe I won’t never have a bit o’ land to me
name, but, I’m tellin’ yuh, I’ve got somethin’ as more’n makes up.
Well, Maun, old boy,” he said, picking up his valise and sticking out
his big, sun-burned hand. “I’ll be goin’ along. Good-bye. Best of luck
to yuh!”
For minutes Mauney stood thoughtfully watching his retreating
figure as, swinging into a long stride, he covered the first lap of his
long walk to Lockwood. His big figure grew smaller and smaller and
the valise dwindled to a little grey speck, but he never turned to look
back and soon he was lost in a bend of the road.
Although Mauney disliked in McBratney, what he considered half-
familiar references to the Creator, he distinctly admired his courage
and did not hesitate to express his admiration next day at supper
when the subject came up. Evidently Bard had called at the
McBratney’s that afternoon on his way from Beulah.
“The old man’s all broke up,” he said. “Poor old chap. There he is
right in the middle of the hayin’ with nobody to help him, and Dave
walks right out an’ leaves him. He might ’a’ stayed till the first o’
August, anyway.”
“I guess Dave’s got it pretty bad, Dad,” William remarked as he
spread a large chunk of butter over his bread. “Anybody that’ll start
out an’ walk to Lockwood on a hot night, carrying a big grip, why,
there’s somethin’ wrong with his brains. I never figured Dave’d be
such a damned fool!”
Mauney looked up sharply at his brother.
“He isn’t a damned fool!” he said flushing. “I may not have any
more use for religion than you have, Bill, but I admire any fellow
who does what he thinks is right!”
“Is that so?” scoffed William, glaring across the table. “Well, now
look here, freshie—”
Mauney, inflamed by the word, as well as by his brother’s sneering
manner, jumped to his feet, and became the centre of attention.
“I refuse to be called ‘freshie’ by you,” he said with some effort at
restraint, “and I have just enough sympathy with Dave McBratney
that I’m not going to have you call him a damned fool, either!”
Bard pounded the table.
“Here, sit down, Maun,” he commanded and then turned with a
faint smile toward his elder son. “Bill, eat your victuals and be quiet.
O’ course,” he added presently, “there ain’t no doubt but what Dave
is a damned fool, and he’s goin’ to wake up one o’ these days and
find it out, too. But now he’s gone away I don’t see what the old
man’s goin’ to do. I advised him to sell out the farm and go up to

You might also like