0% found this document useful (0 votes)
7 views

A Hands On Course in Sensors Using the Arduino and Raspberry Pi Series in Sensors 1st Edition Ziemann - Get the ebook in PDF format for a complete experience

The document provides information about various ebooks available for download on ebookmeta.com, including titles related to sensors using Arduino and Raspberry Pi, as well as other subjects like beekeeping and cancer management. It features a detailed overview of 'A Hands-On Course in Sensors Using the Arduino and Raspberry Pi' by Volker Ziemann, including its content structure and various chapters. Additionally, it includes links to other recommended digital products and outlines the publication details and copyright information.

Uploaded by

meshakcenill76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

A Hands On Course in Sensors Using the Arduino and Raspberry Pi Series in Sensors 1st Edition Ziemann - Get the ebook in PDF format for a complete experience

The document provides information about various ebooks available for download on ebookmeta.com, including titles related to sensors using Arduino and Raspberry Pi, as well as other subjects like beekeeping and cancer management. It features a detailed overview of 'A Hands-On Course in Sensors Using the Arduino and Raspberry Pi' by Volker Ziemann, including its content structure and various chapters. Additionally, it includes links to other recommended digital products and outlines the publication details and copyright information.

Uploaded by

meshakcenill76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

Read Anytime Anywhere Easy Ebook Downloads at ebookmeta.

com

A Hands On Course in Sensors Using the Arduino and


Raspberry Pi Series in Sensors 1st Edition
Ziemann

https://ebookmeta.com/product/a-hands-on-course-in-sensors-
using-the-arduino-and-raspberry-pi-series-in-sensors-1st-
edition-ziemann/

OR CLICK HERE

DOWLOAD EBOOK

Visit and Get More Ebook Downloads Instantly at https://ebookmeta.com


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

A Hands-On Course in Sensors Using the Arduino and


Raspberry Pi 2nd Edition Volker Ziemann

https://ebookmeta.com/product/a-hands-on-course-in-sensors-using-the-
arduino-and-raspberry-pi-2nd-edition-volker-ziemann/

ebookmeta.com

A Hands-On Course in Sensors Using the Arduino and


Raspberry Pi 2nd Edition Volker Ziemann

https://ebookmeta.com/product/a-hands-on-course-in-sensors-using-the-
arduino-and-raspberry-pi-2nd-edition-volker-ziemann-2/

ebookmeta.com

IoT Machine Learning Applications in Telecom, Energy, and


Agriculture: With Raspberry Pi and Arduino Using Python
1st Edition Puneet Mathur
https://ebookmeta.com/product/iot-machine-learning-applications-in-
telecom-energy-and-agriculture-with-raspberry-pi-and-arduino-using-
python-1st-edition-puneet-mathur/
ebookmeta.com

Polyphenols based Nanotherapeutics for Cancer Management

https://ebookmeta.com/product/polyphenols-based-nanotherapeutics-for-
cancer-management/

ebookmeta.com
Beekeeping For Dummies Blackiston

https://ebookmeta.com/product/beekeeping-for-dummies-blackiston/

ebookmeta.com

A Family for Garrett Forever Safe The Twelve Days of


Christmas 1st Edition Haven Rose

https://ebookmeta.com/product/a-family-for-garrett-forever-safe-the-
twelve-days-of-christmas-1st-edition-haven-rose-3/

ebookmeta.com

A Necklace of Springbok Ears Xam Orality and South African


Literature 1st Edition Helize Van Vuuren

https://ebookmeta.com/product/a-necklace-of-springbok-ears-xam-
orality-and-south-african-literature-1st-edition-helize-van-vuuren/

ebookmeta.com

HIGH SCHOOL MATH 2015 COMMON CORE ALGEBRA 2 STUDENT


EDITION GRADE 10 11 Prentice Hall

https://ebookmeta.com/product/high-school-math-2015-common-core-
algebra-2-student-edition-grade-10-11-prentice-hall/

ebookmeta.com

