100% found this document useful (3 votes)
49 views

Download Complete Arduino in Science: Collecting, Displaying, and Manipulating Sensor Data 1st Edition Richard J. Smythe PDF for All Chapters

Arduino

Uploaded by

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

Download Complete Arduino in Science: Collecting, Displaying, and Manipulating Sensor Data 1st Edition Richard J. Smythe PDF for All Chapters

Arduino

Uploaded by

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

Download Full Version ebook - Visit ebookmeta.

com

Arduino in Science: Collecting, Displaying, and


Manipulating Sensor Data 1st Edition Richard J.
Smythe

https://ebookmeta.com/product/arduino-in-science-collecting-
displaying-and-manipulating-sensor-data-1st-edition-richard-
j-smythe/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmeta.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

Arduino Measurements in Science: Advanced Techniques and


Data Projects 1st Edition Richard J. Smythe

https://ebookmeta.com/product/arduino-measurements-in-science-
advanced-techniques-and-data-projects-1st-edition-richard-j-smythe/

ebookmeta.com

Advanced Arduino Techniques in Science: Refine Your Skills


and Projects with PCs or Python-Tkinter 1st Edition
Richard J. Smythe
https://ebookmeta.com/product/advanced-arduino-techniques-in-science-
refine-your-skills-and-projects-with-pcs-or-python-tkinter-1st-
edition-richard-j-smythe/
ebookmeta.com

Cambridge IGCSE and O Level History Workbook 2C - Depth


Study: the United States, 1919-41 2nd Edition Benjamin
Harrison
https://ebookmeta.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-
benjamin-harrison/
ebookmeta.com

Werner Herzog 1st Edition Joshua Lund

https://ebookmeta.com/product/werner-herzog-1st-edition-joshua-lund/

ebookmeta.com
The Truth About Dolphins 1st Edition Eaton

https://ebookmeta.com/product/the-truth-about-dolphins-1st-edition-
eaton/

ebookmeta.com

Opposing Australia’s First Assisted Immigrants, 1832-42


1st Edition Melanie Burkett

https://ebookmeta.com/product/opposing-australias-first-assisted-
immigrants-1832-42-1st-edition-melanie-burkett/

ebookmeta.com

Trading Favors with the Girl Dad 1st Edition Piper Cook

https://ebookmeta.com/product/trading-favors-with-the-girl-dad-1st-
edition-piper-cook/

ebookmeta.com

The Measurement of Sensation A Critique of Perceptual


Psychophysics C. Wade Savage

https://ebookmeta.com/product/the-measurement-of-sensation-a-critique-
of-perceptual-psychophysics-c-wade-savage/

ebookmeta.com

The New Yearbook for Phenomenology and Phenomenological


Philosophy Volume 15 XV 2017 1st Edition Daniele De Santis
(Editor)
https://ebookmeta.com/product/the-new-yearbook-for-phenomenology-and-
phenomenological-philosophy-volume-15-xv-2017-1st-edition-daniele-de-
santis-editor/
ebookmeta.com
True Luna Chasing The White Wolf The White Wolf 2 1st
Edition Tessa Lilly

https://ebookmeta.com/product/true-luna-chasing-the-white-wolf-the-
white-wolf-2-1st-edition-tessa-lilly/

ebookmeta.com
TECHNOLOGY IN AC TION™

Arduino in
Science
Collecting, Displaying, and
Manipulating Sensor Data

Richard J. Smythe
Arduino in Science
Collecting, Displaying,
and Manipulating Sensor Data

Richard J. Smythe
Arduino in Science: Collecting, Displaying, and Manipulating Sensor Data
Richard J. Smythe
Wainfleet, ON, Canada

ISBN-13 (pbk): 978-1-4842-6777-6 ISBN-13 (electronic): 978-1-4842-6778-3


https://doi.org/10.1007/978-1-4842-6778-3

Copyright © 2021 by Richard J. Smythe


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole
or part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical
way, and transmission or information storage and retrieval, electronic adaptation, computer
software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a
trademark symbol with every occurrence of a trademarked name, logo, or image we use the
names, logos, and images only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms,
even if they are not identified as such, is not to be taken as an expression of opinion as to
whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the
date of publication, neither the authors nor the editors nor the publisher can accept any
legal responsibility for any errors or omissions that may be made. The publisher makes no
warranty, express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Natalie Pao
Development Editor: James Markham
Coordinating Editor: Jessica Vakili
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1
NY Plaza, New York, NY 10014. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science + Business Media Finance
Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for
reprint, paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our
Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub via the book's product page, located at www.apress.com/
978-­1-­4842-­6777-­6. For more detailed information, please visit http://www.apress.com/
source-­code.
Printed on acid-free paper
Table of Contents
About the Author�������������������������������������������������������������������������������xiii

About the Technical Reviewer������������������������������������������������������������xv


Acknowledgments����������������������������������������������������������������������������xvii
The Author’s Preface to Arduino in Science��������������������������������������xix

Chapter 1: Button Control of LED Illumination��������������������������������������1


Experimental���������������������������������������������������������������������������������������������������������3
Hardware���������������������������������������������������������������������������������������������������������4
Circuit Schematic: DAQFactory and LabJack Combination�����������������������������5
Software����������������������������������������������������������������������������������������������������������6
Observations, Testing, and Development�������������������������������������������������������15
Discussion�����������������������������������������������������������������������������������������������������17
Raspberry Pi, Python, Screen Push Button LED Control��������������������������������������18
Experimental�������������������������������������������������������������������������������������������������19
Observations��������������������������������������������������������������������������������������������������21
Discussion�����������������������������������������������������������������������������������������������������23
Code Listings������������������������������������������������������������������������������������������������������23
Summary������������������������������������������������������������������������������������������������������������25

Chapter 2: Power Control, Monitoring, and Creation of


Dedicated Graphical User Interfaces��������������������������������������������������27
Experimental�������������������������������������������������������������������������������������������������������29
Hardware������������������������������������������������������������������������������������������������������������32
Software��������������������������������������������������������������������������������������������������������������33

iii
Table of Contents

Page Components Required��������������������������������������������������������������������������������34


Observations, Testing, and Development������������������������������������������������������������36
Discussion�����������������������������������������������������������������������������������������������������������38
Power Monitoring and Control with Raspberry Pi�����������������������������������������������50
Experimental�������������������������������������������������������������������������������������������������������52
Observations�������������������������������������������������������������������������������������������������������54
Discussion�����������������������������������������������������������������������������������������������������������55
Code Listings������������������������������������������������������������������������������������������������������56
Summary������������������������������������������������������������������������������������������������������������74

Chapter 3: Introduction to Scripting���������������������������������������������������75


Experimental�������������������������������������������������������������������������������������������������������76
Hardware�������������������������������������������������������������������������������������������������������77
Software��������������������������������������������������������������������������������������������������������77
Scripting��������������������������������������������������������������������������������������������������������79
Observations�������������������������������������������������������������������������������������������������������80
Discussion�����������������������������������������������������������������������������������������������������������80
DAQFactory Sequences: Arduino LED Array��������������������������������������������������������81
Experimental�������������������������������������������������������������������������������������������������������82
Discussion�����������������������������������������������������������������������������������������������������������83
Raspberry Pi��������������������������������������������������������������������������������������������������������83
Code Listings������������������������������������������������������������������������������������������������������85
Summary������������������������������������������������������������������������������������������������������������92

Chapter 4: Data Entry from the Screen�����������������������������������������������93


Hardware������������������������������������������������������������������������������������������������������������94
Software��������������������������������������������������������������������������������������������������������������96
Page Components Required��������������������������������������������������������������������������96

iv
Table of Contents

Scripting������������������������������������������������������������������������������������������������������������103
Observations������������������������������������������������������������������������������������������������103
Discussion���������������������������������������������������������������������������������������������������104
Screen Entry of Data with the Arduino Microcontroller������������������������������������105
Experimental�����������������������������������������������������������������������������������������������106
Observations������������������������������������������������������������������������������������������������109
Discussion���������������������������������������������������������������������������������������������������109
Raspberry Pi: Screen Entry of Data�������������������������������������������������������������������110
Code Listings����������������������������������������������������������������������������������������������������112
Summary����������������������������������������������������������������������������������������������������������129

Chapter 5: Digital Signal Concepts and Digital Signal Outputs��������131


Experimental�����������������������������������������������������������������������������������������������������132
Hardware�����������������������������������������������������������������������������������������������������132
Software������������������������������������������������������������������������������������������������������134
Observations������������������������������������������������������������������������������������������������136
Discussion���������������������������������������������������������������������������������������������������136
DAQFactory Digital Output Exercise with a Microcontroller
LED Demonstration Array����������������������������������������������������������������������������������137
Experimental�����������������������������������������������������������������������������������������������137
Observations������������������������������������������������������������������������������������������������138
Discussion���������������������������������������������������������������������������������������������������138
Raspberry Pi������������������������������������������������������������������������������������������������������139
Code Listings����������������������������������������������������������������������������������������������������141
Summary����������������������������������������������������������������������������������������������������������151

v
Table of Contents

Chapter 6: Analog or Digital Conversions for Input and Output�������153


Digital-to-Analog Conversions��������������������������������������������������������������������������157
Experimental: LabJack-DAQFactory Decimal-to-Binary Conversions���������������158
Hardware�����������������������������������������������������������������������������������������������������158
Software������������������������������������������������������������������������������������������������������158
Analog-to-Digital Conversions���������������������������������������������������������������������159
Observations������������������������������������������������������������������������������������������������162
DAQFactory–LabJack HMI Analog-to-Digital Numerical Base Conversions ������162
Analog-to-Digital Electronic Signal Conversions�����������������������������������������163
ADC0804: 8-Bit Binary LED Display�������������������������������������������������������������163
Discussion���������������������������������������������������������������������������������������������������165
Analog-to-Digital Conversions with Microcontrollers���������������������������������������168
Experimental�����������������������������������������������������������������������������������������������169
Observations������������������������������������������������������������������������������������������������174
Discussion���������������������������������������������������������������������������������������������������175
Diagnostics for Nonresponsive Displays�����������������������������������������������������175
System Development and Programming�����������������������������������������������������176
Analog and Digital Conversions for Input and Output with Raspberry Pi����������177
Binary-Decimal Conversions�����������������������������������������������������������������������177
ADC with Raspberry Pi��������������������������������������������������������������������������������������178
Experimental�����������������������������������������������������������������������������������������������179
Observations������������������������������������������������������������������������������������������������180
Discussion���������������������������������������������������������������������������������������������������182
Code Listings����������������������������������������������������������������������������������������������������185
Code Listings for Raspberry Pi��������������������������������������������������������������������199
Summary����������������������������������������������������������������������������������������������������������207

vi
Table of Contents

Chapter 7: Variable Intensity and Power Control������������������������������209


Experimental�����������������������������������������������������������������������������������������������������211
Variable Voltage Control������������������������������������������������������������������������������211
Observations������������������������������������������������������������������������������������������������216
Discussion���������������������������������������������������������������������������������������������������216
Experimental�����������������������������������������������������������������������������������������������������217
Pulse Width Modulation of Voltage��������������������������������������������������������������217
Observations������������������������������������������������������������������������������������������������218
Discussion���������������������������������������������������������������������������������������������������221
Raspberry Pi Variable Intensity Control�������������������������������������������������������������222
Introduction�������������������������������������������������������������������������������������������������222
Experimental�����������������������������������������������������������������������������������������������������224
PWM Signals with the RPi.GPIO Library�������������������������������������������������������224
Observations������������������������������������������������������������������������������������������������228
Code Listings����������������������������������������������������������������������������������������������������232
Summary����������������������������������������������������������������������������������������������������������238

Chapter 8: Counting Events and Timing��������������������������������������������239


Software Time and Timing��������������������������������������������������������������������������������240
Basic Time Variables������������������������������������������������������������������������������������242
Scheduled Event Timer��������������������������������������������������������������������������������243
The Stopwatch Timer�����������������������������������������������������������������������������������244
Hardware Timing, Event Counting, and Frequency Determination��������������244
Experimental�����������������������������������������������������������������������������������������������������248
Hardware�����������������������������������������������������������������������������������������������������248
Circuit Schematic����������������������������������������������������������������������������������������248

vii
Table of Contents

Software������������������������������������������������������������������������������������������������������248
Scripting������������������������������������������������������������������������������������������������������250
Circuit����������������������������������������������������������������������������������������������������������251
Software������������������������������������������������������������������������������������������������������251
Observations�����������������������������������������������������������������������������������������������������252
Discussion���������������������������������������������������������������������������������������������������������252
Time Determination�������������������������������������������������������������������������������������252
Manual and Automated Event Counting������������������������������������������������������253
Hardware Time and Timing�������������������������������������������������������������������������������254
Experimental�����������������������������������������������������������������������������������������������257
Schematic����������������������������������������������������������������������������������������������������258
Observations�����������������������������������������������������������������������������������������������������258
Discussion���������������������������������������������������������������������������������������������������������258
Microcontroller Clocks, Timekeeping, and Event Counting�������������������������������261
Experimental�����������������������������������������������������������������������������������������������������262
Observations�����������������������������������������������������������������������������������������������������263
Discussion���������������������������������������������������������������������������������������������������������265
Counting Events and Timing with Python and Raspberry Pi�����������������������������265
Scheduling Events���������������������������������������������������������������������������������������268
Detecting and Counting Events�������������������������������������������������������������������270
Experimental�����������������������������������������������������������������������������������������������������273
Observations�����������������������������������������������������������������������������������������������������276
Discussion���������������������������������������������������������������������������������������������������������281
Code Listings����������������������������������������������������������������������������������������������������283
Raspberry Pi Program Code������������������������������������������������������������������������293
Summary����������������������������������������������������������������������������������������������������������303

viii
Table of Contents

Chapter 9: Graphical Data Recording�����������������������������������������������305