Dirty Kingdom (Covington High #1) 1st Edition Amelia


Winters

https://ebookmeta.com/product/dirty-kingdom-covington-high-1-1st-
edition-amelia-winters/

ebookmeta.com
Comparative and Diachronic Perspectives on Romance Syntax
1st Edition Gabriela Pan■ Dindelegan

https://ebookmeta.com/product/comparative-and-diachronic-perspectives-
on-romance-syntax-1st-edition-gabriela-pana-dindelegan/

ebookmeta.com
A Hands-On Course in
Sensors Using the Arduino
and Raspberry Pi
Series in Sensors
Series Editors: Barry Jones and Haiying Huang

Other recent books in the series:


Resistive, Capacitive, Inductive, and Magnetic Sensor Technologies
Winncy Y. Du
Semiconductor X-Ray Detectors
B. G. Lowe and R. A. Sareen
Portable Biosensing of Food Toxicants and Environmental Pollutants
Edited by Dimitrios P. Nikolelis, Theodoros Varzakas, Arzum Erdem,
and Georgia-Paraskevi Nikoleli
Optochemical Nanosensors
Edited by Andrea Cusano, Francisco J. Arregui, Michele Giordano,
and Antonello Cutolo
Electrical Impedance: Principles, Measurement, and Applications
Luca Callegaro
Biosensors and Molecular Technologies for Cancer Diagnostics
Keith E. Herold and Avraham Rasooly
Compound Semiconductor Radiation Detectors
Alan Owens
Metal Oxide Nanostructures as Gas Sensing Devices
G. Eranna
Nanosensors: Physical, Chemical, and Biological
Vinod Kumar Khanna
Handbook of Magnetic Measurements
S. Tumanski
Structural Sensing, Health Monitoring, and Performance Evaluation
D. Huston
Chromatic Monitoring of Complex Conditions
Edited by G. R. Jones, A. G. Deakin, and J. W. Spencer
Principles of Electrical Measurement
S. Tumanski
Novel Sensors and Sensing
Roger G. Jackson
Hall Effect Devices, Second Edition
R. S. Popovic
A Hands-On Course in
Sensors Using the Arduino
and Raspberry Pi

Volker Ziemann
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742

© 2018 by Taylor & Francis Group, LLC


CRC Press is an imprint of Taylor & Francis Group, an Informa business

No claim to original U.S. Government works

Printed on acid-free paper


Version Date: 20180129

International Standard Book Number-13: 978-0-8153-9360-3 (Paperback)


International Standard Book Number-13: 978-0-8153-9359-7 (Hardback)

This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been
made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity
of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright
holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this
form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may
rectify in any future reprint.

Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized
in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying,
microfilming, and recording, or in any information storage or retrieval system, without written permission from the
publishers.

For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://
www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923,
978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For
organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.

Library of Congress Cataloging-in-Publication Data

Names: Ziemann, Volker (Associate professor of physics), author.


Title: A hands-on course in sensors using the Arduino and Raspberry Pi /
Volker Ziemann.
Other titles: Sensors series.
Description: Boca Raton, FL : CRC Press, Taylor & Francis Group, [2018] |
Series: Series in sensors
Identifiers: LCCN 2017045669| ISBN 9780815393597 (hardback ; alk. paper) |
ISBN 9780815393603 (pbk. ; alk. paper) | ISBN 9781351188319 (e-book) |
ISBN 9781351188296 (e-book) | ISBN 9781351188302 (ebook) | ISBN
9781351188289 (ebook)
Subjects: LCSH: Detectors. | Raspberry Pi (Computer) | Arduino (Programmable
controller) | Microcontrollers.
Classification: LCC TK7872.D48 Z54 2018 | DDC 681/.20285464--dc23
LC record available at https://lccn.loc.gov/2017045669

Visit the eResource: https://www.crcpress.com/9780815393603


Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
Contents

Preface xv

Acknowledgments xvii

Chapter 1  Introduction 1

Chapter 2  Sensors 5
2.1 ANALOG SENSORS 5
2.1.1 Resistance-based sensors 5
2.1.2 Voltage-based sensors 10
2.1.3 Current-based sensors 14
2.2 SIGNAL CONDITIONING 16
2.2.1 Voltage divider 16
2.2.2 Amplifiers 17
2.2.3 Filters 21
2.2.4 Analog-to-digital conversion 23
2.2.5 Supply voltage 26
2.3 DIGITAL SENSORS 28
2.3.1 Buttons and switches 29
2.3.2 On/off devices 30
2.3.3 I2C devices 32
2.3.4 SPI devices 35
2.3.5 RS-232 devices 36
2.3.6 Other sensors 36

Chapter 3  Actuators 39
3.1 SWITCHES 39
3.1.1 Light-emitting diodes and optocouplers 39
3.1.2 Large currents 41
3.2 MOTORS 43
3.2.1 DC motors 44
3.2.2 Servomotors and model-servos 46
3.2.3 Stepper motors 47

v
vi  Contents

3.3 ANALOG VOLTAGES 51


3.4 OTHER ACTUATORS 52

Chapter 4  Microcontroller: Arduino 55


4.1 HARDWARE 55
4.1.1 Arduino UNO 55
4.1.2 ESP8266 and NodeMCU 56
4.2 GETTING STARTED 57
4.3 HELLO WORLD, BLINK 58
4.4 INTERFACING SENSORS 60
4.4.1 Button 60
4.4.2 Analog input 61
4.4.3 I2C 65
4.4.4 SPI 77
4.4.5 Other protocols 80
4.5 INTERFACING ACTUATORS 85
4.5.1 Switching devices 85
4.5.2 DC motors 87
4.5.3 Servos 91
4.5.4 Stepper motors 92
4.5.5 Analog voltages 101
4.5.6 Human attention actuators 102
4.6 COMMUNICATION TO HOST 103
4.6.1 RS-232 and USB 103
4.6.2 Bluetooth 104
4.6.3 WiFi 105
4.6.4 Other communication 110

Chapter 5  Host Computer: Raspberry Pi 113


5.1 HARDWARE 113
5.2 GETTING STARTED 113
5.3 INSTALLING AND USING NEW SOFTWARE 117
5.4 RASPI AS A ROUTER 121
5.5 COMMUNICATION WITH THE ARDUINO 123
5.5.1 Arduino IDE 123
5.5.2 From the command line 124
5.5.3 Python 125
5.5.4 Octave 129
5.6 DATA STORAGE 132
5.6.1 Flatfile 132
5.6.2 MySQL 134
Contents  vii

5.6.3 RRDtool 138


5.7 ONLINE PRESENTATION 141

Chapter 6  Control System: EPICS 147


6.1 INSTALLATION 147
6.2 COMMUNICATING WITH EPICS 149
6.3 ASYN AND STREAM LIBRARIES 150
6.4 WRITING AN IOC 151
6.5 STARTING THE IOC AT BOOT TIME 154

Chapter 7  Messaging System: MQTT 157


7.1 BROKER 158
7.2 NODEMCU CLIENTS 159
7.3 GATEWAY TO EPICS 161

Chapter 8  Example: Weather Station with Distributed Sensors 167

Chapter 9  Example: Geophones 177

Chapter 10  Example: Monitor for the Color of Water 185

Chapter 11  Example: Capacitance Measurement 191

Chapter 12  Example: Profile of a Laser Beam 197

Chapter 13  Example: Fire-Seeking Robot 205

Chapter 14  Presenting and Writing 223


14.1 PREPARING A PRESENTATION 223
14.2 PREPARING A REPORT 225
14.3 PRESENTING DATA 226
14.4 GOOD ENGLISH 227
14.5 POSTSCRIPTUM 228

Appendix A  Basic Circuit Theory 229

Appendix B  Least-Squares Fit and Error Propagation 231

Bibliography 235

Index 237
List of Figures

1.1 The outline of the book. 2

2.1 Image of a light-dependent resistor (LDR) on the left and how to connect it
in a plain voltage-divider configuration (center) and in a Wheatstone bridge
(right). 5
2.2 The band-level scheme and the schematics for the circuit with the LDR in a
voltage divider. The upper graph illustrates dark conditions and the lower
graph shows conditions where the LDR is exposed to light. Note that the
vertical axis by convention shows the energy of electrons. This causes the
positive pole of the battery to have the most negative energy. See the text
for a discussion. 6
2.3 NTC resistors are doped semiconductors that have donor levels just below
the conduction band. Increasing the temperature increases the kinetic energy
of the electrons that allows them to occasionally jump into the conduction
band, where they contribute to the conductivity of the material. 8
2.4 A linear potentiometer (left) and a circuit illustrating the electric connec-
tions (right). 9
2.5 A joystick is shown on the left and a fluid-level resistive sensor on the right. 10
2.6 A strain gauge. 10
2.7 Schematic of an MQ-x gas detector (left) and a sensor mounted on a small
breakout board (right). 11
2.8 Image of an LM35 temperature sensor (left) and how to connect it (right). 11
2.9 On the left we show a schematic of a thermocouple on the top and a ther-
mopile on the bottom. On the right we show an image of an MLX90614
contact-free thermometer. 12
2.10 Schematic of a Hall sensor (left) and the A1324 sensor (right). 12
2.11 The operational principle of an ADXL accelerometer. 13
2.12 An SM-24 geophone with a diameter of about 30 mm. 14
2.13 Energy-band diagram (left) and circuit (right) of a reverse-biased pin diode
in photoconductive mode. 14
2.14 Image of a BPW34 pin diode on the left and two phototransistors on the
right; an IR-sensitive BPX38 and an SFH3310, sensitive in the visible part
of the spectrum. 15
2.15 On the left we have a voltage divider to reduce the input voltage of 0-5 V
to 0-3.3 V. The right circuit shows the use of clamping diodes to protect the
input of the microcontroller to lie between ground and 5 V. 16

ix
x  LIST OF FIGURES

2.16 A bare operational amplifier shown on the left and shown wired as a line
buffer on the right. We omitted the supply wires on the latter schematic. 17
2.17 A non-inverting (left) and inverting (right) amplifier. 18
2.18 A difference amplifier (left) and the same circuit with adjustable V1 (right)
that is used to subtract the baseline. 19
2.19 Instrumentation amplifier (left) and logarithmic amplifier (right). 19
2.20 Amplifying a weak signal and shifting it to mid-range between the power
rails. 20
2.21 A simple low-pass (left) and high-pass (right) filter. 21
2.22 A simple band-pass (left) and band-stop (right) filter. 22
2.23 An active non-inverting (left) and inverting (right) low-pass filter. 22
2.24 The operating principle of a 3-bit flash ADC. 23
2.25 The operating principle of a successive approximation ADC. 24
2.26 The operating principle of a delta-sigma ADC. 24
2.27 Sampling a signal in different Nyquist zones. The dashed line displays a
frequency of 0.15fs and the solid lines show signals with frequency (1 −
0.15)fs on the left and (1+0.15)fs on the right. Note that at the times when
the signal is sampled (indicated by boxes), the signals are indistinguishable. 25
2.28 The dashed signals s1 and s2 are the images aliased into the base band of
the original signals S1 and S2 in higher Nyquist zones. 26
2.29 Schematics of very simple power supply circuits. 27
2.30 Variable-voltage (left) and fixed-voltage (right) regulator circuits. 28
2.31 Connecting a switch or button with a pull-up resistor. 29
2.32 Level shifter circuitry using a n-type MOSFET. The source of the MOSFET
is connected to the 3.3 V logic and the drain to the 5 V logic. 30
2.33 Schematic view of a PIR sensor (left) and the hardware (right). 31
2.34 HR-SR04 distance sensor. 31
2.35 Illustration of the operational principle of a barometric pressure sensor. 32
2.36 A BMP180 barometric pressure sensor and an HYT-221 humidity sensor. 33
2.37 The operational principle of one gyroscope in the MPU-6050. 34
2.38 An MPU-6050 accelerometer on a breadboard. 35
2.39 A GPS receiver on the left and a DHT11 humidity sensor on a breadboard
on the right. 36
2.40 A Shinyei PPD42NS particle sensor (left) and a GP2Y1010AU0F dust sensor
(right). 37

3.1 A close-up of a light-emitting diode is shown on the left. In the center is the
schematic of connecting an LED and the same circuit on a breadboard. 40
3.2 The physics of an LED. 41
3.3 The terminals of an NPN transistor (left), and using an NPN transistor as
switch (right). 42
3.4 Two NPN transistors connected to form a Darlington pair (left) and a
ULN2003 Darlington array (right). 42
LIST OF FIGURES  xi

3.5 Schematic illustrating the functionality of a relay (left) and an image of a


relay (right). 43
3.6 Basic operation principle of a DC motor. The magnetic north pole of the
stator is to the left and the south pole to the right of the coil. Current is
supplied to the brushes where it enters the commutator and passes through
the rotor-coil, where the Lorentz force causes a force on the wire, moving
it upwards. After half a turn, the commutator has rotated and reverses the
polarity such that the current on the left side of the coil points in the same
direction as before. 44
3.7 Schematic illustrating the functionality of an H bridge. 45
3.8 A small model-servo. 46
3.9 The timing of the control signal for the servo. 47
3.10 Schematics of a stepper motor. Note that the coils are denoted by upper-case
letters and the corresponding terminals with lower-case letters. 48
3.11 Wiring of the coils in a bipolar stepper motor (left) where the respective
center terminals are often connected. In a unipolar motor (right) the center
terminals are exposed. 50
3.12 Connection for a unipolar stepper motor. 51
3.13 Operational principle of a digital-to-analog converter. 51
3.14 Sketch of a butterfly valve. 53

4.1 An Arduino UNO. 56


4.2 The ESP-01 on the left and a NodeMCU on the right. 56
4.3 The Arduino IDE. 57
4.4 The “Blink” sketch. 59
4.5 Interfacing a button to the Arduino. 60
4.6 Interfacing a potentiometer (left) or an LM35 temperature sensor (right) to
the Arduino. 62
4.7 Connecting the MLX90614 contact-free thermometer to an Arduino UNO. 66
4.8 Connecting the HYT-221 humidity sensor to the Arduino (left) and using
the serial plotter to display the humidity and temperature measurements
(right). 67
4.9 Connecting the MCP23017 IO-extender to the UNO. 74
4.10 Connecting the MCP3304 ADC to the NodeMCU. 77
4.11 Connecting the DS18b20 sensor to the Arduino UNO. 82
4.12 Oscilloscope trace of a pulse-width modulated signal on pin D9 of an Arduino
UNO with values of 88 (left) and 220 (right). 85
4.13 Using pulse-width modulation and a transistor to adjust the brightness of
an LED. 87
4.14 Controlling the speed of a motor with pulse width modulating the base of
a TIP-120 Darlington transistor. See the text for a discussion of the diodes. 88
4.15 The pin assignment of the L293D H-bridge driver. 88
4.16 Controlling speed and direction of a DC motor. 89
4.17 Connecting a model-servo to the Arduino UNO. 91
xii  LIST OF FIGURES

4.18 Connecting a unipolar stepper motor to the UNO with a ULN2003 Darling-
ton driver. 93
4.19 Connecting a bipolar stepper motor to the UNO with an L293D H-bridge
driver. 94
4.20 Connecting a bipolar stepper motor to the UNO with a DRV8825 stepper
motor driver with microstep capability. 98
4.21 Adjusting the maximum current on the DRV8825 breadboard. 99
4.22 Connecting an MCP4921 12-bit DAC to the Arduino UNO. 101
4.23 Connecting a speaker and a piezo buzzer to the Arduino. 103
4.24 Front and back side of the HC-06 Bluetooth dongle and the connection to
the Arduino. 104
4.25 The NodeMCU with an LM35 temperature sensor. 106
4.26 The communication with a web server showing the HTTP header. 108

5.1 A Raspberry Pi board. 114


5.2 The Accessory menu behind the button with the raspberry shows a number
of installed programs such as the Terminal (command) window. 115
5.3 The nano text-editor with available commands listed on the bottom. 118
5.4 The Synaptic Package Manager. 119
5.5 Telnet session connected wirelessly to the NodeMCU. 124
5.6 Using Python on the Raspi to communicate with the query response sketch
running on the Arduino UNO. 125
5.7 Simple ASCII graphics from querying the UNO repeatedly. 126
5.8 Plot from the temperature logger. 131
5.9 Graphics from rrdtool. 140
5.10 Web page from the Raspi after installation of the Apache2 web server. 141
5.11 The first self-made web page. 142
5.12 User pi’s home page that displays the continuously (but slowly) updated
temperature. 144

6.1 Using the EPICS commands caget and caput. 150

8.1 The weather-node circuit with the NodeMCU on the right and the LM35,
HYT221, and BMP180 sensors towards the left. 168
8.2 The weather station web page served by the Raspi. 173

9.1 The amplifier to interface an SM-24 geophone to the NodeMCU. 178


9.2 The prototype with the SM-24 geophone connected to the amplifier board
and the NodeMCU. 180
9.3 The raw time series from the geophone and the corresponding spectrum. 181

10.1 The setup to measure the color-dependent absorption (left) and the reflec-
tion from a surface (right). 185
10.2 The setup to measure the water color with an Arduino UNO. 186
LIST OF FIGURES  xiii

10.3 The color sensor with the RGB-LED on the left and the phototransistor on
the right. 188

11.1 The setup to measure the capacitance. 192


11.2 The waveform of the voltage on the capacitor as a function of time, while a
2.2 µF Tantal capacitor discharges through a 33 kΩ resistor on a linear scale
(above) and on a logarithmic scale (below). 195

12.1 The schematic setup to measure the beam size of a laser pointer. 197
12.2 The chassis from the CD-ROM drive with the laser mounted on the top right
and the photoresistor on the bottom right. The black obstacle is mounted
on the carriage that can be moved via the spindle on the top by a small
stepper motor that is located below the laser. 198
12.3 The schematics of the circuit. The stepper motor of the frame is connected
to points labelled PA,. . . ,PD. 199
12.4 The raw sensor value as a function of the position of the obstacle and the
derived laser beam profile, which shows a moderate asymmetry. 203

13.1 The chassis of the robot with two breadboards. The smaller one can be
turned by operating a model-servo. Mounted on the larger breadboard are
a NodeMCU on the right and a second chip on the left, a bare ATmega328
that was initially tested and later replaced by an Arduino NANO. 206
13.2 Simplified setup of the remote controller on a breadboard. 207
13.3 The schematic of the remote controller. 207
13.4 The electronics circuit of the robot (color version available online). 212
13.5 The schematic of the robot electronics. 213
13.6 The operational robot from the back (left) and from the front (right). 221

A.1 Two impedances connected in series (left) and in parallel (right). 230
Preface

Some years ago three young students inquired about a moderately complex project to earn
some credits. I happily agreed to supervise them and assigned moderately difficult tasks,
namely, to build from scratch a data acquisition system for slow signals. I suggested to
connect some sensors to an Arduino microcontroller and then write a program for the
Arduino to interface the measurement values to the control system we use in our lab.
The students were very dedicated and a real joy to work with. They had the Arduino
under control within a few hours and had the first sensors reporting their measurement
values after the first day. Then they worked out a protocol that is compatible with our
EPICS-based control system, and after discussions with our control systems experts and
even more debugging, eventually the students had a prototype system working. After clean-
ing up their project, they had to give a presentation and write a report to earn their
well-deserved credits.
I soon realized that there is a clear progression of the information generated by a sensor.
The information bubbles upwards through a sequence of microcontrollers and computers
that provide data-handling, storage, and online presentation to a seminar presentation, and
eventually ends up in a report. Understanding the path the measurement data take ap-
peared like a useful concept to communicate to students. Moreover, I wanted the students
to understand the details of the signal chain and how it really works. Therefore, I used
the hands-on approach with programming the Arduino that serves as communication glue
between the sensor and the control system. This proved beneficial for the students’ under-
standing and was appreciated by them. The abstract concepts thus led to a very concrete
realization. In the final stages of the project I coached the students on how to prepare a
presentation for a seminar according to some simple guidelines, and eventually put the oral
presentation into writing for a report to hand in and receive their credits.
This book is inspired by these students and their projects, but goes a step further and
adds a number of additional topics such as signal conditioning, controlling actuators such as
switches and motors, as well as control system setup, data storage, and networking. Please
note that I cover only basic examples that are boiled down to the bare essentials in order
to illustrate the main concepts and to get started quickly. Anyway, the concepts covered
should come in handy when working with real-world data-acquisition tasks. I basically follow
Mrs. Robinson’s guideline of “help you learn to help yourself” (remember the Simon and
Garfunkel song?) and try to fill the toolbox with practical know how. This know how should
enable the reader to help herself and pick up datasheets and manuals to adapt the basics
from this book to realize far more advanced projects.

User Guide
The main theme of the book is From Sensor to Report, and that should be the guiding
principle of using it in the classroom, either in a student laboratory or as the basis for
individual projects.
For a student laboratory I suggest installing the software with some of the more arcane
instructions before starting the lab. This comprises turning the Raspi into a router (Sec-

xv
xvi  Preface

tion 5.4), installing the MySQL database (Section 5.6.2), and installing EPICS (Section 6.1).
The students should focus on the sensors and use the above systems as a background infras-
tructure. They should, on the other hand, understand the basic operation of the sensors,
learn how to interface them to a microcontroller, and move the information to the next level
on a different computer. This requires them to write network code, fill an SQL database,
prepare the protocol files for EPICS, or present data on a web server. In the lab a knowledge-
able supervisor, a “tutor”, should be available to answer questions and guide the students.
Using solderless breadboards in the lab enables the students to quickly arrive at a working
system on which to base further experiments and try out new ideas.
A suitable scope for student projects, suitable for a single or a group of two students,
is to connect a small number of sensors to an Arduino. Then they should be given a target
system where they can publish the data. This can be a database, EPICS, MQTT, or a web
page. After a prototype system is working, the students should present their system in a
seminar and prepare a report.
All code and the corresponding images of the circuits on a breadboard, prepared
with Fritzing [1], are available on this book’s web site at https://www.crcpress.com/
9780815393603.
Acknowledgments

This book only materialized because my students, Adam, Måns, and Frida, asked about
“some project” and then completed it with such enthusiasm. I gratefully acknowledge their
contributions and input.
I gratefully thank my colleagues Roger Ruber and Mattias Klintenberg. They read and
commented on parts of the manuscript and provided essential feedback. All remaining errors
are of course my responsibility.
I thank Camilla Thulin, Uppsala University, for her help with the photography.
This book is only possible thanks to the open source community that created the Arduino
and Raspberry Pi ecosystems and the large number of people who answer questions on
Internet forums.
I acknowledge the creators and maintainers of the Fritzing software. I relied on it to
prepare many drawings to illustrate the wiring of circuits.
I am indebted to my editor Francesca McGowan and to Rebecca Davies at Taylor &
Francis for competently guiding me through the intricacies of writing and publishing a book.
Last, but not least, I acknowledge my family for putting up with me during the writing
and editing period, when I was more often than not absent minded and showed a distinct
lack of response to other matters.

xvii
CHAPTER 1

Introduction

What is the path that the electrical signal from a sensor takes to end up in a report? We
address this question because collecting sensor data, processing them, and deriving some
understanding from the data plays an important role in many circumstances. One example
is a utility company that gathers information about electricity, heating, and water in order
to prepare statements for their customers and to estimate demand for their product in the
future. Smart homes are another example; they measure temperatures or detect the presence
of beverages in the refrigerator to adjust the thermostat in the first case, or to prepare
a report for us to pick up some milk or beer on the way home in the second case. Quite
generally, many Internet of Things (IoT) technologies share a common base with the topic of
the book, but even large experimental collaborations such as the ATLAS [2] or CMS [3] that
operate the huge detectors at the Large Hadron Collider (LHC) [4] at CERN [5] get their
data from sensors that are buried deep inside the detectors. They sense currents from drift
chambers where charged particles cause a discharge between wires at different potentials, or
they cause electrical signals from semiconductor detectors, where they create electron–hole
pairs that induce a current. Other examples are Hall sensors, to measure magnetic fields, and
humidity sensors or barometric pressure sensors to detect variations of ambient conditions.
All these sensors produce electrical signals that often need to be amplified or otherwise
conditioned. This stage involves operational amplifiers and various filters to improve the
signal-to-noise ratio. Once properly processed, the analog signals are passed on to analog-
to-digital converters (ADC), where they are converted to a digital representation that is
subsequently handled by computers. Often some of the computing power is located close
to the sensor and is provided by microcontrollers that collect signals from nearby sensors
and convert them to the underlying physical quantities, formatted to have a standardized
output format. Thus they act as “communication glue” between the specific interface to
the sensor and a more generic interface to a host computer that is usually located further
away. The latter is the other end of the communication channel from the microcontroller
and provides data storage and presentation, and sometimes also shows recent data for on-
line monitoring. The host computer may run generic control-system software to provide a
further abstraction layer towards higher-level software. Examples we discuss are MQTT [6],
which is popular with IoT projects, and the EPICS control system [7], commonly found in
scientific laboratories.
In this book we will build a system that contains all the ingredients also found in
large scientific or industrial installations. In a sense it is a simplified model of a large
installation, yet containing all the hardware and logical building blocks. In particular, we
use the Arduino microcontroller [8] as the local intelligence to control switches and motors
to move the sensors around and enable reading them out and translating the signals to
a format that allows communication with a host computer using a standardized protocol.

1
2  A Hands-On Course in Sensors Using the Arduino and Raspberry Pi

Analog Digital
sensors sensors

Actuators
I2C switches, motors
Signal SPI
conditioning

Digitization Reading

Turning on and moving


the sensors
Preparation to standard Arduino
output format Microcontroller

Communiating with the


host computer

RS-232, WIFI
Protocol

Communication with the


micro-controller
Raspberry Pi
Data storage Host computer

Data presentation
Publish with web server
EPICS control system
MQTT messaging system

Presenting at seminar

Writing the report

Figure 1.1 The outline of the book.


Introduction  3

This comprises the hardware channels, which can be USB, RS-232, Bluetooth, or WiFi as
well as the logical protocol, such as a simple query-response protocol. As host computer
we use a Raspberry Pi [9] which, in its most recent incarnation, features four processing
cores and runs a standard Linux system with a huge base of available software, including
web servers, the MATLABTM -clone Octave, and even MathematicaTM , all without license
charges.
The remainder of the book is organized as laid out in Figure 1.1. We first discuss a
number of analog sensors and signal-conditioning methods, followed by a number of sensors
that already provide their measurements in digital form, and the buses and protocols used.
Next we discuss actuators. They switch things on and off, even those requiring large currents,
and we learn how to control different types of motors that are sometimes needed as part of
the measurement process. We then describe how to interface the actuators and the sensors
with the Arduino, either by digitizing the signals or by using the appropriate bus-interface.
We go on to describe a program structure that permits the Arduino to support a simple
query-response protocol in order to serve as a slave to a host computer. Next, we configure
a Raspberry Pi as a standardized host computer. It will provide data storage in databases,
and present the data in graphical form either using Octave running locally on the Raspi
or by publishing our measurement data with a web server, also running on the Raspi. We
continue the discussion by installing the EPICS control system software and turn the Raspi
into a full-blown control-system server that can join any other EPICS installation in a
transparent way. We go on to discuss the MQTT message-passing system, which plays an
important role in IoT applications. Having assembled all the parts, we consider examples
in which we build a weather station with distributed sensors, and systems to record ground
vibrations, monitor the color of water, and measure the capacitance of a capacitor. In two
more advanced examples, we build a system to measure the width of the beam of a laser
pointer, and a remote-controlled robot that also senses flames autonomously, moves to the
fire, and sounds an alarm. We conclude with presenting guidelines about how to prepare
a seminar presentation based on the examples and how to write a readable publication
describing our data acquisition system using sensors, actuators, Arduino, and Raspberry
Pi.
CHAPTER 2

Sensors

A sensor is a device that converts a physical quantity to an electrical signal [10, 11, 12, 13],
and therefore either provides a voltage or a current, or causes a change of its resistance.
More generally, the impedance of the sensor, which also comprises capacitive and inductive
sensors, may change. We are thus faced with the task to measure either of these electrical
quantities.
Below we discuss examples of the different types of sensors. The examples only show
a selection of those available on the market, and searching the Internet for the physical
quantity one wants to measure jointly with the keyword “sensor” will give an idea of what
is available. Once the sensor is identified, careful reading of the datasheet to learn about
how to interface the sensor is mandatory.

2.1 ANALOG SENSORS


We start by considering resistance-based sensors.

2.1.1 Resistance-based sensors


The first resistance-based sensor we look at is a light-dependent resistor or LDR, shown
on the left of Figure 2.1. It changes its resistance depending on the exposure to light. The
range of variation depends on the device and typically ranges from a few 100 Ω to MΩ. The

Image of a light-dependent resistor (LDR) on the left and how to connect


Figure 2.1
it in a plain voltage-divider configuration (center) and in a Wheatstone bridge
(right).

5
6  A Hands-On Course in Sensors Using the Arduino and Raspberry Pi

Few thermically Lower boundary of


Supply voltage equals exited electrons conduction band
voltage drop across
both resistors
Measured
voltage
Upper boundary
of valence band

Highest energy
for electrons
Vcc
LDR

Wire Wire Wire


Resistor

Vcc Signal

More electrons
in conduction
Measured band
voltage
Band gap
2.4 eV

Supply voltage equals


voltage drop across
both resistors Photon Upper boundary
of valence band
Hole in
valence band
Highest energy
for electrons

Conduction band
lower boundary

Vcc Photon
LDR

Wire Wire Wire


Resistor

Vcc Signal

Figure 2.2The band-level scheme and the schematics for the circuit with the LDR in
a voltage divider. The upper graph illustrates dark conditions and the lower graph
shows conditions where the LDR is exposed to light. Note that the vertical axis
by convention shows the energy of electrons. This causes the positive pole of the
battery to have the most negative energy. See the text for a discussion.
Sensors  7

operating principle of this and many other sensors is based on the availability of electrons in
the conduction band of a material. In good (wires) or bad (resistors) conductors, electrons
partially fill the available states in the conduction band up to some energy, the Fermi level,
whereas in insulators the Fermi level is located in between the completely filled valence band
and the conduction band [14]. Therefore, no electrons are available in the conduction band.
Furthermore, the energy-difference between the upper boundary of the valence band and
the lower boundary of the conduction band, the bandgap, is large, while for semiconductors
it is on the order of electron-volt (eV).
In photoresistors the base material is often CdS, a semiconductor with a bandgap of
about 2.4 eV. This energy equals that of photons of green light with a wavelength of about
500 nm. Therefore, green photons can elevate electrons from the valence to the conduction
band and thus create electron–hole pairs. These now freely moving charge carriers conduct
electric current and therefore increase the conductivity of the material. Figure 2.2 illustrates
this in more detail. The upper figure shows a simplified band level scheme under dark
conditions. The bold lines show the lower boundary of the conduction band and the upper
boundary of the valence band. The dashed line shows the highest energy-states that electrons
occupy. For metals and resistors, this is close to the Fermi level, but in a semiconductor, like
CdS, the Fermi level lies between valence and conduction band. Yet, at room temperature,
there are a few thermally excited electrons in the conduction band of CdS. We visualize this
by the close proximity of the dashed line to the lower conduction-band boundary. In metals
there are plenty of electrons in the conduction band, and the conductivity is high. In the
resistor there are fewer electrons in the conduction band, or their mobility is impeded in
other ways such that there is a shift in the Fermi level across the resistor. In dark conditions
there are only very few thermally excited electrons in the conduction band of the LDR, and
the conductivity is very low. Consequently, there is a large voltage-drop across the LDR
and the measured voltage, which is the difference of Fermi levels between the measurement
points. The measured voltage is therefore close to the full voltage delivered by the battery.
If, on the other hand, the LDR is illuminated, the photons lift electrons from the valence
band into the conduction band. This increases the conductivity and only a small voltage is
dropped across the LDR. This consequently reduces the measured voltage, as shown in the
lower graph of Figure 2.2. Note that we do not discuss the details of the interfaces between
the different parts because it is beyond the scope of this book.
In the middle of Figure 2.1 we show how to connect a photoresistor in series with a
resistor R0 (here 10 kΩ) to create a voltage divider between the supply voltage Vcc and
ground. From the discussion of voltage dividers and a short refresher of basic circuit theory
in appendix A or [15, 16], the voltage Vs on the signal terminal is then given by Vs =
Vcc RLDR /(R0 + RLDR ). Thus, the illumination of the LDR changes its resistance RLDR
and the signal voltage varies correspondingly. Note that we have to select the resistor R0
in the middle of the range of RLDR . This causes the voltage we measure to be around one
half of the supply voltage. Therefore, we also need to use a volt meter in that voltage range.
Very small variations of the light intensity are then difficult to resolve and may need to
be amplified. Using a Wheatstone bridge, where we compare the voltages in two resistor
dividers, as shown on the right of Figure 2.1, helps to alleviate this problem. We expand on
the use of Wheatstone bridges in Section 2.2.
Other resistance-based sensors are resistance-based temperature detectors (RTD) such as
the PT100 temperature sensor. It is a calibrated platinum-based sensor with a resistance
of exactly 100 Ω at 0 o C. It is based on the fact that the resistance of a very pure metal
is determined only by scattering of electrons in the conduction band with phonons, which
are vibrations of the ions that make up the crystal lattice of the metal. Moreover, higher
8  A Hands-On Course in Sensors Using the Arduino and Raspberry Pi

Energy Conduction band


lower boundary electron

Band
Occupied donor levels Partially occupied gap
donor levels

Valence band
at low upper boundary at higher
temperature temperature

Figure 2.3NTC resistors are doped semiconductors that have donor levels just below
the conduction band. Increasing the temperature increases the kinetic energy of the
electrons that allows them to occasionally jump into the conduction band, where
they contribute to the conductivity of the material.

temperatures cause stronger vibrations of the lattice, with correspondingly higher resistance.
Intuitively one might think of the crystal ions at higher temperature to oscillate with larger
amplitudes, creating a larger target for the electrons to scatter, thus impeding their motion.
Since this is an intrinsic property of the material, calibration measurements of resistance as
a function of temperature are universally valid for all sensors of the same metal, provided
the metal is very pure and free of imperfections. Commercial sensors are often made of
platinum wire wound on a ceramic support body. The PT100 sensors are connected to a
calibrated current source and the voltage drop across the sensor is measured with a volt
meter, just as any other resistance measurement.
Thermistors are resistors that have their temperature dependence deliberately made
large. In positive temperature calibration (PTC) devices, the resistance increases with tem-
perature, and in negative temperature calibration (NTC) devices, it decreases. PTCs are
mostly used as protection devices that switch the resistance from a low- to a high-resistance
state if a certain temperature is exceeded. They are based on polycrystalline materials that
change their dielectric constant at a certain temperature, the Curie temperature, by a large
amount. Above the Curie temperature, the state of the magnetic dipoles is disordered and
the dielectric constant is small. This causes the formation of large potential barriers be-
tween the crystal grains, which leads to a high resistance. Below the Curie temperature the
molecular dipoles are aligned, the dielectric constant is large, and the resistance is low. A
typical application of the PTC thermistor is a self-regulating heater, in which the heater
also warms up the thermistor, which increases the resistance and limits the current to the
heater until an equilibrium is found. PTCs can also be used to detect whether a threshold
temperature is exceeded.
The converse thermistors are NTCs, which decrease their resistance with increasing
temperature. They are often used for temperature sensing and are based on a doped semi-
conducting material that has occupied impurity donor levels below the conduction band, as
shown in Figure 2.3. Increasing the temperature thermally excites these electrons to jump
into the conduction band, thus increasing the conductivity. This effect is much larger than
the reduction of the resistance due to the ions oscillating and impeding the motion of the
electrons, which was responsible for the temperature dependence in the PT100 sensor. Both
NTC and PTC thermistors are sensed by connecting them to a constant-current source and
measuring the voltage drop across the thermistor.
Sensors  9

A number of position sensors are based on potentiometers. A potentiometer is a variable


resistor where a slider moves up and down a resistance and shortens the distance of one end
point to the slider, thereby reducing the resistance between two terminals. The distance be-
tween the slider and the other end point lengthens, causing the resistance between the slider
and the other terminal to increase correspondingly. On the left-hand side of Figure 2.4 we
show a potentiometer with three connectors; the two end points are connected to dark wires
and the one controlled by the slider is connected to a lighter-colored wire. The schematic
view on the right of Figure 2.4 explains the functionality; the slider controls a variable mid-
point of a voltage divider and the output voltage interpolates from 0 to 5 V in this case. A
variation of the potentiometer is a joystick, which is based on two orthogonally mounted
potentiometers, controlled by a small stick. We simply need to measure the voltage on the
output with respect to ground in order to determine the position of the slider or the stick.
An image of a joystick is shown on the left of Figure 2.5.
Also, fluid levels of liquids with a small conductivity can be determined with a resistor
whose resistance is varied by reducing the resistance between conducting stripes shown in
Figure 2.5. The sensor is connected just as a potentiometer with the liquid level acting as
the slider.
Applying an external force to a material will cause a change its equilibrium shape, and
therefore strains the material. An example is a stretched wire that will get longer and
thinner if pulled. Consider the resistance R = ρL/A of the wire, given in terms of resistivity
ρ, length L, and cross section A, and consider its change. We see that increasing L and
decreasing A increases the resistance R. Thus, the simple wire converts its deformation to a
small change in the resistivity, and therefore serves as a force-sensitive resistor that is often
used as one branch in a Wheatstone bridge. The small effect of only changing the geometry
of the wire can be greatly enhanced by using heavily doped semiconductors instead. The
latter also change their resistivity ρ by a large amount when strained. Alternatively, they are
based on polymer thick-film technology. An example is the strain gauge shown in Figure 2.6.
The MQ-2 and other MQ-x are gas sensors sensitive to different types of gas, depending
on their type specification. They are based on a semiconductor substrate with a thin surface
layer of polycrystalline SnO2 tin oxide that is either sputtered or deposited by evaporation.
The specificity to various gases depends on the temperature of the active area, which is
adjusted by a heater, by the method of deposition, or by small additions of other materials,
such as palladium, gold, or platinum. The variation of the resistance depends on the grain
boundaries of the polycrystalline SnO2 and on the insulating oxide layer between the grains

Figure 2.4A linear potentiometer (left) and a circuit illustrating the electric connec-
tions (right).
10  A Hands-On Course in Sensors Using the Arduino and Raspberry Pi

Figure 2.5 A joystick is shown on the left and a fluid-level resistive sensor on the
right.

that is affected by the adsorbed gases. On the left of Figure 2.7 we illustrate the working
principle. The heater is located under the SnO2 active layer and powered by passing a
current through it. The resistance, which depends on the concentration of the specific gas,
can be measured between the terminals labeled 1 and 2. A device mounted on a small
breakout board is shown on the right of Figure 2.7. The sensing area is located under the
metallic hat that protects against the heated area, and potential explosive reactions on the
hot surface should a “wrong” gas ignite.
After this short selection of resistance-based sensors we progress to discuss sensors that
report a voltage directly.

2.1.2 Voltage-based sensors


An example of a sensor that directly produces a voltage at its output pin is the LM35
temperature sensor, which is a silicon-bandgap temperature sensor. The operating princi-
ple is based on passing known currents In with n = 1, 2 with current densities jn across
the base-emitter junctions of two bipolar transistors, and comparing their respective volt-
age drops VBE,n . The voltage difference is proportional to the temperature. This is easily
understandable by inverting the current–voltage curve for the diode of the base-emitter
junction h i
jn = A(T ) e(eVBE,n −Eg )/kT − 1

where Eg = 1.2 V is the bandgap energy of silicon, k is the Boltzmann constant, and
T the absolute temperature in Kelvin. A(T ) is a device-specific constant with moderate
temperature dependence. Assuming that both transistors are located on the same substrate
and have the same temperature, we solve for two current densities j1 and j2 and obtain
for the voltage difference ∆VBE = VBE,1 − VBE,2 = kT /e ln(j1 /j2 ). In the LM35, the base-

Figure 2.6 A strain gauge.


Sensors  11

Uh

Sn2O

1 2

Heater

Schematic of an MQ-x gas detector (left) and a sensor mounted on a small


Figure 2.7
breakout board (right).

emitter diodes of the two transistors have different areas such that the ratio of the areas
determines the current densities, provided that the same macroscopic current passes through
the two transistors. There are operational amplifiers on the same substrate to provide signal
conditioning such that the LM35 produces an output voltage Vs that is related to the
temperature T by Vs = T /100. Here Vs is measured in volts and the temperature in degrees
Celsius, such that a temperature of 23 o C results in a voltage of 0.23 V. The LM35 has three
pins; one is connected to ground, one to the supply voltage, and the third one carries the
voltage Vs that is proportional to the temperature. Note the polarity for connecting the
LM35 in Figure 2.8. The flat surface is pointing to the wires on the left-hand side.
Thermocouples are temperature sensors that are based on the effects of temperature and
temperature gradient on conductors made of different materials. Directly at the junction of
the conductors, the Peltier effect causes a current that depends on the temperature. This
happens at the points labeled by their respective temperatures T1 and T2 on the top left
in Figure 2.9. On the wire segments a temperature gradient causes an additional current
to flow, the Thomson effect. And finally, joining the two junctions and the wires causes a
current to circulate, provided the loop is closed. This is called the Seebeck effect. If the loop
is open, as shown at the top left of Figure 2.9, a voltage U develops at the end terminals
as a consequence of the Peltier, Thomson, and Seebeck effects. In practice, one junction,
say at T1 , is held at known and constant temperature, for example, by immersing the

Figure 2.8 Image of an LM35 temperature sensor (left) and how to connect it (right).
12  A Hands-On Course in Sensors Using the Arduino and Raspberry Pi

material A

T1 T2
material B U material B

T1

A A A A A A
B B B B B B

T2
U

Figure 2.9On the left we show a schematic of a thermocouple on the top and a
thermopile on the bottom. On the right we show an image of an MLX90614 contact-
free thermometer.

junction in ice water. Then the voltage U is related to the temperature difference T2 − T1
of the sensing end at T2 and the reference temperature T1 . The magnitude of the voltage
generated depends on the combination of metals and is typically on the order of 50 µV/o C.
In a thermopile a number of wire segments of materials A and B are connected in series,
as shown on the bottom left in Figure 2.9. This increases the sensitivity of the device to
temperature differences. Thermopiles are often found in devices sensing heat and infrared
radiation, such as thermal imaging devices or contact-free thermometers. The sensor used
in the latter is shown on the right of Figure 2.9.
Some crystals and ceramics react to external stresses by producing a piezoelectric voltage
between opposite sides of the material, as a consequence of rearranging charges within their
crystal structure. The resulting voltages reach several kV and can be used to produce
sparks in ignition circuits or in old-fashioned vinyl record players. There, a “crystal”-stylus
is squeezed in the grooves of the record and the generated voltages are amplified and made
audible as sound. In scientific applications, piezoelectric sensors are used to measure pressure
or forces.
The speed of angular motion is easily sensed by a DC electrical motor that is operated
backwards as a generator. Instead of applying a voltage to turn the axis of the motor,
turning the axis induces an induction voltage in the motor coils that is proportional to the
angular velocity. Attached to a propeller that is turned by either a flowing liquid or a gas,
such a device can measure flow rates.

+Uh/2

I I
E
B

-Uh/2

Figure 2.10 Schematic of a Hall sensor (left) and the A1324 sensor (right).
Sensors  13

Hall sensors produce a voltage that is proportional to the magnetic induction B. Their
mode of operation is explained in Figure 2.10 and is based on passing a known current
I through a semiconductor. In the presence of a magnetic field, the Lorentz force de-
flects the charge carriers—electrons and holes—towards perpendicularly mounted electrodes
(shaded). This creates a potential difference (a voltage) between the electrodes, which causes
a transverse electric field that counteracts the deflection from the Lorentz force such that the
following charge carriers can move towards the exit electrode undeflected. In equilibrium,
the voltage difference between the upper and lower electrodes is proportional to the mag-
netic induction B and can be measured with a voltmeter. The A1324 Hall sensor, shown on
the right in Figure 2.10, has signal-conditioning circuitry on board and only needs three pins
for ground, supply voltage, and output voltage. The latter is proportional to the magnetic
field, with a sensitivity of 50 mV/mT centered at 2.5 V when no field is present.
The ADXL335 is a three-axis integrated acceleration sensor based on micromachined
structures on a silicon substrate where an inertial mass is suspended by springs [12]. The
inertial mass is part of an assembly of capacitors driven by an AC voltage that is used to
measure the imbalance of a capacitive voltage divider. As opposed to our simplified model
with only one capacitor doublet, the real device uses a large number of interleaved capacitor
doublets in order to increase the sensitivity. Figure 2.11 illustrates the principle of operation
for a single direction. On the left in Figure 2.11 there is an AC-voltage generator that drives
the light-grey capacitor plates. The dark-grey inertial mass is placed halfway between the
driven plates, and in the absence of acceleration, the capacitances between the two light
grey plates and the inertial mass are equal. An acceleration introduces an imbalance in the
capacitances that affects the voltage level on the inertial mass. Comparing the phase and
amplitude of that signal with that of the driving AC signal yields direction and magnitude
of the acceleration. After some signal processing, it is then made available as Uacc on one
of the output pins of the ADXL335 in the range from 0 to 3 V, such that the voltage is
proportional to the acceleration in the range from -3 g to +3 g and is updated at a rate of
about 100 times per second.
The SM-24 is another type of accelerometer called a geophone, and is shown in Fig-
ure 2.12. It is based on a coil connected to the housing by springs embedded in a magnetic
field generated by permanent magnets that are attached to the housing. If the housing
moves, the coil remains stationary due to its inertia, and a voltage is induced in the coil,
which is proportional to the velocity and can be measured. The sensitivity is 28.8 V/(m/s)
and the device operates in the range of 10-240 Hz.

acc

C+dC Compare Phase


and Amplitude
C-dC Inertial
mass
Uacc
Spring

Figure 2.11 The operational principle of an ADXL accelerometer.


14  A Hands-On Course in Sensors Using the Arduino and Raspberry Pi

Figure 2.12 An SM-24 geophone with a diameter of about 30 mm.

Microphones convert sound to electrical signals and can be classified as sensors. Two
major classes are on the market. Dynamic microphones operate similarly to the geophones.
A coil, attached to a membrane, is excited by sound, moves in a magnetic field, and induces
an induction voltage in the coil that is amplified and measured. In electret microphones, the
membrane constitutes one electrode of a capacitor. If it moves, the capacitance changes,
and the amount of charge stored on the capacitor is pushed on and off the capacitor and
creates a current that is amplified and measured.
The electret microphone serves as a nice example with which to turn to current-based
sensors.

2.1.3 Current-based sensors


The BPW34 is a pin diode that generates a current of up to 100 nA depending on the
irradiance of up to mW/cm2 . Pin diodes are similar to conventional diodes and consist of a
semiconductor with a pn junction, which is created by doping semiconductor material, often
silicon based, with a material that has either five valence electrons, in which case it becomes
n-doped, or three valence electrons, in which case it becomes p-doped. Pin diodes, however,

E +Vb
n i p
electron raised
to cond band acceptor
levels R
Rf
nip
photon Vb _
conduction
band Ip Ip
OpAmp
donor Vo
levels
+

valence
band

Figure 2.13Energy-band diagram (left) and circuit (right) of a reverse-biased pin


diode in photoconductive mode.
Sensors  15

Figure 2.14Image of a BPW34 pin diode on the left and two phototransistors on the
right; an IR-sensitive BPX38 and an SFH3310, sensitive in the visible part of the
spectrum.

have an additional layer of un-doped, intrinsically (‘i’) conducting silicon in order to increase
the target area for the photons and provide a chance to produce additional charge carriers.
One operational mode of the pin diode, called photoconductive, is illustrated on the left-
hand side of Figure 2.13, which shows a simplified energy-band diagram of a reverse-biased
diode. Note that by convention, the upwards energy axis corresponds to the potential energy
of electrons that is lowest at the most positive voltage and that is found on the left-hand
side. In the figure the cathode (n side) is therefore at higher voltage than the anode (p
side) and results in all charge carriers being pulled out of the intermediate zone; electrons
to the left and holes to the right. This results in the diode blocking any current flow. The
extra layer of un-doped silicon provides extra potential charge carriers that act as targets
for photons, having energy higher than the band-gap. These photons create electron–hole
pairs by lifting electrons from the valence band into the conduction band, as indicated in
Figure 2.13. The applied voltage, which is more positive on the left-hand side, causes the
electrons to move to the left and the holes move to the right. Combined, this constitutes
a current Ip . We mention in passing that ionizing radiation, such as high-energy photons
and gamma rays as well as charged particles with high energies, create electron–hole pairs.
This makes pin-diodes suitable as radiation detectors. The circuit on the right-hand side of
Figure 2.13 shows an operational amplifier that converts the current Ip flowing towards its
negative input port into a voltage Vo = −Rf Ip on its output port. We will cover operational
amplifiers in more detail in the coming sections. A BPW34 pin diode is shown on the left
of Figure 2.14.
Phototransistors such as the BPX38 or SFH3310, both shown on the right of Figure 2.14,
are similar to normal transistors, but their base-collector diode is a reverse-biased photo-
diode, similar to the one described in the previous paragraph. It causes a current to flow
as a consequence of impinging photons. The base-emitter diode is already forward biased
and will ensure that the collector–emitter connection becomes conducting. Moreover, often
there is a lens to increase the number of photons impinging onto the base terminal with the
photosensitive area. Phototransistors sensitive to special spectral ranges such as infrared
radiation, by suitably choosing their band gap, can be used as flame detectors.
The sensors in imaging applications such as cameras are charge-coupled devices, or CCDs,
which are similar to a pin diode that is attached to a small capacitor, one for each pixel
of the camera. Exposure to light transfers a small charge to the capacitor. The often large
number of pixels are read out sequentially by transferring the charge from on capacitor to
the one closer to the external readout port. A bucket chain to transfer water that is emptied
16  A Hands-On Course in Sensors Using the Arduino and Raspberry Pi

Figure 2.15On the left we have a voltage divider to reduce the input voltage of 0-5 V
to 0-3.3 V. The right circuit shows the use of clamping diodes to protect the input
of the microcontroller to lie between ground and 5 V.

at the end point comes to mind. In a CCD, once the charge reaches the output port, it is
passed through a resistor, where it creates a voltage drop that can be measured.
Solar cells operate in a similar fashion to photodiodes in photovoltaic mode where they
provide a voltage to a load. They are, however, optimized to absorb as large a part of the
spectrum as possible, and also to have a large absorbing area, in order to maximize the
electric power available to the load.
After this brief overview of different analog sensors, we need to address how to prepare
the signals such that they can be easily interfaced. This preparatory stage is referred to as
signal conditioning.

2.2 SIGNAL CONDITIONING


The analog signals from the sensors can be too high or too low. They can be too noisy
or otherwise inadequate to directly feed to an analog-to-digital converter (ADC) or a mi-
crocontroller. In many cases some signal conditioning is needed, and we will discuss some
common methods in the following sections.

2.2.1 Voltage divider


In case the input voltage of the sensor exceeds the input range of what the microcontroller
can handle, we have to reduce the voltage by a voltage divider, which consists of two fixed-
value resistors. A typical example is to reduce the range from 0-5 V to 0-3.3 V, which is
accomplished by a combining two resistors with a ratio of R1 /(R1 + R2 ) = 3.3/5 = 0.66.
A close example is shown in Figure 2.15, with a 12 and a 22 kΩ resistor. The ratio is
22/34 = 0.65, which is close to the desired ratio. Other combinations with larger and
smaller values will work as well, as long as the ratio is correct. The sum of both resistors
should not be too small because that will draw a larger current from the 0-5 V voltage
source, and, depending on the internal resistance of the source, may affect the measured
values.
In order to improve the measurement sensitivity, resistance-based sensors are often wired
in a Wheatstone-bridge configuration. An example was shown on the right of Figure 2.1.
Here the voltage divider on the left side of the breadboard provides half the supply voltage
Sensors  17

Figure 2.16A bare operational amplifier shown on the left and shown wired as a line
buffer on the right. We omitted the supply wires on the latter schematic.

at its center tap (the lower-signal wire) because the two resistors are equal. The voltage
divider on the right-hand side is the same one, we encountered previously, with the upper-
signal wire connected to the point between the upper resistor and the LDR. Normally one
would choose the resistance of the right resistor to be in the middle of the range of interest
of the LDR, such that voltage-difference between the signal wires is close to zero, indicating
mid-range. In this way, depending on the light exposure, the voltage difference between the
wires varies around zero and the sign will tell us whether the exposure is lower or higher
than the expected mid-range value. Since we now deal with voltages that vary around zero,
it is easier to amplify that voltage in order to increase the sensitivity. For example, when
using a plain voltmeter, we can use a smaller voltage range.
In case we use a piezo-based sensor, the generated voltages can be much higher than is
acceptable in the following circuit such as a microcontroller. In such a situation, clamping
diodes, as shown on the right of Figure 2.15, are used. If the input voltage is between 0 and
5 V, the diodes are blocking, and the signal is passed on to the microcontroller. If, on the
other hand, the input voltage exceeds 5 V plus the forward voltage drop, the diode starts
conducting and shorts the input to the upper power rail of 5 V. If the input voltage is below
0 V, the lower diode starts conducting and shorts the input to ground. In either case, the
voltage delivered to the microcontroller is limited to 0-5 V plus or minus the forward diode
voltage drop. Many integrated circuits including microcontrollers have built-in clamping
diodes. The Raspberry Pi, however, is a notable exception.

2.2.2 Amplifiers
Very small electrical signals usually need to be amplified to reach levels adequate for further
processing. The standard device to achieve this is an operational amplifier or op-amp, shown
on the left of Figure 2.16. There are two input ports on the left, one labeled “plus”, one
labeled “minus”, and one output port. The latter delivers a voltage that depends on the
difference between the two input ports. In an ideal op-amp, the amplification factor is
infinite and we usually use some feedback mechanism to obtain a deterministic behavior,
as discussed below. Normally, op-amps require both positive and negative supply voltage,
even though sometimes it is possible to tie the negative supply rail to ground, in which case
only unipolar signals can be amplified.
Before discussing different circuits, we need to describe three basic principles that char-
acterize op-amps.
18  A Hands-On Course in Sensors Using the Arduino and Raspberry Pi

Figure 2.17 A non-inverting (left) and inverting (right) amplifier.

The input impedance of the input ports is “infinite”, which means that no current
flows into the op-amp and it will not load the upstream circuitry.
The op-amp tries to reduce the difference between the input ports V+ − V− to zero.
The amplification without feedback is quasi-infinite, and the output has a very low
impedance and can provide high output currents.

These simple rules will help us to design and understand the following circuits, but consult
[15] and [16] for a more extensive discussion.
We start by considering a line buffer, which is typically used as an impedance converter
that transforms the output of a sensor with a high impedance to a low-impedance signal
that is less susceptible to noise. We show the circuit on the right of Figure 2.16, where the
output of the op-amp is fed back onto the negative input port. By using the second op-amp
rule, we see that the op-amp tries to make the positive and negative input ports equal,
but negative is tied to the output, which forces the output to follow the positive input.
Moreover, by the first rule, the input impedance is high and no current (or at least very
small current) is drawn from the sensor, while the output is low impedance and can provide
a high current. Note that we omitted the connections to the supply rails on the right of
Figure 2.16, and will do so henceforth in order not to clutter the schematics.
The line buffer is essentially an amplifier with unit amplification, but if we require a
higher degree of amplification, we need to add two additional resistors to the circuit, and
arrive at the left of Figure 2.17. The two resistors R1 and R2 constitute a voltage divider
that forces the negative input voltage to be V− = Vout R2 /(R1 + R2 ). But, at the same time,
the op-amp forces V− = V+ , which, after solving for Vout , leads to Vout = V+ (R1 + R2 )/R2 ,
where (R1 + R2 )/R2 = 1 + R1 /R2 is the amplification factor. Since the output voltage Vout
has the same sign as the input voltage V+ on the positive input port, this configuration is
called a non-inverting amplifier...
...which hints at the existence of an inverting amplifier, for which we show the schemat-
ics on the right of Figure 2.17. To calculate the amplification factor, we note that the
input current Iin only flows through the input resistor R4 and the feedback resistor R5
because the input impedance of the op-amp is essentially infinite and no current flows into
the input ports. But the equality of the current in the input and the feedback resistor
implies I = (Vin − V− )/R4 = (V− − Vout )/R5 . Moreover, we observe that the positive in-
put port is grounded, which forces the negative input port to be on ground potential as
well. This implies V− = 0, and the relation between input and output voltage becomes
Sensors  19

Figure 2.18A difference amplifier (left) and the same circuit with adjustable V1
(right) that is used to subtract the baseline.

Figure 2.19 Instrumentation amplifier (left) and logarithmic amplifier (right).

Vout = −Vin R5 /R4 , where the negative sign indicates that the amplifier is inverting. Note
that we can add several input resistors R4 in parallel with one end connected to the negative
input port. This allows us to add the currents passing through the parallel copies of R4 , and
we obtain a summing amplifier. The resistor values were simply chosen to be in a reasonable
range. They need to be determined adequately for each application.
Sometimes the signal one wants to measure changes around a non-zero baseline. Exam-
ples are the Hall sensor A1324 from the previous section, where zero magnetic field produces
2.5 V and the magnetic field added or subtracted from that value depending on its polarity.
In order to increase the resolution, we want to amplify not the signal, but the difference of
the signal to the baseline. In other words, we need a circuit to subtract the baseline and
amplify the difference. A differential amplifier as shown in Figure 2.18 accomplishes this
feat, provided that R2 = R4 and R1 = R2 . The output voltage Vout in that case is given by
Vout = (V2 − V1 )R2 /R1 . Adding a potentiometer that adjusts V1 between the positive and
negative supply rail subtracts it as baseline voltage.
20  A Hands-On Course in Sensors Using the Arduino and Raspberry Pi

Figure 2.20 Amplifying a weak signal and shifting it to mid-range between the power
rails.

A circuit similar to the one in Figure 2.18 but with line buffers on the inputs is called
an instrumentation amplifier, and an example is shown on the left of Figure 2.19. Normally
it is not necessary to build instrumentation amplifiers from discrete components. There are
ready-made circuits available such as the AD620 or INA131.
Often, sensors produce small voltages that vary around zero, but the analog-to-digital
converter (ADC) requires an input range of 0 to 5 V. We thus face the problem of amplifying
a bipolar signal and changing the baseline level to mid range of the ADC. We show a circuit
that amplifies by approximately a factor of 10 in Figure 2.20. The amplification is mainly
determined by the ratio of the feedback resistor R3 to the input resistors R1 and R2 . The
voltage divider of R6 and R8 provides the mid-range offset voltage. The average level of the
output voltage crucially depends on the tolerances of the resistors, and in order to place
the level safely in mid range, we use the capacitor C1 to first remove the DC level of the
output signal before adjusting it properly to mid-range, with the voltage divider consisting
of R4 and R5 .
In case we need to amplify input signals that vary over a huge range of values, a loga-
rithmic amplifier such as the one on the right of Figure 2.19 is a useful circuit. It can be
shown that the relation between input and output voltage is Vout = −Vt ln(V1 /Is R), where
Vt is the thermal voltage and Is the saturation current of the diode. Swapping the diode
and the resistor results in an exponential amplifier.
A close relative to the operational amplifier is the comparator. It can be visualized as
an op-amp with very large, even infinite, amplification, whose output port saturates at the
power rails. If the voltage at the positive input terminal of a comparator is larger than
that on the negative input terminal, the output voltage is very close to the positive supply
voltage. On the other hand, if the voltage on the positive input terminal is lower than that
on the negative, the output is close to ground potential. In this way it translates the input
voltages to a binary digital state. A comparator may therefore be considered as a 1-bit
analog-to-digital converter, and we will see in a later section how it is used to extend the
number of bits of the conversion. Some comparators have the threshold when switching
from low to high output configured to be slightly higher than the threshold switching from
the high output state back to the low one. This small hysteresis prevents the output from
Sensors  21

Figure 2.21 A simple low-pass (left) and high-pass (right) filter.

switching back and forth uncontrollably, should the voltages on the two input terminal be
very close.
After the basics of signal amplification, we will now address the question of how to reduce
noise in the circuits and decrease the sensitivity of a circuit in an undesired frequency range.
This is the realm of filters.

2.2.3 Filters
The task of filters is to remove certain frequencies from an electrical signal such as all high
frequencies, in which case the filter is called a low-pass filter. An example is a low-pass filter
that removes “hissing” in audio-signals. The converse filter is a high-pass filter that removes
low frequencies. An example is a anti-rumble filter found in old vinyl record players. If we
know that the desired signal contains only a certain range of frequencies and we wish to
remove all others, we use a band-pass filter. An example is the IF filter found in radios that
are based on the super-heterodyne principle. And finally there are filters that remove only
frequencies in a narrow band. They are called band-stop or notch filters. An example is a
filter that removes the omnipresent 50 Hz or 60 Hz hum coming from the power grid.
We first consider a low-pass filter, which in the simplest incarnation is a frequency-
dependent voltage divider made of a resistor with resistance R and a capacitor with ca-
pacitance C, as shown on the left of Figure 2.21. For a refresher of basic concepts circuit
theory, such as impedance, please consult appendix A. In our circuit, the capacitor has an
impedance 1/iωC, which gets smaller with increasing frequency ω = 2πf. Intuitively, the
higher frequencies are shorted to ground. If we build a voltage divider as shown on the
left of Figure 2.21, the output voltage Vout is given by Vout = (Vin /iωC)/(R + 1/iωC) =
Vin /(1+iωRC) and we see that it is attenuated with increasing frequency ω and, conversely,
the low frequencies are unaffected, hence the√name low-pass filter. The frequency where the
signal amplitude is attenuated by a factor 2 is given by ωc = 1/RC, and the imaginary
unit indicates that there is a phase shift between input and output voltage that depends
on the frequency. Equivalently, a low-pass filter can be constructed with an inductor with
impedance iωL and resistor R, but in many operational situations the inductances have
values that are difficult to find; therefore filters are usually constructed from resistors and
capacitors. The frequency dependence of the filter asymptotically behaves as the first inverse
power of ω, and the filter is called a single-pole filter. Cascading two such filters results in
two-pole low-pass filters that exhibit a steeper frequency-dependence of 1/ω 2 .
Swapping the resistor and capacitor in the low-pass filter results in the high-pass filter
shown on the right of Figure 2.21, which has a frequency dependence of iωRC/(1 + iωRC)
Exploring the Variety of Random
Documents with Different Content
"Herra kuningas", hän sanoi, "taivas on synkkä raskaista
lumipilvistä, enkä minä enää näe tuota pikkuista valoa." Kuningas
sanoi: "mene vielä takaisin vuoren kukkulalle."

Taas sanoi kuningas hetken perästä: "missä vartiani on?" Ja vartia


tuli. Mutta nyt havaitsi kuningas, että vartia vapisi ja hän oli aivan
sokea.

Kuningas sanoi: "sinä uskollinen vartiani, miksi sinä vapiset? Ja


kuinka sinä tulit noin sokeaksi?"

Vartia sanoi: "herra kuningas, pilvet ovat kadonneet, ja tähti,


suurempi ja kirkkaampi kuin kaikki muut tähdet, loistaa taivaan
kannelta. Tästä syystä minä vapisen, ja sen näkö saatti minun
sokeaksi."

Kuningas sanoi: "mitähän tämä tietänee? Eikö valkeus nyt ole


kadonnut ja pimeyden valta ikuinen?"

Mutta kaikki peikot seisoivat yli-ympäri ääneti ja vavisten, eikä


kukaan vastannut.

Viimein yksi joukosta sanoi: "herra kuningas, täällä seisoo oven


vieressä kaksi ihmislasta. Kysytään heiltä; ehkä he tietävät enemmän
kuin me."

Kuningas sanoi: "kutsukaat tänne lapset." Heti vedettiin Fredrik ja


Lotta kuninkaan istuimen eteen, ja arvaa tuon helposti, että ne sillä
kertaa olivat hyvin alla päin, pahoilla mielin. Kuningatar näki heidän
suuren pelkonsa ja sanoi yhdelle tonttu-ämmälle, joka seisoi
valtaistuimen vieressä: "annappas lapsiraukoille vähän lohikäärmeen
verta ja pari koppakiiskin kuorta virvoitukseksi, että he saavat
suunsa auki."

"Syökäät ja juokaat! syökäät ja juokaat!" sanoi ämmä. Mutta


tähän ei lapsilla ollut ensinkään halua.

Kuningas sanoi lapsille: "te olette nyt täällä minun vallassani, ja


minun on voima muuttaa teidät variksiksi taikka hämähäkeiksi. Mutta
minua haluttaa panna yksi arvoitus teidän eteenne, ja jos osaatte
selittää sen, annan minä viedä teidät eheinä takaisin kotiinne.
Suostutteko siihen?"

"Kyllä me suostumme", sanoivat lapset.

"No niin", sanoi kuningas. "Mitä se tietää, kun valkea koittaa


keskellä vuoden pimeintä yötä, jolloin kaikki valkeus on kadonnut ja
peikot hallitsevat maailmaa? Kaukaa idästä näkyy tähti, joka loistaa
heleämmin, kuin kaikki muut tähdet, ja uhkaa vallalleni perikatoa.
Sanokaat minulle, lapset, mitä se tähti merkitsee?"

Lotta sanoi: "se on tähti, joka joulu-yönä nousee Betlehemin ylitse


Juudan maalla ja loistaa ympäri koko maailmaa."

Kuningas sanoi: "miksi se niin loistaa?"

Fredrik sanoi: "siksi, että tänä yönä on Vapahtajamme syntynyt, ja


hän on se valkeus, joka valaisee koko maailman. Ja tästä alkaa
valkeus enetä ja kaikki päivät uudestaan pidentyä."

Kuningas rupesi kovasti vapisemaan istuimellansa, ja hän sanoi


jälleen: "mikä sen valkeuden herran ja kuninkaan nimi on, joka tänä
yönä on syntynyt ja joka on tullut vapauttamaan maailmaa pimeyden
vallasta?"
Molemmat lapset sanoivat: "Jesus Kristus, Jumalan poika."

Mutta tuskin tämä oli lausuttu, ennenkuin koko vuori alkoi väristä
ja vavista ja luhistua kokoon, ja raju tuuli puhalsi suuren salin lävitse
ja kukisti kuninkaan istuimen, ja tähti paistaa heloitti sisään
pimeinten rotkojen ylitse, ja kaikki peikot hajosivat kuin varjot ja
savu, kunnes ei muuta ollut jäljillä, kuin jäinen joulupuu, ja tämä
alkoi kiiltää ja sulaa, ja korkealta ilmasta rupesivat enkelien äänet
soimaan kuin kanteleet. Mutta lapset peittivät kasvonsa käsillään
eivätkä rohjenneet katsahtaa ylös, ja heihin tuli ikäänkuin uni, kun
jotakuta kovin väsyttää, eivätkä he enää tietäneet, mitä vuoressa
tapahtui.

Kun he jälleen heräsivät, makasivat he kumpikin vuoteessansa, ja


valkea paloi pesässä, ja vanha Kaisa, jonka aina oli tapa herättää
heidät, seisoi vuoteen vieressä ja sanoi heille: "joutukaat ylös, että
ehditte kirkkoon!"

Fredrik ja Lotta nousivat istualle ja katselivat hämmästyneinä


Kaisaa tokko hän kenties oli vaan kyynärän pituinen, parta leuassa,
ja tahtoi tarita heille lohikäärmeen vertä ja koppakiiskin kuoria.
Mutta sen sijaan he huomasivat, että kahvipöytä tuoreihine
joulukakkuinensa jo seisoi valmiina, sillä jouluaamuna kaikki lapset
saivat kahvia, vaikk'ei sitä tapaa muutoin pidetty. Ja ulkoa kuului
kulkusten kilinä, ihmisiä lähti pitkät jonot kirkkoon, ja valkeita näkyi
kaikista akkunoista, mutta kaikkein kirkkaammalta loisti kirkko.

Fredrik ja Lotta katselivat toinen toistansa eivätkä tohtineet jutella


Kaisalle, että he olivat olleet peikkojen joulua viettämässä. Kenties
hän ei olisi uskonut heitä, vaan nauranut ja sanonut, että he olivat
nukkuneet koko yön vuoteessansa. Et sinä sitä tiedä, enkä minä sitä
tiedä, eikä kukaan oikein tiedä, kuinka se asia oli. Mutta jos sinä
tiedät sen, ja jos minä tiedän sen, niin emme ole kumpikaan sitä
tietävinämme, ja joll'ei kukaan sitä tiedä, ei myöskään kukaan tiedä,
tiedätkö sinä sen ja tiedänkö minä sen. Ja nyt sinä tiedät, mitä minä
tiedän, joka en mitään tiedä, ja hauska olisi tietää, mitä sinä tiedät
ja tiedätkö sinä enemmän kuin minä tiedän.
KUN ON JUHANNUS.

Juhannuksena on vihantaa ja valoisaa elää maan päällä. Silloin kaikki


linnut laulavat, silloin kaikki puut viheriöitsevät ja aurinko sukeltaa
järveen sill'aikaa, kun kukko pikimältään ummistaa silmänsä orrella,
ja nousee taaskin, ennenkun kukko edes on ennättänyt saada sukat
jalkaansa.

Suomi on niin suuri maa, että pohjoisissa osissa on kesä paljon


valoisampi ja talvi paljon pimeämpi kuin eteläisemmissä seuduissa.
Sen vaikuttaa maan erilainen etäisyys päiväntasaajasta, josta saa
oppia maantieteessä.

Tiirassa, Helsingissä ja Viipurissa täytyy sytyttää kynttilä juhannus-


yönä, jos tahtoo lukea, ja jos taivas sattuu olemaan pilvessä. Mutta
Oulussa voi kolmen kuukauden kuluessa lukea kirjaa läpi koko yön
ilman kynttilää, jos olisi kuinkakin pilvistä. Oli kerran pieni koira, joka
oli syntynyt Huhtikuun loppupuolella ja siis Heinäkuun lopulla oli
kolmen kuukauden vanha. Koko hänen elämänsä aikana ei ollut
kertaakaan pimeä. Kun sitte Elokuu tuli ja yöt rupesivat
pimenemään, oli pennun mielestä kovin kummallista. Hän luuli, että
koko luonto oli kömpinyt säkkiin, ja asettautui rappusille ja rupesi
haukkumaan pimeyttä.
Juhannus-aattona on poikien tapana olla niityllä pallosilla, ja tytöt
leikkivät ja tanssivat. Ne, joilla on varaa, saavat tippaleipiä, rinkeliä
ja mettä, ja köyhät lapset saavat sitä vaan katsella, ell'ei joku ja'a
osaansa heidän kanssansa. Yöllä palaa korkeilla paikoilla tuli, jota
Suomessa nimitetään kokoksi ja muutamilla seuduilla Ruotsissa
Balder'in rovioksi, ja tuli merkitsee, että kaikki ihmiset iloitsevat
valon ajasta. Kun pimeyden aika on jouluna, palavat kynttilät
kirkkaina kirkossa, ja se merkitsee, että Herramme Jesus Kristus on
maailman ijankaikkinen valkeus, joka loistaa kaiken pimeyden läpi
täällä maan päällä. Mutta juhannuksen aikaan on jumalanpalvelus
koko luonnossa ja silloin on koko metsä kirkkona, siellä valaisee
auringon komea lyhty taivaan katolta, sinikellot siellä soittavat,
kunnianarvoisat männyt saarnaavat, kosken kuohu siellä messuaa, ja
tuuli soittaa urkuja puitten latvoissa, ja pienet linnut heleillä
äänillänsä laulavat alinomaa virsiä Jumalan kiitokseksi.

Esipuhe kesän saarnaan on otettu Isä meidän alkusanoista:


"Pyhitetty olkoon sinun nimes. Lähestyköön sinun valtakuntas.
Tapahtukoon sinun tahtos niin maassa kuin taivassa." Ja lintujen
lauluilla on sanoja, vaikka kaikki eivät niitä ymmärrä. Nämä sanat
ovat linnut oppineet Jumalan enkeleiltä ja ne kuuluvat näin: "Kunnia
olkoon Jumalalle korkeudessa ja maassa rauha ja ihmisille hyvä
tahto!"

Mutta kukkaset sanovat toisillensa: "Kuningas Salomo kaikessa


kunniassansa ei ollut vaatettu niinkuin yksikään meistä."

Totta on hyvä kiittää ja ylistää Jumalaa sekä kirkossa muiden


kanssa että yksin kamarissaan. Mutta iloista on myöskin, kun koko
maa ylistää Jumalan hyvyyttä ja kun seisoo päivän paisteessa
metsässä ja kuulee puitten puhuttelevan toinen toistansa: "katso,
me olemme kaikki Jumalan lapsia ja mitä me olemme, siksi olemme
me tulleet Hänen sanomattoman armonsa kautta. Kiittäkäämme ja
ylistäkäämme Hänen pyhää nimeänsä!"

Minä tahdon kertoa teille jotakin hauskaa ja kaunista, joka


tapahtui eräänä juhannus-yönä.

Kaarle Kustaa ja hänen sisarensa Sohvi olivat nukkuneet


iltapuolella, voidaksensa pitää pienet silmänsä auki, kun yö tuli. Kello
6 illalla söivät kumpikin voileipänsä ja lasisen maitoa, ja sitte he
menivät niitylle palloinensa, sauvoinensa ja heittorenkainensa. Ja he
olivat kumpikin saaneet isältänsä pienen hopearahan ostaaksensa
jotakin hyvää, sillä siellä istui tavallisesti muijia, jotka myivät vohvelia
ja pannukakkuja lapsille.

Niityllä oli monta poikaa ja tyttöä jo ennestään. Siellä oli vallaton


Valtteri, joka joutui pahaan pulaan kiekkonsa kanssa, ja Kalle, joka
oli opettanut Kaisalle Euroopan karttaa ja Matti, joka oli puolustanut
Urholan linnaa ja Emma, joka oli kuullut sinikellojen soittoa, ja Aina
ja Terese, jotka olivat tavanneet haltijan metsässä. He heittivät
palloa ja kiekkoja, olivat "leskisillä", leikkivät "haukkaa ja kyyhkystä."
Ja se oli hyvin hauskaa. Itse varpusetkin, jotka istuivat läheisen
ladon katolla, visertelivät omalla hauskalla tavallaan, niinkuin niiden
on tapana, kun niiden mielestä jotakin on oikein sukkelaa
maailmassa.

Kun nyt Kaarle Kustaa ja Sohvi olivat juosseet väsyksiin asti, sanoi
veli sisarelle: "tule, niin menemme maantien varrelle muijan luo ja
ostamme vohvelia rahallani!" — "Niin, tehdäänpä niin", Sohvi sanoi.

Mutta maantien varrella istui viisi tai kuusi poikaa ja tyttöä, jotka
par'aikaa ajoivat hottiinsa ja latoivat sokeria vohveleille niin paksusti,
että kärpäset olisivat voineet ajaa lumiauraa niiden päällä, jos vaan
olisivat saaneet lupaa.

Aivan lähellä istui pieni, repaleinen kerjäläistyttö, joka ääneti


katseli vohvelia. Hän ei sanonut mitään, hän ei pyytänyt mitään,
mutta alinomaa katseli hän sinnepäin ja toisinaan imi hän pieniä
sormiaan.

"Sinun on varmaankin kovin nälkä", sanoi Sohvi. "Etkö ole syönyt


mitään ennen tänäpäivänä?"

Pienokainen istui alussa ääneti eikä tahtonut vastata. Mutta


lopullisesti sanoi hän: "minä en ole syönyt mitään eilisestä."

"Tässä, ota minun rahani ja osta itsellesi ruokaa", sanoi Kaarle


Kustaa. "Me olemme syöneet voileivän jo aikaisemmin iltapuolella, ja
paitsi sitä, on minun sisarellani vielä yksi raha."

"Säästäkäämme minun rahani siksi, kun meidän on enemmän


nälkä", sanoi
Sohvi. "Niin", sanoi Kaarle Kustaa.

Ja sitte lähtivät he taas leikkimään. Mutta tyttönen nyykäytti:


"kiitoksia, kiitoksia!" Eikä kukaan tiennyt, mitä hän rahallansa osti.

Nyt tuli jo myöhäinen ilta ja muutamat lapset menivät kotiin


nukkumaan, toiset lähtivät metsään polttamaan kokkoa.
Korkeimmalla kukkulalla oli iso läjä pihkaisia puita ja muuta, jota
sukkelasti saa palamaan ja kun aurinko laski, sytytettiin se, ja silloin
rupesi tuo iso latomus palamaan. Kylläpä se oli komea nähdä!
Tummat kuuset seisoivat ympärinsä; korkealle tuprusi savua ja
liekkiä sinistä yötaivasta kohti ja valkean ympärillä tanssivat pienet ja
suuret. Iltarastas, joka juuri piti laulajaisia metsässä, vaikeni hiljaa;
hyttyset olivat niin ihastuksissaan, että lensivät suorastaan tuleen ja
repo metsässä kurkisti varovaisesti kiven takaa, ottaaksensa selkoa,
mitä kummallisia laitoksia tuo mahtoi olla.

Kun ensimmäiset polttoaineet loppuivat, olivat kaikki pojat valmiit


laahaamaan sinne uutta ja nyt kuului hoilotusta ja naurua, jo olipa
oikein iloa metsässä! Mekot ja housut, ne saivat maksaa pidot,
pihkaisiksi ja nokisiksi kun tulivat.

"Hyi, Kaarle Kustaa!" sanoi Sohvi veljelleen, joka tuli laahaten


suurta puuta, joka oli puolta pitempi kuin hän itse. "Mitä äiti sanoo,
kun niin ryötät vaatteesi?"

"Onhan se kyllä paha", sanoi Kaarle Kustaa, vaan ei voinut


kuitenkaan muuta kuin nauraa. "Tiedätkö mitä, Sohvi? Sinulla on
pitkät viikset ja vieläpä leukapartaakin noesta. Kylläpä olet oikein
kaunis!"

Sohvi oikein pelästyi, kasteli nenäliinansa nipukkaa ja rupesi


pyyhkimään huuliansa. "Onko jo pois?" kysyi hän.

"Niin, tulevaksi kerraksi", sanoi Kaarle Kustaa, ja pian olikin


Sohvilla uudestaan viikset, sillä hän tahtoi väkisinkin puhaltaa
valkeaa, kun ei se oikein ottanut palaakseen.

"Nyt menemme ostamaan voileipää", sanoi Kaarle Kustaa, "sillä


minun on suunnattoman nälkä."

"Niin tehdäänpä niin", sanoi Sohvi. "Minulla on vielä rahani."

Mutta tällä kertaa seisoi tien varrella pieni poika melkein ilman
vaatteita, sillä hänen päällänsä oli ainoastaan repaleinen paita.
Ja kun hän seisoi valkean ääressä, oli hänen lämmin, mutta kun
hän tahtoi auttaa muita kantamaan polttopuita, oli hänen kylmä, että
hampaat tärisivät, sillä yö-ilmassa oli vilponen, niin kuin useinkin on
juhannuksen aikana. — "Miksi et pue enemmän päällesi?" kysyi
Kaarle Kustaa häneltä.

"Minulla ei ole vaatteita", poika vastasi ja hiipi niin lähelle valkeaa


kuin hän taisi.

"Semmoinen rehjänä, jolla ei edes ole vaatteita, voisi mennä


kotiinsa ja panna maata", sanoi pitkä Tuure, joka seisoi siinä lähellä.

"Minulla ei ole kotoa, jossa saisin panna maata", vastasi


kerjäläispoika.

"Sinulla on kaksi pitkä takkia", sanoi Sohvi Tuurelle, joka kantoi


päällystakkiansa käsivarrella. "Lainaa toinen pojalle!"

"Lainaa!" naurahti Tuure. "Niin, jos joku maksaa vuokraa takistani,


niin kyllähän lainaan takkini siksi, kun aurinko nousee."

"Tuossa sen saat", sanoi Sohvi, ja hän antoi Tuurelle


hopearahansa. Ja takki puettiin pojan päälle ja hänen oli lämmin ja
hyvä olla ja hauskaa. Mutta ei kenelläkään ollut hauskempi kuin
Kaarle Kustaalla ja hänen sisarellansa, vaikka he olivat ilman sekä
vohvelia, voileipiä että rahaa.

Niin paloi valkea koko yön, eikä se yö ollut pimeä. Sillä hetken
kuluttua puna taivaanrannalla koillisessa rupesi hohtamaan yhä
heleämmin ja lopullisesti tuli se kirkkaaksi kuin keltaisin kulta. "Heti
aurinko nousee", sanoi Kaarle Kustaa. "Tulkaa, nouskaamme vuorelle
paremmin nähdäksemme!" "Missä on takkini? Tahdon takkini", huusi
Tuure, joka oli ottanut maksun siitä, kun oli tehnyt hyvän työn. "Oi,
minkälainen narri minä olinkaan!" huusi hän. "Nyt olen kadottanut
hopearahan, jonka vuokraksi sain!"

Ei ole milloinkaan siunausta siitä, jos ansaitsee rahaa sillä, jota


köyhille annetaan. Takkinsa löysi Tuure kyllä mäellä, mutta iloista
mielialaa ei hän löytänyt. Hän oli harmissaan ja tiuskasi kaikille
ihmisille. Ja vierasta poikaa ei näkynyt enää. Ei kukaan tietänyt,
mihin hän oli kadonnut.

Kun Kaarle Kustaa ja Sohvi tulivat vuoren korkeimmalle kohdalle,


näkivät he ihmeekseen, että nuo molemmat köyhät lapset, jotka
olivat saaneet heidän hopearahansa, olivat siellä ennen heitä.
Eivätkä he enää näyttäneet köyhiltä eivätkä surullisilta. Tyytyväisyys
loisti heidän kasvoistaan ja he sanoivat: "Koska te olette olleet hyviä
meille, niin kiitämme teitä niinkuin ei kukaan ole kiittänyt teitä ennen
meitä. Asettukaa polvillenne lähelle meitä!" Kaarle Kustaa ja Sohvi
laskeutuivat polvilleen, vaikka he eivät ymmärtäneet, mitä lapset
tarkoittivat. He unohtivat, että he olivat sekä nälkäisiä että unisia. He
ajattelivat: "mitä me nyt saamme nähdä?"

Samassa hiljeni metsä niin hiljaiseksi, että kuuli hyttysen surinan.


Mutta hyttyset laskivat siipensä, linnut vaikenivat; yksin raju
koskikaan ei enää kohissut kallioita vastaan metsässä.

Samassa kultainen valo säteili yli koko taivaan kannen ja suuri,


loistava aurinko kohosi hiljaa taivaan rannalle, ja oli kuin ilon
värähdys olisi tuntunut läpi koko luonnon. Samana hetkenä kaikki
luonnon äänet rupesivat taas kuulumaan, hyttyset surisivat, linnut
lauloivat, koski kohisi ja suuri metsä rupesi suhisemaan.

"Huomatkaa nyt!" sanoivat kerjäläislapset.


Silloin näkivät Kaarle Kustaa ja hänen sisarensa, miten pienet
läpikuultavat enkelit täyttivät ilman; niitä oli luvultansa miljoonia ja
legioonia, ja ne liehuivat ylös ja alas kukin holhokkinsa luo, sillä
jokaisella puulla oli enkelinsä, ja jokaisella kukkasella omansa ja
jokaisella eläimellä oli oma suojelushenkensä.

Silloin sanoi Sohvi veljellensä: "Näetkö, että kaikilla luoduilla


olennoilla on suojelushenkensä, joka vie heidän rukouksensa
Jumalalle. Mutta meillä molemmilla ei ole." "Niinkö luulette", kysyivät
kerjäläislapset, "Ketä me sitte olisimme? Ettekö jo ymmärrä, että me
olemme teidän suojelusenkelinne? Ja vaikka te ette ole nähneet
meitä ennen, niin olette tunteneet meidät teidän sydämmissänne
joka kerran, kun olette rukoilleet Jumalaa taikka tehneet jotakin
hyvää. Juuri me olemme levittäneet valkoiset siipemme kätkyenne
yli, kun te olitte pienet. Me käymme joka hetki teidän vieressänne ja
Jesuksen nimessä varjelemme teitä kaikesta pahasta tässä
maailmassa. Ja me seuraamme teitä läpi koko elämänne, jos vaan
pelkäätte Jumalaa ja noudatatte hänen käskyjänsä kuuliaisuudessa
ja rakkaudessa ja rauhassa ja totuudessa elämän loppuun."

Köyhäin lasten näin puhuessa tulivat he niin loistavan kirkkaiksi ja


läpikuultaviksi, että saattoi heidän lävitsensä nähdä auringon ja
puitten lehdet, kunnes he vähitellen muuttuivat valkeiksi pilviksi
hohtavassa aamuruskossa.

Ja Kaarle Kustaa ja hänen sisarensa lupasivat jotakin toinen


toisillensa. He tahtoivat aina elää niin, että heidän hyvät enkelinsä
saisivat heistä iloa. Ja kun he nostivat silmänsä, kuulivat he metsän
saarnan ja lintujen virsiä juhannuksen aikaan: "Pyhitetty olkoon
sinun nimes. Lähestyköön sinun valtakuntasi. Tapahtukoon sinun
tahtosi niin maassa kuin taivaassa."
KUKKAIN HALTIAN JA
AALLOTTAREN SATUJA.

1. Kultakärpänen

(Kukkain haltia kertoo.)

Miss' on oravan jäljet ja muurahaistie?


Lukin seittiin laaditko silmäsen sie?
Mehiläisiä silmäsi nähnyt on.
Vaan tunnetko keijuisten tuomion?

Vähä kärpänen kiilteli kullasta vain.


Sanoi ampiaispoika: — ol' armahanain!
— Mehiläinen on kultani, kiitos vaan…
Se nyt kärpäsen kuoletti vaapsellaan.

Ja kun kuu rupes laaksohon loistelemaan,


Tuli keijuiset yhtehen tuomitsemaan,
Ja nyt kuolohon tappaja tuomittihin,
Mehiläinen sen tuomion täyttikin.
Vähä kärpänen lehtisen kuihtuneen
Sai keijuislaaksossa arkukseen.
Suruvirsiä sääsket veisasi.
Koko niitty se kastetta kyynelsi.

2. Punainen lippu.

(Aallotar kertoo.)

Ilo Aaltolass' oli riehuva niin,


Kun louna vei siskoni tanssijaisiin,
Ja he raivosti tanssi… Mut poikanen, kas!
Oli karilla seitsemänvuotias.

Hän ol' uljas, ei vaaraa arvannutkaan.


Piti vain punalippua kourassaan.
— Uros aalto, nyt leikimme! Käy sotimaan!
Käy pääll', ota lippuni, jos saat vaan!

Ja nyt lainehet roiski ja räiski ja löi,


Karin ympäri raivoissaan elämöi,
Mut ne ruhjotuin päin alas vaipui vaan:
Sitä poikainen nauroi riemussaan.

Lumivuorena hyökylaine nyt käy


Yli kallion… ei koko karia näy…
On poikakin poissa: mä uhmailevan
Punalippusen aallolla näin viruvan.

3. Jalopeura.
(Kukkain haltia.)

Jalopeurani, oi!… Saharassa jos sen


Olisit jalon nähnyt harppauksen!
Oli uljas se päivinä nuoruuden,
Erämaan kuningas, pöpö tiikerien.

Se pit' halpana väijyvän pantterin


Sekä myös pahan, pelkurin sakaalin.
Jalopeuraa ryntäs se vastahan,
Löi maahan norsunkin vahvimman.

Niin ennen. Nyt kaupunkipaikassa näin


Väen virtaavan eläintarhaa päin.
Jalopeura, se kauhistus erämaan,
Oli pilkkana julkean joukon nyt vaan.

Hampaitta ja kynsittä karsinassaan


Se nyt selkää joukolle köyristi vaan,
Sai kuumaa rautaa, ruoskaa sai.
— Jalopeurani, parempi kuolema kai!

Ja se alkoi ääntäni kuuntelemaan.


— Jalopeurako riemuin ei kaatuiskaan?
Vain arvoton kahlitun on elo tää,
Noin pilkkaa täynnä ja myös häpeää.

Lisäs sanani naurua katsojain.


Pedon nyt piti hyppiä kissana vain,
Ja johtaja nosti jo ruoskaa… Ui!
Jalopeura nyt hyppyhyn kuuristui.
Ja se pyövelinä kimppuun karkasi. Kas,
Jalopeurani nyt oli taas kuningas.
Tyrannin löi se ja raukenevin
Mua katsehin silmäs ja kuolikin.

4. Meren syvyydessä.

(Aallotar.)

Valas purskuva mun oli ratsunani.


Syvimpään merehen menin ratsastain.
Yhä hiljaa siellä on, on iki yö;
Mut on sielläkin Herra ja Herran työ.

Rumat, kauheat, kolkot sen vuoret on.


Väritön muta paksu ja muodoton.
Lohikäärmeet hirveät siell' asustaa,
Meren viemiä uhreja ahmustaa.

Ei ääntä, ei niin valon rahtuakaan!


Meri määrätön rintaa painoi vaan.
Jotakin putos mulle nyt jalkoihin;
Minä kummastuin otin sen sylinhin.

Näkymättömät peikot nielläksehen


Sitä pyydysti multa; mä säilytin sen,
Ja mä aaltojen pauhuun ratsastin,
Valon näin sekä ilmaa henkäilin.

Ja, kas! hukkunut laps oli mun sylissäin,


Mitä armahin tyttö… Sen henkivän näin,
Sopet suun, tosin kelmeät, liikahtikin;
Pudonneen sen laivasta arvasin.

Sepä syvään uppos, ei kuollutkaan.


Ylös nousin mä rantahan kukkaisaan,
Sitä kukkain keskellä suutelin: oi,
Ilo suuri! se auki jo silmät loi.

Niin kaukana, pienenä pilkkuna vaan


Lens purje tuulessa joutuisaan.
Siell' äiti itkevä seisoen
Yhä katseli, katseli vain merehen.

— Alas laskeos, laivuri, venhe nyt.


Meri tyttöni juuri on ryöstänyt!
— Vene ei täss' auta! mi jää, se jää:
Peninkulmaa on syvä seutu tää.

Mä nyt saavuin vierehen laivan sen;


Laps ui yli aallon hymyillen.
— Ulos venhe! Lapsens äiti jo saa.
Meri mykkäkin kiitti nyt myös Jumalaa.

5. Lähde.

(Kukkain haltia.)

Hämehessä mun on kivilinnojain:


Yli metsän vuoret ne siintää vain.
Rusopilviä niillä on aamuisin,
Siell' untuvi pohjonen iltaisin.
Siell' on laaksossa järvi ja honkiakin,
Ja järvessä saari on kukkaisin,
Ja saarella luola on pylväineen
Ja luolassa lähde suihkuineen.

On lähtehen reunalla valkopää,


Satavuotinen prinsessa: kuihtunut tää.
Hän laskevi pisarat kaikki vain,
Lorinaa tuon lähtehen tarkastain.

Oli kahdeksantoista hän, kun sotimaan


Ritarinsa jo puolesta riens isänmaan,
Ja hän vannoin varrota sulhastaan,
Kunnes lähteess' ei ole tippaakaan.

Minun linnani kaukaa haamuittaa,


Veden käydessä luolanakin vipajaa:
Yhä lähde se tippuvi, tippuvi vain.
Yhä varroten laskevi prinsessain.

6. Sumusaaret.

(Aallotar.)

Itämeressä mulla on kareja: nuo


Kimaltain ylös aallosta päänsä luo.
Ne illan usvassa nousevat,
Valoss' aamun aaltohon vaipuvat.

Kummeksivat rannalla lapset niin:


— Mepä soudamme saarihin siintäviin!
Veden siltaa sinne ei pitkältä lie,
Peninkulmaa pitkä ei kai se tie.

— Mitä, tyttöni, annat, jos soutaisin,


Sulle valkokukkasen noutaisin?
— Somimman punaruusuni antaisin;
Vaan aamuksi tullos sä takaisin!

Sumun maahan poika läks soutamaan,


Muut lapset rannalla vartosi vaan.
Koko yön he vartosi ahkeraan,
Vaan ei vene varrottu tullutkaan.

Kun mä eilen uin sumusaaria päin,


Venosen minä aaltoa kyntävän näin.
Mies vanha souteli venhossaan,
Mut hän kaukana viel' oli satamastaan.
TOTUUDEN HELMI.

Satu, kolme tapausta.

Henkilöt:

Kuningas.
Kuningatar.
Kuninkaan julistaja.
Tulpaani, kuninkaan puutarhuri
Bumburrifex, rosvo, velho ja ihmissyöjä.
Bumburra, hänen vaimonsa.
Tähkö, poika, | Tulpaanin lapset.
Palko, tyttö, |
Nopsajalka, köyhä poika.
Varma, hänen sisarensa.
Hunttu Honkasalmelta, mylläri poika.
Kalle Kukkanen, |
Matti Laukka, | Tähkön ja Palon
Riikka Kukkanen | leikkikumppaneja.
Kasi Aituri, tyttö. |
Musti, koira.
Ukkoja, akkoja ja lapsia kuninkaan kaupungista.

Ensimmäinen tapaus.

Vihreä niitty puutarhurin tuvan edessä. Puutarhan aita näkyy aivan


vieressä. Tähkö, Palko, Kalle, Matti, Riikka ja Kasi tanssivat. Hunttu
on liian lihava tanssimaan.

Lapset laulavat.

Nyt on kevät, hausk' on meidän hypellä


Kummuilla ja vihreöillä niityillä,
Nythän leivo riemuisena laulahtaa,
Tuulen leyhkä koivun oksaa tuudittaa,
Jopa raskas kuusikin nyt huojuu.
Tuhannet nyt heloittaapi kukkaset,
Tuhannet nyt hyppeleepi hyttyset,
Nyt on kevät, hausk' on meidän hypellä
Kummuilla ja vihreöillä niityillä,
Nythän leivo riemuisena laulahtaa,
Tuulen leyhkä koivun oksaa tuudittaa,
Jopa raskas kuusikin nyt huojuu.

Kasi (lyö Mattia). Untamo!

Matti (lyö Palkoa). Sinä se olet!

Palko (lyö Kallea). Tästä saat!

Kalle (lyö Riikkaa). Riikka sen sai!


Riikka (lyö Tähköä). Tähköpä sen saikin!

Tähkö (lyö Hunttua). Hunttu sen sai!

Kaikki lapset. Hunttu sen sai! Huttu sen sai!

Hunttu (joka on istunut ruohossa, nousee kömpelösti ylös). No,


malttakaahan; tulkaapas tänne, kyllä minä annan takaisin.

(Lapset juoksevat pakoon laulaen:)

Lipi, lipi, lipi, lipi, hauskaa kansaa,


Makkarat soittaa ja rieskat ne tanssaa.
Lipi, lipi, lipi, lipi, untamo, Hunttu,
Hunttu Honkasalmelta!

Hunttu. Malttakaahan, kyllä minä hunttuutan teitä. Vahinko, että


söin puuroa päivälliseksi; se on varmaan painunut minulle jalkoihin.

(Lapset juoksentelevat pakoon ja Hunttu lönkyttää jäljestä.


Tulpaani tulee tuvasta, ruiskukannu kädessä.)

Tulpaani. Niin, sen kyllä saatoin arvata, nyt ne kelvottomat lapsen


veitikat taas juoksentelevat ruohoa tallaamassa. Eivät ne muuta tee
kuin pahuutta päivät päästänsä. Ettekö pysy teillä, sanon minä!
Uskaltakaapahan käydä mellastelemassa puutarhassa! Koskekaahan
vain koivun oksaankaan aidan sisäpuolella, niin kyllä minä sitä
tanssitan teidän seljässänne! (Itsekseen.) Niin, olisipa todellakin
kaunista, jos he taittaisivat kruunaustulpaanin, jota nyt olen kastellut
ja hoidellut koko kuusi viikkoa kuin omaa lastani! Se ehtii juuri
paraiksi valmistua ylihuomeiseksi kuninkaan ja kuningattaren
kruunajaisiin. Mitähän kuningas sanoo, kun näkee sellaisen ihmeen.
Vähintään hän nimittää minut suuren auringonruusun ritariksi. Se
vasta on tähti, joka kelpaa, niin suuri, että riippuu vatsalla asti! Huh,
miten kuuma tänään on! Jospa täällä olisi ketään, jonka saisin
avukseni kastelemaan puutarhaa. Mutta nuo lapset, eivät ne koskaan
osaa muuta kuin meluta ja juoksennella. (Nopsajalka ja Varma
tulevat.) Tuossa tulee taas kaksi uutta lasta. Keitä te olette? Mitä
teillä on täällä tekemistä?

Nopsajalka (nostaen lakkiaan). Me olemme kaksi köyhää lasta,


joilla ei ole isää eikä äitiä. Isämme oli sotamies, ja hän on kuollut
sodassa.

Varma (niiaten). Ja äitimme on myönyt nauriita kuninkaalle. Nyt


me menemme kuninkaan kaupunkiin etsimään palvelusta.

Tulpaani. Katsoppas vain; tuollaisetko nulikat saisivat palvelusta!


Mutta tosiaan te voitte minua auttaa aivan heti paikalla. Osaitteko
kastella kukkia?

Nopsajalka. Kyllä minä osaan kantaa vettä.

Varma. Ja minä aina kastelin äitini nauriita siihen aikaan, kuin


meillä vielä oli pieni naurismaa.

Tulpaani. Hyvä, hyvä. Kastelkaa nyt kukat tuolla puutarhassa, niin


saatte ruokaa ja yösijan huomeiseen asti. Mutta varokaa tulpaania,
kuuletteko, varokaa tulpaania! Se säästetään kuninkaan omakätisiin
kruunajaisiin. Menkää nyt, minä tulen kohta perästä. Varokaa
tulpaania! (Menee tupaan.)

Nopsajalka (ottaa ruiskukannun). Tule, Varma, niin teemme, kuten


hän käski.
Varma. Se lienee hyvin kaunis tulpaani. Sitä meidän pitää varoa
kuin omaa silmäteräämme. (Menevät.)

Tähkö (kurkistaa aidan ylitse puutarhan puolelta). Tulkaa tänne,


pojat, tulkaa tänne, niin narraamme Huntun etsimään meitä!

Matti (aidan takaa). Eiköhän sinun isäsi vain suutu?

Tähkö. Mitä vielä? Tulkaa vain!

Palko (aidan takaa). Tulkaa, tytöt, tulkaa vain, älkää ollenkaan


peljätkö!

Kasi (aidan takaa). Tuossa tulee Hunttu jo!

Tähkö (aidan takaa). Tulkaa, juoskaamme pensasten taakse, että


hän ei löydä meitä!

(Kuuluu melua aidan takaa puutarhasta.)

Kalle (aidan takaa). Voi, juoksentelit kukkapenkissä!

Tähkö. Viisi minä huolin kukkapenkeistä. Tulkaa pois vain, että


Hunttu ei löydä meitä!

Hunttu (tulee puhkuen ja käy istumaan aidan viereen, pannen


toisen jalan allensa). Huh, nyt minä olen juossut itseni kuoliaaksi,
minä aivan hajoan taikka sulan mäsäksi. Tokkohan minulla vielä on
jalat tallella? Tässä on toinen. Mutta missä se toinen on? Eikö
kukaan ole nähnyt minun toista jalkaani? Mihin ihmeellekähän
olenkaan voinut hukata toisen jalkani?

Lapset (tirkistelevät, nenät aidan raoissa, ja laulavat "ukko Noakin"


nuotilla, siten, että kukin yksikseen vuorotellen laulaa: Hunttu).
Hunttu, Hunttu, Hunttu, Hunttu
Honkasalmelta!
Hän kun jauhattaapi,
Niin lapset hältä saapi
Oikein paljon, oikein paljon
Soker'pullia.

Hunttu (puoli itkussa). Malttakaas vähän, eikö kukaan ole nähnyt,


mihin minulta on pudonnut toinen jalka.

Lapset (laulavat).

Hunttu, Hunttu, Hunttu, Hunttu


Honkasalmelta!
Hän kun jauhattaapi,
Lapset hältä saapi
Oikein paljon, oikein paljon
Piparkakkuja.

Hunttu. Minä jauhatan sekä pullia että piparkakkuja sille, joka


löytää minun toisen jalkani.

Tähkö (pistää kepin aidan raosta ja lyö Hunttua sääreen). Tuossa


sinun toinen jalkasi on!

Hunttu (hypähtää seisomaan). Aijai, mitenkä se koski kipeästi,


aijaijai! Mutta mitä tämä on? Minullahan taitaa ollakin kaksi jalkaa.
(Lukee.) Yks', kaks'… Ei, luetaanpas uudestaan: yks', kaks'… (hyppii
ilosta). Jo minä löysin toisen jalkani! No, jopas löysin toisen jalkani!
(Lapset meluavat puutarhassa.)

Tähkö (kurkistaa aidan ylitse). Isä tulee! Isä tulee!


Palko (aidan takaa). Kulkaas, tytöt, älkää sanoko, että olimme
puutarhassa!

Tähkö. Niin, pojat, älkää sanoko sitä isälle. (Hän menee taas
piiloon.)

Tulpaani (tulee tuvasta). Teinpä hyvin tyhmästi, kun lähetin vieraat


lapset yksinään puutarhaan, Tokkohan ne antavat edes
karviaismarjan raakaleidenkaan olla rauhassa. (Kurkistaa aidan
raosta puutarhaan.) Mitä ihmettä, millaista täällä on? Turkkilaisiako
siellä on ollut mellastelemassa minun kukkapenkeissäni?… Voi
tulpaaniani! Voi minun tulpaaniani! Voi suurta, kaunista, harvinaisen
komeata kukkaani!

Nopsajalka (puutarhassa). Tule pois, Varma: ikävätä tämä on,


mutta emme me voi sitä auttaa.

Varma (puutarhassa). Odotahan, minä koetan nostaa pystyyn


koreata tulpaania!

Tulpaani (ulkopuolella). Enkö jo sanonut? Enkö minä sitä jo


sanonut? Nyt nuo kelvottomat kerjäläispenikat ovat juoksennelleet
kuin hottentotit minun kukkapenkeissäni, ja tuossa nyt tyttö juuri on
taittamassa minun kaunista tulpaaniani. Tulkaapas tänne, niin kyllä
minä teidät opetan!

Nopsajalka (aidan takaa). Tule pois, Varma!

(Tähkö, Palko ja muut lapset tulevat toiselta puolen, ikään kuin


metsästä.)

Tulpaani. Ahah, vai olette tekin tässä? Oletteko olleet penkkejä


sotkemassa, kelvottomat veitikat? Oletteko olleet puutarhassa,
sanokaa!

Palko. Emme, hyvä isä, mehän tulemme juuri metsästä.

Tähkö. Niin, siellä me leikkelimme itsellemme vihellyspillejä.

Kasi. Ja poimiskelimme karpaloita.

Riikka (nykäsee häntä kylkeen). Hyi, miten sinä valehtelet.

Kasi. Vaiti, sinä siinä. Oli niin hirveätä kivikkoa siellä metsässä.
Minulta hävisi sinne toinen kenkä.

Kalle. Ja minulta läntistyi kanta toisesta saappaasta.

Matti (hiljaa). Niin, juoksennellessasi sedän kukkapenkeissä.

Kalle (hiljaa). Vaiti, sinä siinä, taikka saat selkääsi.

(Hunttu tulee, koetellen jalkojansa).

Tulpaani. Mitä minä huolin teidän kengistänne ja saappaistanne!


Kunhan vain ette ole olleet puutarhassa.

Hunttu. Kyllä se oli niin, että me tosiaankin…

Kasi (sulkee kädellään häneltä suun). Jos et ole vaiti, niin minä
varastan sinulta jalkasi!

Palko. Mitä te, isä, puhutte, onko kuka tehnyt pahaa puutarhassa?

Tähkö. Onko kuka tehnyt pahaa meidän tulpaanillenne?

Tulpaani. Voi minua onnetonta puutarhuria! Minun kukkani on


sotkettu, kruunaustulpaanini on katkaistu! Mitähän kuningas tästä
sanoo?

Kasi. Minä luulin nähneeni kaksi vierasta lasta puutarhassa.

Kalle. Niin minäkin. Ja tuossahan ne juuri tulevatkin molemmat, ja


tytöllä on koko tulpaani kädessä!

(Nopsajalka ja Varma tulevat.)

Tulpaani. Te myyrät! Te kaalimadot! Te omenan varkaat! Miten te


uskalsitte tehdä sellaista tuhoa minun tarhassani? Tiedättekö, että
kuningas saattaa piiskauttaa sellaisia petoja nokkosilla, ja osaan sitä
tehdä minäkin!

Nopsajalka. Hyvä mestari, kun me menimme puutarhaan


kastelemaan kukkia, oli kaikki jo sotkettu ja turmeltu. Emme me sille
mitään voi.

Varma. Ja tässä, hyvä mestari, on tulpaani. Minä kyllä koetin


nostaa sitä pystyyn, mutta ei se jaksanut seisoa, se oli ihan poikki.

Tulpaani. Kuuleppas vain, mitä ne lörpöttelevät, nuo linnunpojat!


Eivät ole tietävinään koko asiasta.

Kasi. Miten viaton tuo tyttö on olevinaan! Ikään kuin eivät kaikki
tietäisi, että hän juuri taittoi tulpaanin.

Tähkö. Ja tuo poika, miten hän teeskentelee! Ikään kuin hän ei


olisi astua tallustellut kukkapenkeissä.

Riikka (hiljaa). Mutta kuules, Kasi, sinähän juuri talloit?

Matti (hiljaa). Mutta kuules, Tähkö, sinähän juuri juoksentelit, ja


me tulimme jäljestä.
Kasi ja Tähkö. Sinä valehtelet. Nuo ne olivat!

Kalle ja Palko. Niin, niin, nuo kerjäläispennut ovat syypäät


kaikkeen.

Hunttu. Malttakaas, nyt minä muistan. Ei ne nuo olleet, vaan…

Kasi (hiljaa). Etkö kuule, että kuningas saattaa piiskauttaa meitä


kaikkia nokkosilla?

Hunttu (hiljaa). Niin, mutta koska he ovat syyttömät…

Kasi (hiljaa). Jokaisella on oma selkä lähinnä.

Hunttu. Se oli vahinko, se, Kasi. Minä jo ihan tunnen, miten


nokkoset polttavat selkääni.

Tulpaani. Kuuletteko te, käärmeen sikiöt? Kuuletteko te,


lihakärpäset? Kaikki sanovat, että te olitte pahan teossa, ja näinhän
minä sen omillakin silmilläni.

Nopsajalka. Minä sanon teille, mestari, jotakin. Sisareni ja minä


emme koskaan valehtele.

Varma. Kun äitimme kuoli pois meiltä, kutsui hän meidät


luoksensa ja sanoi: rakkaat lapset, minä olen köyhä, minulla ei ole
hopeaa eikä kultaa antaa teille kuollessani. Mutta minä annan teille
parempaa kuin kulta ja hopea; se on kolme lausetta pyhästä
raamatusta. Tahdotteko, mestari, kuulla ne kolme lausetta?

Tulpaani. No, millaiset ne lauseet ovat?

Nopsajalka. Ensimmäinen on Viisauden kirjasta, tämä: "se suu,


joka valhettelee, tappaa sielun."
Varma. Toinen on Sirakin kirjasta ja sanoo näin: "Älä koskaan
puhu totuutta vastaan, vaan anna häpeän tulla päälles, jos sinä
viallinen olet."

Nopsajalka. Kolmas on myöskin Sirakin kirjasta, ja se on tällainen:


"Vastaa totuuden puolesta kuolemaan asti, niin Herra Jumala on
sotiva sinun edestäs."

Tulpaani. Olivatpa ne kauniit lauseet, mutta uskotteko te myöskin


ne?

Varma. Uskomme, mestari. Äitimme opetti ne meille kuollessaan.

Nopsajalka. Ja siitä te, mestari, voitte käsittää, että me emme


koskaan valehtele.

Tulpaani. Hyvät lapset, minä alan uskoa, että te olette viattomat.

Kasi. Kylläpä se on kaunis luottamus, kun tyttö tuossa seisoo,


tulpaani kädessä!

Tähkö. Ja ettekö näe, isä, että pojan jalat ovat mullassa puutarhan
penkeistä?

(Matti ja Riikka nykivät turhaan heitä vaatteista.)

Kalle. Kukapa muu sen olisi tehnyt?

Palko. Eihän ketään muita ole käynyt puutarhassa.

Tulpaani. Niin, se on totta, se. Ja kuitenkin seisotte siinä


valehtelemassa minulle vasten silmiä, te kelvottomat, petolliset
kerjäläispennut! Heti matkaanne niin kauas, kuin tietä kestää.
Kiittäkää onneanne, että minä en lähetä nimismiestä niskaanne.
Putkaan teidät pitäisi toimittaa. Turmella tuolla tavalla minun ainoa
iloni, kaunis kruunaustulpaanini! Mutta odottakaahan, jos vain
uskallatte hiipiä vielä kaupunkiin, niin minä kerron kuninkaalle, mitä
olette tehnyt.

Nopsajalka. Tule pois, Varma. Älä ole pahoillasi, pikku siskoseni.


Me kyllä olemme köyhät, mutta me olemme kuitenkin rikkaat niin
kauan, kuin meillä on äitimme perintö. (He menevät.)

Tulpaani. Minä onneton puutarhuri, minähän nyt olen ihan kuin


kuorittu tulpaani! Mitähän kuningas sanoo, kun hänet kruunataan
ilman kruunaustulpaania? (Menee.)

Matti. Hyvästi jääkää. Minusta ei ollenkaan tuntunut hyvälle, että


valehtelimme köyhäin lasten päähän.

Riikka. Ei minustakaan. Tuntuu ihan kuin neula kaivelisi


sydämmessä.

Palko. Tekikö sitte mielesi saada selkääsi nokkosilla?

Tähkö. Eikä tässä mitään vahinkoa tapahtunut. Päästihän isä ne


tyhmät lapset menemään rauhassa tiehensä.

Kalle. Niin, joutavia. Tulivat vain vähän pahaan maineesen, mutta


me pääsimme pulasta.

Kasi. Te, Matti ja Riikka, älkää luulkokaan, että teillä muka on niin
ylevät omattunnot! Ken on vaiti ja siten yhtyy kujeesen, kun toiset
selvittäytyvät pienellä hätävalheella, hän ei ole yhtään parempi
toisia.
Hunttu. Niin se juuri on. Hyi häpeätä, hyi meitä kaikkia! (Lähtee
menemään pois.)

Kasi. Kas Honkasalmen Hunttua! Mihinkä hän nyt lähtee


tallustelemaan kelvottomilla jaloillaan?

Hunttu. Niin, niin, Hunttu raukka on vähän tyhmä, mutta hän


näyttää, että hän on rehellinen mies.

(Ensimmäisen tapauksen loppu.)

Toinen tapaus.

Bumburrifexin tupa metsässä. Seinällä riippuu pyssyjä ja sapeleja.


Pöydällä palaa kynttilä. Uuninluuta seisoo uunin nurkassa. Bumburra
istuu yksinään, villoja kartaten.

Bumburra.

Nuku, lapsein, nuku vain


Kartan piikkein päällä!
Villatuppu lapsenain
Minulla on täällä.
Maailma on, tiedän sen,
Niinkuin kartta piikkinen,
Nuku, lapsein, nuku vain
Kartan piikkein päällä.

Laps, kun suureks vartut vain,


Otan kutrin vienon,
Siitä kehrään rukillain
Säikeen ani hienon.
Aika kuluu, rukki käy,
Kasva, suureks ennättäy,
Laps, kun suureks vartut vain,
Kehrään säikeen hienon.

Mutta tässä minä vain istun karttaamassa enkä ollenkaan muista,


että mieheni, suuri Bumburrifex, kohta tulee kotiin. Niin, suuri hän
on, se on varma, mutta hän saisi ennemmin olla pieni, pienempi
hiirtäkin, jos hän vain heittäisi pahat tapansa. Onpa välistä ikään
kuin hiukan ruma olla rouvana ryövärillä, ihmissyöjällä ja velholla.
Mutta mikäpä tässä auttaa? Jokin toimi täytyy jokaisella tässä
maailmassa olla. Minun ukkoseni on tavallaan kyllä rehellinen mies.
Kun hän ryöstää jotakin, niin hän aina ottaa toisilta rosvoilta. Hän
loitsii vain huviksensa; jotainhan hänelläkin pitää olla huvitusta
joutohetkinään. Ihmisiä hän ei syö koskaan muulloin kuin hyvin
nälissään, milloin minulla ei ole kylliksi ruokaa kaapissa. Kuten nyt
esimerkiksi. Tosiaankaan nyt ei olisi hyvä pikku lasten hiipiä tänne,
kun minulla on vain yksi ainoa kukko padassa. Varsinkaan
sotamiesten lasten. No, siitä minun nyt ei tarvitse olla huolissani.
Metsässä on koiran ilma; sataa, kuin olisi taivas auki. Eiköhän Musti
parkakin mielellään nyt ryömi kojuunsa siellä ulkona.

(Musti haukkuu ulkona hau vau vau!)

Bumburra. Vai niin, joko mieheni nyt tulee kotiin. Ja minulla kun
on vain kukko iltaseksi! Onhan minulla porsaskin, mutta se on
jouluporsas, se. (Hän avaa oven, Nopsajalka ja Varma astuvat
sisään.) Mitä ihmettä? Kaksi lasta!

Nopsajalka. Hyvä emäntä, olkaa niin hyvä, antakaa yösijaa


kahdelle köyhälle lapselle! Me olemme läpimärkinä sateesta.
Bumburra. Menkää heti tiehenne! Onko meillä tilaa kaikille mieron
kiertäjille, jotka metsää samoelevat?

Varma. Meillä ei ole isää eikä äitiä. Me eksyimme pimeässä, ja


metsä on täynnä susia.

Nopsajalka. Me näimme etäältä tulta ja ilostuimme, kun löysimme


metsästä tuvan.

Bumburra. Ilostuitteko? Kyllä varmaan vähemmän iloitsisitte, jos


tietäisitte, mihin nyt olette tulleet. Parempi teidän olisi nukkua suden
pesässä. Mutta pitänee minun katsoa, mitä voin tehdä teille. Jos
teidät joku syö suuhunsa, niin älkää syyttäkö minua!

Nopsajalka. Kuka syödään?

Bumburra. Te taikka minä; mutta tuskinpa vain minä kelvannen.


Tietäkää, että minun mieheni, suuri Bumburrifex, on ihmissyöjä.

Varma. Huh, Nopsa, lähdetään pois täältä. Minna pelottaa niin


hirveästi.

Nopsajalka. Emäntä vain meitä vähän pelottelee.

Bumburra. Ette te saa jäädä tänne, ettekä te myöskään voi mennä


metsään susien syötäväksi. No, jääkää sitte tänne. Ehkäpä joku
keino keksitään, kun vain ette ole sotamiehen lapsia. Minun ukkoni
vihaa sotamiehiä, he kun eivät anna hänen rosvota rauhassa, ja
sentähden hän välistä syöksentelee heidän lapsiansa.

Varma. Kuuletko, Nopsa, hän on myöskin rosvo!

You might also like