Experimental: Linear Graphical Data Recording������������������������������������������������307
Part 1: Hardware and Component Selection – Square Wave Output�����������307
Electronic Components Required����������������������������������������������������������������309
Circuit Schematic����������������������������������������������������������������������������������������309
Software������������������������������������������������������������������������������������������������������310
Page Components Required������������������������������������������������������������������������310
Part 1: Observations������������������������������������������������������������������������������������313
Experimental�����������������������������������������������������������������������������������������������������315
Part 2: Hardware and Component Selection – Triangular and
“Sawtooth” Outputs������������������������������������������������������������������������������������315
Part 2: Observations������������������������������������������������������������������������������������316
Part 3: Hardware and Component Selection – Dual-Slope
Triangular Waveform�����������������������������������������������������������������������������������318
Part 3: Observations������������������������������������������������������������������������������������320
X-Y Data Recording�������������������������������������������������������������������������������������������321
Observations: x-y Plotting���������������������������������������������������������������������������������325
Discussion���������������������������������������������������������������������������������������������������������326
X vs. Time Recordings���������������������������������������������������������������������������������329
X-Y Recordings��������������������������������������������������������������������������������������������335
Microcontroller Data Plotting����������������������������������������������������������������������������335
Experimental�����������������������������������������������������������������������������������������������337
Observations������������������������������������������������������������������������������������������������338
Discussion���������������������������������������������������������������������������������������������������338
Graphical Data Recording with Python and the Raspberry Pi���������������������������340
Introduction�������������������������������������������������������������������������������������������������340
Experimental�����������������������������������������������������������������������������������������������341
Observations������������������������������������������������������������������������������������������������343
Discussion���������������������������������������������������������������������������������������������������346

ix
Table of Contents

Code Listing������������������������������������������������������������������������������������������������������348
Summary����������������������������������������������������������������������������������������������������������351

Chapter 10: Current Control��������������������������������������������������������������353


Constant Current Sources���������������������������������������������������������������������������������354
Experimental�����������������������������������������������������������������������������������������������������355
Hardware�����������������������������������������������������������������������������������������������������355
Circuit Schematic����������������������������������������������������������������������������������������356
Software������������������������������������������������������������������������������������������������������359
Observations�����������������������������������������������������������������������������������������������������359
Discussion���������������������������������������������������������������������������������������������������������360
Control of Larger DC Currents���������������������������������������������������������������������������362
Introduction�������������������������������������������������������������������������������������������������362
Brushless Direct Current (BLDC) Motors (Motors Without
Commutators or Sparking Brushes)������������������������������������������������������������362
Experimental�����������������������������������������������������������������������������������������������������363
Hardware�����������������������������������������������������������������������������������������������������363
Circuit Schematic����������������������������������������������������������������������������������������365
Software������������������������������������������������������������������������������������������������������367
Observations�����������������������������������������������������������������������������������������������������368
Discussion���������������������������������������������������������������������������������������������������������369
Stepper Motors��������������������������������������������������������������������������������������������370
Experimental�����������������������������������������������������������������������������������������������������372
Hardware�����������������������������������������������������������������������������������������������������372
Circuit Schematic����������������������������������������������������������������������������������������373
Software������������������������������������������������������������������������������������������������������376
Observations�����������������������������������������������������������������������������������������������������376
Discussion���������������������������������������������������������������������������������������������������������378

x
Table of Contents

Control of AC Current Sources��������������������������������������������������������������������������379


Introduction�������������������������������������������������������������������������������������������������379
Experimental�����������������������������������������������������������������������������������������������������382
Hardware�����������������������������������������������������������������������������������������������������382
Circuit Schematic����������������������������������������������������������������������������������������384
Software������������������������������������������������������������������������������������������������������386
Observations�����������������������������������������������������������������������������������������������������386
Discussion���������������������������������������������������������������������������������������������������������387
Current Control with Raspberry Pi and Python�������������������������������������������������390
Introduction�������������������������������������������������������������������������������������������������390
Control of Larger DC Currents���������������������������������������������������������������������390
Experimental�����������������������������������������������������������������������������������������������������392
Non-inductive Loads������������������������������������������������������������������������������������392
Observations�����������������������������������������������������������������������������������������������������395
Discussion���������������������������������������������������������������������������������������������������������395
Power Control to Inductive Loads���������������������������������������������������������������������397
Introduction�������������������������������������������������������������������������������������������������397
Experimental�����������������������������������������������������������������������������������������������398
Observations�����������������������������������������������������������������������������������������������������403
Discussion���������������������������������������������������������������������������������������������������������404
Control of AC Currents���������������������������������������������������������������������������������������405
Introduction�������������������������������������������������������������������������������������������������405
Experimental�����������������������������������������������������������������������������������������������������405
Observations�����������������������������������������������������������������������������������������������������407
Discussion���������������������������������������������������������������������������������������������������������408
Code Listings����������������������������������������������������������������������������������������������������409
Raspberry Pi–Python Codes������������������������������������������������������������������������409
Summary����������������������������������������������������������������������������������������������������������413

xi
Table of Contents

Chapter 11: Microcontrollers and Serial Communications���������������415


Experimental: Microprocessor to Host PC Communications – “Uploading”������419
Hardware�����������������������������������������������������������������������������������������������������422
Circuit Schematic����������������������������������������������������������������������������������������422
Software������������������������������������������������������������������������������������������������������423
Page Components Required������������������������������������������������������������������������428
Observations�����������������������������������������������������������������������������������������������������428
Discussion���������������������������������������������������������������������������������������������������������430
Experimental: Host PC to Microprocessor
Communications – “Downloading”�������������������������������������������������������������������432
Introduction�������������������������������������������������������������������������������������������������432
Hardware�����������������������������������������������������������������������������������������������������433
Software������������������������������������������������������������������������������������������������������433
Observations�����������������������������������������������������������������������������������������������������435
Discussion���������������������������������������������������������������������������������������������������������435
Raspberry Pi and Arduino���������������������������������������������������������������������������������436
Experimental�����������������������������������������������������������������������������������������������������437
Observations�����������������������������������������������������������������������������������������������������438
Discussion���������������������������������������������������������������������������������������������������������440
Code Listings����������������������������������������������������������������������������������������������������441
Summary����������������������������������������������������������������������������������������������������������447

Appendix A: List of Abbreviations����������������������������������������������������449

Appendix B: List of Suppliers�����������������������������������������������������������459

Index�������������������������������������������������������������������������������������������������461

xii
About the Author
Richard J. Smythe attended Brock University
in its initial years of operation in southern
Ontario and graduated with a four-year
honors degree in chemistry with minors in
mathematics and physics. He then attended
the University of Waterloo for a master’s
degree in analytical chemistry and computing
science and a doctorate in analytical
chemistry. After a post-doctoral fellowship at
the State University of New York at Buffalo in
electro-analytical chemistry, Richard went into
business in 1974 as Peninsula Chemical Analysis Ltd. Introduced in 1966
to time-shared computing with paper tapes, punched cards, and BASIC
prior to Fortran IV at Waterloo, as well as the PDP 11 mini-computers and
finally the PC, Richard has maintained a currency in physical computing
using several computer languages and scripting codes. Professionally,
Richard has functioned as a commercial laboratory owner and is currently
a consulting analytical chemist, a civil forensic scientist as PCA Ltd., a
full partner in Walters Forensic Engineering in Toronto, Ontario, and
senior scientist for Contrast Engineering Limited in Halifax, Nova Scotia.
A large portion of Richard’s professional career consists of devising
methods by which a problem that ultimately involves making one or more
fundamental measurements can be solved by using the equipment at hand
or using a readily available “off-­the-­shelf/out-of-the-box” facility to provide
the data required.

xiii
About the Technical Reviewer
Roland Meisel holds a B. Sc. in physics from
the University of Windsor, a B. Ed. from
Queen’s University specializing in physics
and mathematics, and an M. Sc. in physics
from the University of Waterloo. He worked
at Chalk River Nuclear Laboratories before
entering the world of education. He spent
twenty-eight years teaching physics,
mathematics, and computer science in the
Ontario secondary school system. After retiring from teaching as the head
of mathematics at Ridgeway Crystal Beach High School, he entered the
world of publishing, contributing to mathematics and physics texts from
pre-algebra to calculus in various roles, including technology consultant,
author, interactive web files (which he conceived, created, published and
edited), and photography. He remains active in several organizations,
including the Ontario Association of Physics Teachers, the Ontario
Association of Mathematics Educators, the Canadian Owners and Pilots
Association, and the Wainfleet Historical Society.
He has always had a strong interest in technology, mail-ordering
his first personal computer, an Apple II with a 1 MHz CPU and 16 kB of
memory, from California in 1979. At leisure, he can be found piloting small
airplanes, riding his bicycle or motorcycle, woodworking, reading, or
playing the piano, among other instruments.

xv
Acknowledgments
Acknowledgments begin with my late parents, Richard H. Smythe and
Margaret M. Smythe (née Earle), who emigrated from the remains of
London, England, after the war with their small family of three and
eventually raised four siblings in Canada. Our parents instilled in us the
need to be educated as much as possible in order for each of us to be self-­
sufficient and independent. That independence has led to the comfortable
retirement of the middle two and to the youngest continuing in her chosen
occupation for close to a decade past retirement and the oldest to still be
actively engaged in the business of chemical analysis consulting and the
practice of civil forensic science.
Along the way, numerous individuals have served as an inspiration
while teaching and mentoring me, imparting knowledge, the art of rational
thinking, tenacity, and in most cases valuable wisdom:
From Merritton High School in St. Catharines, Ontario:
Mrs. E. Glyn-Jones, mathematics; Mr. J. A. Smith, principal; and Mr.
E. Umbrico, physics
From Brock University in St. Catharines, Ontario:
Prof. E. A. Cherniak, Prof. R. H. Hiatt, Prof. F. Koffyberg, and Prof. J. M.
Miller
From the University of Waterloo in Waterloo, Ontario:
Prof. G. Atkinson
From the State University of New York at Buffalo:
Prof. S. Bruckenstein
It may also be said that the seeds for the growth and development of
this work began when as a parent I made sure that both my daughters,
Wendy and Christie, could read at a very early age and devised graphic
teaching aids for them to learn and understand binary digital arithmetic.

xvii
Acknowledgments

Acknowledgments would not be complete without recognizing


the person who has allowed me the time required to write, in spite of
life’s everyday chaos in the country, my spouse, Linda. She has suffered
through many years of papers, notes, books, breadboards, wires, electronic
components, and desktop experiments scattered everywhere in our home
and, when she wasn’t looking, on the kitchen table! Thank you, my love.
Although my career consists of solving essentially chemistry-based
problems and writing reports explaining how the problem came into
existence and how to correct its effects or avoid its re-occurrence, I have
never written a book. This work would not be possible without the help
and guidance of editors at Apress, Ms. Natalie Pao, Ms. Jessica Vakili, and
Mark Powers.

xviii
The Author’s Preface to
Arduino in Science
Arduino in Science is written to provide an introduction to the basic
techniques that can be used by individuals to engage in experimental
science. It is hoped that the manuscript can assist students and those new
to or with limited backgrounds in electro-mechanical techniques or the
physical sciences, to devise and conduct the experiments they need to
further their research or education. It is also hoped that the manuscript
will be useful where there are limited financial resources available for the
development of experimental designs and experimental or educational
programs.
Migrating or foraging animals and insects use daylight, near- infrared
light, polarized light, celestial indicators, chemical traces in water, the
Earth’s magnetic field, and other aids to navigate over the Earth’s surface
in search of food or to return home to their breeding grounds. Astronomy,
biology, chemistry, geology/geography, mathematics, physics, and other
subjects through to zoology are human concepts and classifications
entirely unknown to the travelers of the animal world. There are parallels
between the animal kingdom’s usage of multiple scientific phenomena
of which they have no knowledge and current scientific investigations.
A significant amount of new scientific knowledge is being revealed by
investigators educated in one classifiable discipline using the unfamiliar
experimental techniques from another. Although written by an analytical
chemist, this manuscript is a compilation of introductory basic techniques
applicable to any scientific discipline that requires the experimental
measurements of basic physio-chemical parameters.

xix
The Author’s Preface to Arduino in Science

The author is an experimental analytical chemist who has worked


with vacuum tubes, transistors, integrated circuits, main frame, mini-­
computers, microcomputers, and microcontrollers, while computing
technology transitioned from BASIC, Fortran, and variations of C to
iterations of the open source systems such as Python, Processing (the basis
of the Arduino microcontroller integrated development environment (IDE)
language), and Linux operating systems used in the Raspberry Pi. New and
revised versions of languages, IDEs, and operating systems are available
free of charge from the Internet and are constantly in a state of flux.
This work could be considered as being virtually obsolete as it is
being written, but as with the science and technology that it describes,
it is a starting point in an ever-changing subject. For the researcher and
practicing scientist, the fundamentals of science are relatively constant
and reasonably well understood, so a great deal of caution must be used
when deciding that a concept or technique is “obsolete.” The SCADA
concept and its development significantly predate the PC. Some of the
transistor and CMOS ICs and the 7400 series of integrated circuitry that
are in heavy use today date from the 1970s. Many chemical analysis and
physical measurement techniques, taught and in use today, date virtually
from the Middle Ages.
SCADA is the acronym for supervisory control and data acquisition.
SCADA software allows a computer to supervise an electro-mechanical
process and do so by acquiring data from sensors that are monitoring
the process being controlled. Many of the measurement techniques to be
discussed can be considered as single element components that are now
part of the developing technology being called the Internet of things (IOT)
with the Node-RED connectivity open source software.
HMI is the acronym for human-machine interface. The HMI can be
an electronic device or construct that provides an interface between a
computer, an experimental setup, and a human operator. (A graphical user
interface, GUI, may serve as an HMI.)

xx
The Author’s Preface to Arduino in Science

USB is the acronym for Universal Serial Bus that is, in reality, a written
standard of specifications to which electro-mechanical hardware systems
are expected to conform. The USB is a subsystem that lets a personal
computer communicate with devices that are plugged into the Universal
Serial Bus.
When a personal computer runs supervisory control and data
acquisition software with a human-machine interface connected via the
Universal Serial Bus system, then investigative science experiments or
other processes, experimental apparatus, or equipment setups, either “in
the field” miles away or “on the bench” next to the computer/workstation
or laptop, can be monitored and controlled in “real time.”
Laptops, stand-alone desktops, and cabled or wireless networked
workstations together with Internet connections now allow unprecedented
flexibility in laboratory or “in-field” monitoring of investigative science
experiments.
The options available to the experimentalist for implementing SCADA
systems can essentially be divided into three categories based upon the
amount of development work required to achieve a fully functional system.
Complete, finished, working software systems that are able to
measure and control virtually any electro-optical-mechanical system are
available from manufacturers such as National Instruments and Foxboro.
Commercially available fully functional, basic, software-only systems can
be expected to cost in the range of several thousands of dollars.
The author chose to develop this manuscript on three much-lower-­
cost options for SCADA implementation in experimental setups.
A moderate-cost implementation strategy, involving the following list
of resources, has been used to develop the exercises in this manuscript.
These resources should also be adequate for further experimental
development of new applications:

xxi
The Author’s Preface to Arduino in Science

1) A PC with SCADA software. Numerous systems


are available, and the DAQFactory Express and the
base-level DAQFactory version of the system from
AzeoTech have both been used in this manuscript
(cost for DAQFactory base-level software approx.
$250 CDN, 2008). There are freeware versions of
SCADA systems available for those who are able to
adapt the software and may require the extended
flexibility.

2) A USB HMI. Again there are many devices available


from many manufacturers, and the device chosen
for this manuscript is the model U12 from LabJack
Corporation. (U12 costs approx. $120. U3 was
added later, which costs approx. $110 USD.) The
LabJack devices are provided with software in
the form of a working version of the DAQFactory
program called “Express.” The LabJack-supplied
software is excellent with respect to its graphical
display capabilities and for many applications in
investigative sciences is more than adequate. The
DAQFactory Express is however limited to ten lines
of script code, five script sequences, and two display
pages. For some of the topics discussed and project
exercises described in this manuscript, the more
extensive capabilities of a commercial version of
the DAQFactory software may be required. If the
software is to be purchased, the reader should start
with the most basic program available and add
upgrades as required.

xxii
The Author’s Preface to Arduino in Science

3) The third option for experimentalists is the newest


and lowest-cost approach to the implementation of
a SCADA system that consists of the Raspberry Pi, its
Linux operating system, the Python programming
language with its matplot library, and the tkinter
graphical user interface. The Linux operating
system and Python and its modules are all open
source projects and hence free for download
from the Internet. The Raspberry Pi project has
made available the Raspberry Pi board that can
be purchased from many large electronics supply
houses such as DigiKey or Newark element14, to
name only two, for $35. The Raspberry Pi board
requires an HDMI-compatible TV or computer
monitor, mouse, and keyboard to form a fully
functional computing system. In addition to the
virtually no-cost software, the Raspberry Pi board
contains its own general-purpose input/output bus
in addition to its USB input/output connection and
hence contains its own HMI requiring no additional
circuitry or expense to be interfaced to external
electronics or experimental setups. The Raspberry
Pi board is manufactured with an Ethernet
connection and is thus network capable.

In 2008 an open source project called Arduino made available a series


of USB-connected microcontroller boards that allowed designers, artists,
hobbyists, and non-electronics specialists to interface electro-optical-­
mechanical devices to a computer. The basic Arduino Uno Rev3 board
can be purchased from any of the major electronics supply houses for
$25. The software to program the microcontroller board is another open
source project and is freeware that can be downloaded from the Internet.

xxiii
The Author’s Preface to Arduino in Science

The Arduino board can be used with Windows or Linux-based operating


systems and is fully supported with an online forum, many tutorials, and
an extensive range of example programs and applications.
Experimental investigations using SCADA-type implementations can
thus take the form of a complete commercially available package, useable
as received with no required development time, as a lesser-cost system
requiring a moderate amount of programming using the DAQFactory
program and commercial HMI devices such as the LabJack series of
interfaces or as an assemblage of very-low-cost hardware and open source
software freely available for download from the Internet.
In addition to the software and hardware required to implement the
monitoring and controlling system, additional ancillary equipment may be
required in the form of the following list:

1) A solderless breadboard system, appropriate power


sources such as battery or electronic regulated
supplies, and access to various IC and passive
electronic components are required.

2) For troubleshooting, a multimeter is required; and


for more advanced work, an oscilloscope, either
stand-alone or an oscilloscope program for a PC,
may be required.

It is suggested that the reader, new to this technology, work through the
manuscript in order of presentation so as to gain practice and confidence
with software, wiring, and increasing project complexity. The basics
of scripting software, hardware interfacing, electronics fundamentals,
and IC usage will all progressively become more complex; and the basic
knowledge and procedures established in the earlier exercises will not be
repeated in the more advanced projects. All science is empirical in nature,
and this manuscript is no different than real-life scientific work. The
investigator must progress from the simple to the more complicated facets

xxiv
The Author’s Preface to Arduino in Science

of the project at hand, verifying and validating each intermediate step in a


multiple-stage measurement process.
The rate at which the individual can progress through the various
topics presented will be dependent upon their knowledge of the basic
physical sciences that form the core of the exercises. If difficulty is
encountered, textbooks, online tutorials, and academic course outlines
with exercises can be located to further aid in understanding the required
base knowledge.
As the title states, this manuscript deals essentially with monitoring
and measuring physical-chemical parameters with integrated circuitry and
physical computational systems. In this work, inexpensive “off-the-shelf
components” are used to monitor and control experimental setups that
are able to measure data in the form of basic physio-chemical parameters
of interest to investigators in many of the classified sciences, with in some
cases astounding sensitivity, flexibility, accuracy, and precision.
Disclaimer

1) 110-volt electricity can be lethal and will start fires.

2) Soldering irons are hot enough to cause serious


burns.

3) This document is for educational purposes only


and presents concepts that are demonstrated
through experimental formats. These experimental
setups have not been tested for robustness and
are not designed or intended for any form of
implementation in field service. These concepts
are the basis for education only and are intended
as being starting points for further R&D into
instrumental methods of monitoring experimental
scientific apparatus for the purposes of gathering
data or making physical measurements.

xxv
The Author’s Preface to Arduino in Science

4) The concept for this work came to the author in


the mid-1960s, and in the interim years, various
portions of this work were developed with the
technology available at the time, while other
concepts were found to be unworkable. Although
formal assembly of this document was begun
in 2008 and 2009 using the integrated circuitry,
physical computing, and Internet information
resources available at that time, the document
continues to develop as it is being written using new
integrated circuits, physical computing software,
and online information sources. The continued
availability of either software or electro-mechanical
hardware can never be assured, and hence the
practitioners of this or any science must learn the art
of “a work-around.”

Exercise Road Map


As noted in the Preface, this work is not intended to be a first or
ab initio introduction to data collection. Although motivated or
enthusiastic investigators can plunge right in and try to pick up needed
knowledge and skills on the fly, the guide is aimed at those who have at
least some experience in working with electronic hardware and computer
software. A basic familiarity with simple electronics as well as some
elementary programming in a structured language such as Python or C++
will shorten the time required to complete the various exercises.

xxvi
The Author’s Preface to Arduino in Science

The manufacturer’s literature for most of the data collection hardware


referred to in this guide provides guidance and elementary activities to
help familiarize the new user with its implementation. Online sources can
also provide numerous practical applications of the hardware at hand.
Once the experimenter is comfortable with the hardware and software
exercises described in this work, the experimental measurement of many
basic scientific parameters can be made in accordance with the methods
detailed in the next book in this series, Arduino Measurements in Science.
This work is devoted to developing the techniques that can be used
for making experimental physio-chemical measurements with equipment
assembled from readily available components, materials, and most small
desktop or portable computing systems. This manuscript is an attempt to
provide written methodologies by which fundamental measurements can
be made by investigators of varying levels of familiarity with electronics,
electro-optical, and simple mechanical systems. A series of experimental
measurement procedures are developed as a prelude for being able
to make the basic measurements of parameters such as temperature,
distance, light intensity, sound frequency, relative humidity, and other
fundamental measurements in basic science.
Each of the chapters develops a method or technique that can
ultimately be used to assemble a testing or measurement method or
procedure consisting of the various methodologies developed.

Exercise Format
Experimental
Hardware
Software
Observations
Discussion
Code Listings

xxvii
The Author’s Preface to Arduino in Science

Project Management
When working through each of the exercises in the various chapters, the
following procedures are suggested:

1) In preparation for the assembly of an experimental


exercise or project described in a chapter, review the
manuscript information and collect the published
work relevant to the exercise such as manufacturer’s
data sheets for the components in use. This will
serve to add to the depth of knowledge available to
the investigator and may avoid component damage.
Rough notes and drawings should be collected
together into a notebook (either on paper or in an
electronic format).

2) Begin assembling the hardware/electronics and


corresponding software from the simplest unit
operations of the project, debugging the individual
modules and then verifying operational status until
the entire project functions as designed.

3) Caution is required in reading schematic diagrams


and attempting to duplicate their assembly as
certain discrete components and integrated
circuitry are constantly decreasing in physical
size or are replaced with newer technology. The
decrease in size means that identification markings
on components are getting smaller also.

Resistance and capacitor markings may appear in several formats


as combinations of numbers and letters with the magnitude symbol
sometimes replacing the decimal point. Surface mount technologies (SMTs)
have a three-digit code in which the first two digits are the value and the
third is the power of 10 of the value multiplier.

xxviii
The Author’s Preface to Arduino in Science

Resistors’ unit of measure is ohms, symbol Ω.


M is 106 or 1,000,000 ohms, and typical identifications may be 1.5 M or
1M5.
K is 103 or 1,000 ohms, and typical identifications may be 1.2 K or 1K2.
R is 100 or 1 or unit ohms, and typical identifications may be 100 R or
just 100 as there is no decimal point to replace.
m is 10-3 or 1/1000 ohms, and 0.052 Ω is written as 52 mΩ.
Capacitance units in older works were mainly limited to micro- and
picofarad designations, and the range of nano- was covered either by
thousands of pico- or thousands of microfarads. Most current capacitor
notation usage seems to adhere to the three main fractional designations
listed in the following but has recently been expanded to include the Farad
to avoid using thousands and millions of the micro- term when describing
ultra- and super-capacitor devices.
Capacitors’ unit of measurement is Farads, symbol F.
u is microfarad and is 10-6 Farads.
n is nanofarad and is 10-9 Farads.
p is picofarad and is 10-12 Farads.
The exercises in this book use very simple electrical circuits that will
be assembled on a “breadboard” and connected to the LabJack HMI,
DAQFactory Express system, Arduino microcontroller–DAQFactory
combination, or directly to the Raspberry Pi or RPi-Arduino systems
to provide an interface between the working electronic circuit and
a computer-generated GUI. Each of these combinations allows the
experimenter to exercise supervisory control, acquire data, or monitor a
data stream trend, through a software, user interface screen. There is no
better way to gain experience with electro-mechanical control systems
than to mechanically assemble circuits and test and establish their
functioning, before configuring software for data acquisition (DAQ) and
hardware control. As a general rule, the hardware is assembled, tested, and
validated before one moves on to interfacing and software development.

xxix
The Author’s Preface to Arduino in Science

The following discussion uses the first of the exercises as an example


of the general methodology that will be used for the rest of the exercises.
Each exercise in this work is generally set out in the traditional laboratory
format, and it is assumed that this general section has been read and is
understood by the researcher.
When working with electrical signals from a sensor or experimental
apparatus, ensure that the output voltage level does not exceed the input
voltage capability of the electronic components being used to process the
signal. Most discrete integrated circuitry is limited to 5 volts, some op-­
amps will operate at up to 18 volts, and most surface mount technologies
operate at a nominal 3.3 volts.
As with all scientific endeavors, a logical progression should be made
from the simplest to the more complex. When developing the software for
the project at hand, the experimenter should begin with the code required
to connect the apparatus to the computing and display circuitry.
The simplest form of electrical signal transmission uses a series
connection for both analog and digital signals.
Analog voltage signals are often connected directly to the input pins
of integrated circuits that provide some form of signal processing, while
digital signals are connected to pins that sense whether the signal is high
or low. In general terms, a large portion of sensor outputs are voltage
based, but current sensing is also used in some sensor measurements.
Computational circuitry usually accesses external data through a
“serial port.” The serial port is often a specific addressable location in
the computer memory that accepts incoming digital data according
to a specific encoding called a protocol. The protocol specifies the
meaning of the high-to-low or low-to-high transitions that make up the
digital signal with respect to timing, data values, and signal processing
control parameters. There are numerous scientific and industrial serial
transmission protocols designed and optimized for specific applications,
but the following exercises will be predominantly confined to the basics of
serial data transmission.

xxx
The Author’s Preface to Arduino in Science

The exercises can use the DAQFactory scripting language, Python, and
the variant of C used in Arduino programming. All three programming
languages have reserved keywords that cannot be used as variable
names. Follow the variable naming rule suggestions in the appropriate
documentation for the language in use. Create meaningful names by
following traditional C styles such as MySignificantName, MySgnfcntNme,
or My_Significant_Name. Do not use proper words such as “temperature”
or “Temperature” or any other word that may be a proper word used within
Python, DAQFactory scripting, C, or C++ programming code. Scripts
that contained proper words used as variable names or channels for
“clarity” by the author that failed to operate and produced baffling outputs
suddenly performed flawlessly when the proper words were re-keyed with
unique mixed upper- and lowercase characters. Follow the proper formal
methodology built into the software at hand. In the DAQFactory software,
creation of the channels first allows DAQFactory to populate the pop-up
intelligent listing of channels, variables, and constants to cut down on
error-prone typing. The primary step in all troubleshooting procedures
involving written coded systems that do not work is to check all spelling.
Names are case sensitive.
Keep detailed notes of what is being done, write down calculations,
sketch schematics and rough mechanical drawings. This is, after all,
science. The drawing conventions for mechanical systems and electronic
circuits can be found in several reference texts.1 The reader is encouraged
to follow these conventions.

1
1) Building Scientific Apparatus 4th Edn., Moore, Davis, and Coplan, Cambridge
University Press, ISBN 978-0-521-8785-6
2) The Art of Electronics 2nd Edn., Horowitz and Hill, Cambridge University Press,
ISBN 0-521-37095-7
3) Practical Electronics for Inventors 3rd Edn., Scherz and Monk, McGraw Hill
ISBN 978-0-07-177133-7

xxxi
Discovering Diverse Content Through
Random Scribd Documents
1
A’the boys of merry Linkim
War playing at the ba,
An up it stands him sweet Sir Hugh,
The flower amang them a’.

2
He keppit the ba than wi his foot,
And catchd it wi his knee,
And even in at the Jew’s window
He gart the bonny ba flee.

3
‘Cast out the ba to me, fair maid,
Cast out the ba to me!’
‘Ah never a bit of it,’ she says,
‘Till ye come up to me.

4
‘Come up, sweet Hugh, come up, dear Hugh,
Come up and get the ba’!’
‘I winna come up, I mayna come [up],
Without my bonny boys a’.’

5
‘Come up, sweet Hugh, come up, dear Hugh,
Come up and speak to me!’
‘I mayna come up, I winna come up,
Without my bonny boys three.’

6
She’s taen her to the Jew’s garden,
Where the grass grew lang and green,
She’s pu’d an apple reid and white,
To wyle the bonny boy in.

7
She’s wyl’d him in thro ae chamber,
She’s wyl’d him in thro twa,
She’s wyl’d him till her ain chamber,
The flower out owr them a’.

8
She’s laid him on a dressin-board,
Whare she did often dine;
She stack a penknife to his heart,
And dressd him like a swine.

9
She rowd him in a cake of lead,
Bade him lie still and sleep;
She threw him i the Jew’s draw-well,
’Twas fifty fathom deep.

10
Whan bells was rung, and mass was sung,
An a’ man bound to bed,
Every lady got hame her son,
But sweet Sir Hugh was dead.
E
Motherwell’s Minstrelsy, p. 51, as taken down from the recitation
of a lady.
1
Yesterday was brave Hallowday,
And, above all days of the year,
The schoolboys all got leave to play,
And little Sir Hugh was there.

2
He kicked the ball with his foot,
And kepped it with his knee,
And even in at the Jew’s window
He gart the bonnie ba flee.

3
Out then came the Jew’s daughter:
‘Will ye come in and dine?’
‘I winna come in, and I canna come in,
Till I get that ball of mine.

4
‘Throw down that ball to me, maiden,
Throw down the ball to me!’
‘I winna throw down your ball, Sir Hugh,
Till ye come up to me.’

5
She pu’d the apple frae the tree,
It was baith red and green;
She gave it unto little Sir Hugh,
With that his heart did win.

6
She wiled him into ae chamber,
She wiled him into twa,
She wiled him into the third chamber,
And that was warst o’t a’.

7
She took out a little penknife,
Hung low down by her spare,
She twined this young thing o his life,
And a word he neer spak mair.

8
And first came out the thick, thick blood,
And syne came out the thin,
And syne came out the bonnie heart’s blood,
There was nae mair within.

9
She laid him on a dressing-table,
She dressd him like a swine;
Says, Lie ye there, my bonnie Sir Hugh,
Wi yere apples red and green!

10
She put him in a case of lead,
Says, Lie ye there and sleep!
She threw him into the deep draw-well,
Was fifty fathom deep.

11
A schoolboy walking in the garden
Did grievously hear him moan;
He ran away to the deep draw-well,
And fell down on his knee.

12
Says, Bonnie Sir Hugh, and pretty Sir Hugh,
I pray you speak to me!
If you speak to any body in this world,
I pray you speak to me.

13
When bells were rung, and mass was sung,
And every body went hame,
Then every lady had her son,
But Lady Helen had nane.

14
She rolled her mantle her about,
And sore, sore did she weep;
She ran away to the Jew’s castle,
When all were fast asleep.

15
She cries, Bonnie Sir Hugh, O pretty Sir Hugh,
I pray you speak to me!
If you speak to any body in this world,
I pray you speak to me.

16
‘Lady Helen, if ye want your son,
I’ll tell ye where to seek;
Lady Helen, if ye want your son,
He’s in the well sae deep.’

17
She ran away to the deep draw-well,
And she fell down on her knee,
Saying, Bonnie Sir Hugh, O pretty Sir Hugh,
I pray ye speak to me!
If ye speak to any body in the world,
I pray ye speak to me.

18
‘Oh the lead it is wondrous heavy, mother,
The well it is wondrous deep;
The little penknife sticks in my throat,
And I downa to ye speak.

19
‘But lift me out o this deep draw-well,
And bury me in yon churchyard;
. . . . . . . .
. . . . . . .

20
‘Put a Bible at my head,’ he says,
‘And a Testament at my feet,
And pen and ink at every side,
And I’ll lie still and sleep.

21
‘And go to the back of Maitland town,
Bring me my winding sheet;
For it’s at the back of Maitland town
That you and I shall meet.’

22
O the broom, the bonny, bonny broom,
The broom that makes full sore,
A woman’s mercy is very little,
But a man’s mercy is more.
F
Hume’s Sir Hugh of Lincoln, p. 35, obtained from recitation in
Ireland.
1
’Twas on a summer’s morning
Some scholars were playing at ball,
When out came the Jew’s daughter
And leand her back against the wall.

2
She said unto the fairest boy,
Come here to me, Sir Hugh;
‘No! I will not,’ said he,
‘Without my playfellows too.’

3
She took an apple out of her pocket,
And trundled it along the plain,
And who was readiest to lift it
Was little Sir Hugh again.

4
She took him by the milk-white han,
An led him through many a hall,
Until they came to one stone chamber,
Where no man might hear his call.

5
She set him in a goolden chair,
And jaggd him with a pin,
And called for a goolden cup
To houl his heart’s blood in.

6
She tuk him by the yellow hair,
An also by the feet,
An she threw him in the deep draw-well;
It was fifty fadom deep.

7
Day bein over, the night came on,
And the scholars all went home;
Then every mother had her son,
But little Sir Hugh’s had none.

8
She put her mantle about her head,
Tuk a little rod in her han,
An she says, Sir Hugh, if I fin you here,
I will bate you for stayin so long.

9
First she went to the Jew’s door,
But they were fast asleep;
An then she went to the deep draw-well,
That was fifty fadom deep.

10
She says, Sir Hugh, if you be here,
As I suppose you be,
If ever the dead or quick arose,
Arise and spake to me.

11
‘Yes, mother dear, I am here,
I know I have staid very long;
But a little penknife was stuck in my heart,
Till the stream ran down full strong.

12
‘And mother dear, when you go home,
Tell my playfellows all
That I lost my life by leaving them,
When playing that game of ball.

13
‘And ere another day is gone,
My winding-sheet prepare,
And bury me in the green churchyard,
Where the flowers are bloomin fair.

14
‘Lay my Bible at my head,
My Testament at my feet;
The earth and worms shall be my bed,
Till Christ and I shall meet.’
G
a. Written down by Mrs Dulany, January 14, 1885, from the
recitation of her mother, Mrs Nourse, aged above ninety, as learned
when a child, in Philadelphia. b. From the same source, furnished
several years earlier by Miss Perine, of Baltimore.
1
It rains, it rains in old Scotland,
And down the rain does fa,
And all the boys in our town
Are out a playing at ba.

2
‘You toss your balls too high, my boys,
You toss your balls too low;
You’ll toss them into the Jew’s garden,
Wherein you darst not go.’

3
Then out came one of the Jew’s daughters,
All dressed in red and green:
‘Come in, come in, my pretty little boy,
And get your ball again.’

4
‘I winna come in, and I canna come in,
Without my playmates all,
And without the will of my mother dear,
Which would cause my heart’s blood to fall.’

5
She shewed him an apple as green as grass,
She shewed him a gay gold ring,
She shewed him a cherry as red as blood,
Which enticed the little boy in.

6
She took him by the lily-white hand,
And led him into the hall,
And laid him on a dresser-board,
And that was the worst of all.

7
She laid the Bible at his head,
The Prayer-Book at his feet,
And with a penknife small
She stuck him like a sheep.

8
Six pretty maids took him by the head,
And six took him by the feet,
And threw him into a deep draw-well,
That was eighteen fathoms deep.

* * * * *

9
‘The lead is wondrous heavy, mother,
The well is wondrous deep,
A keen pen-knife sticks in my heart,
And nae word more can I speak.’
H
Communicated by Miss Perine, of Baltimore, Maryland, as sung by
her mother about 1825.
1
It rains, it rains in fair Scotland,
It rains both great and small
. . . . . . .
. . . . . . .

2
He tossed the hall so high, so low,
He tossed the ball so low,
He tossed it over the Jew’s garden-wall,
Where no one dared to go.

3
Out came one of the Jew’s daughters,
All dressed in apple-green;
Said she, My dear little boy, come in,
And pick up your ball again.

4
‘I dare not come, I will not come,
I dare not come at all;
For if I should, I know you would
Cause my blood to fall.’

5
She took him by the lily-white hand,
And led him thro the kitchen;
And there he saw his own dear maid
A roasting of a chicken.

6
She put him in a little chair,
And pinned him with a pin,
And then she called for a wash-basin,
To spill his life blood in.

7
‘O put the Bible at my head,
And the Testament at my feet,
And when my mother calls for me,
You may tell her I’m gone to sleep.’
I
Sir E. Brydges, Restituta, I, 381, “obtained some years since”
(1814) from the recitation of an aged lady.
1
It rains, it rains in merry Scotland,
It rains both great and small,
And all the children in merry Scotland
Are playing at the ball.

2
They toss the ball so high, so high,
They toss the ball so low,
They toss the ball in the Jew’s garden,
Where the Jews are sitting a row.

3
Then up came one of the Jew’s daughters,
Cloathed all in green:
‘Come hither, come hither, my pretty Sir Hugh,
And fetch thy ball again.’

4
‘I durst not come, I durst not go,
Without my play-fellowes all;
For if my mother should chance to know,
She’d cause my blood to fall.’

* * * * *

5
She laid him upon the dresser-board,
And stuck him like a sheep;
She laid the Bible at his head,
The Testament at his feet,
The Catechise-Book in his own heart’s blood,
With a penknife stuck so deep.

* * * * *
J
a. Notes and Queries, First Series, XII, 496, B. H. C., from the
manuscript of an old lacemaker in Northamptonshire. b. N. and Q.,
First Series, VIII, 614, B. H. C., from memory, stanzas 1–6.
1
It rains, it rains in merry Scotland,
Both little, great and small,
And all the schoolfellows in merry Scotland
Must needs go play at ball.

2
They tossd the ball so high, so high,
With that it came down so low;
They tossd it over the old Jew’s gates,
And broke the old Jew’s window.

3
The old Jew’s daughter she came out,
Was clothed all in green:
‘Come hither, come hither, you young Sir Hugh,
And fetch your ball again.’

4
‘I dare not come, nor I will not come,
Without my schoolfellows come all;
For I shall be beaten when I go home
For losing of my ball.’

5
She ‘ticed him with an apple so red,
And likewise with a fig;
She threw him over the dresser-board,
And sticked him like a pig.

6
The first came out the thickest of blood,
The second came out so thin,
The third came out the child’s heart-blood,
Where all his life lay in.

7
‘O spare my life! O spare my life!
O spare my life!’ said he;
‘If ever I live to be a young man,
I’ll do as good chare for thee.’

8
‘I’ll do as good chare for thy true love
As ever I did for the king;
I will scour a basin as bright as silver
To let your heart-blood run in.’

9
When eleven o’clock was past and gone,
And all the school-fellows came home,
Every mother had her own child
But young Sir Hugh’s mother had none.

10
She went up Lincoln and down Lincoln,
And all about Lincoln street,
With her small wand in her right hand,
Thinking of her child to meet.

11
She went till she came to the old Jew’s gate,
She knocked with the ring;
Who should be so ready as the old Jew herself
To rise and let her in!

12
‘What news, fair maid? what news, fair maid?
What news have you brought to me?
. . . . . . .
. . . . . . .

13
‘Have you seen any of my child today,
Or any of the rest of my kin?’
‘No, I’ve seen none of your child today,
Nor none of the rest of your kin.’
K
Notes and Queries, First Series, IX, 320; taken down by S. P. Q.
from the recitation of a nurse-maid in Shropshire about 1810.
Salopian Shreds and Patches, July 21, 1875, in Miss Burne’s
Shropshire Folk-Lore, p. 539.
1
It hails, it rains, in Merry-Cock land,
It hails, it rains, both great and small,
And all the little children in Merry-Cock land
They have need to play at ball.

2
They tossd the ball so high,
They tossd the ball so low,
Amongst all the Jews’ cattle,
And amongst the Jews below.

3
Out came one of the Jew’s daughters,
Dressed all in green:
‘Come, my sweet Saluter,
And fetch the ball again.’

4
‘I durst not come, I must not come,
Unless all my little playfellows come along;
For if my mother sees me at the gate,
She’ll cause my blood to fall.

5
‘She showd me an apple as green as grass,
She showd me a gay gold ring;
She showd me a cherry as red as blood,
And so she entic’d me in.

6
‘She took me in the parlor,
She took me in the kitchen,
And there I saw my own dear nurse,
A picking of a chicken.

7
‘She laid me down to sleep,
With a Bible at my head and a Testament at my feet;
And if my playfellows come to quere for me,
Tell them I am asleep.’
L
a. Communicated in a letter from the Rev. E. Venables, Precentor
of Lincoln, as sung to him by a nurse-maid nearly sixty years ago,
January 24, 1885. A Buckinghamshire version. b. A Walk through
Lincoln Minster, by the Rev. E. Venables, p. 41, 1884.
1
It rains, it hails in merry Lincoln,
It rains both great and small,
And all the boys and girls today
Do play at pat the ball.

2
They patted the ball so high, so high,
They patted the ball so low,
They patted it into the Jew’s garden,
Where all the Jews do go.

3
Then out it spake the Jew’s daughter,
As she leant over the wall;
‘Come hither, come hither, my pretty play-fellow,
And I’ll give you your ball.’

4
She tempted him [in] with apple so red,
But that wouldnt tempt him in;
She tempted him in with sugar so sweet,
And so she got him in.

5
Then she put forth her lilly-white hand,
And led him through the hall:
‘This way, this way, my pretty play-fellow,
And you shall have your ball.’

6
She led him on through one chamber,
And so she did through nine,
Until she came to her own chamber,
Where she was wont to dine,
And she laid him on a dressing-board,
And sticket him like a swine.
d st c et eas e

7
Then out it came the thick, thick blood,
And out it came the thin,
And out it came the bonnie heart’s blood,
There was no more within.
M
F. H. Groome, In Gipsy Tents, 1880, p. 145: “first heard at
Shepherd’s Bush, in 1872, from little Amy North.”

You might also like