SlideShare a Scribd company logo
Datalogger Programming Using
Arduino - Part 1
Jeffery S. Horsburgh
Hydroinformatics
Fall 2018
Objectives
• Learn basic data collection concepts for hydrologic
data
• Examine more closely observation dimensionality,
including the scale triplet of support, spacing, and
extent
• Learn the basic datalogger program structure for
logging data
Arduino Programs – “Sketches”
• Sketch = Program
• Unit of code uploaded to and run on an Arduino
board
• 5 parts:
1. A descriptive header comment block
2. Definition of global variables
3. Setup() function
4. Loop() function
5. User-defined functions
• Arduino Language Reference:
https://www.arduino.cc/en/Reference/HomePage
Arduino Language
• Roughly based on C
• All statements must end with a ;
• Variables are storage compartments for numbers
• Variables must be defined before use
• // Comments are preceded by two forward slashes
What’s the best way to learn the language?
Study the examples and other people’s code!!!
Exercise – The “Blink” Sketch
• Plug your Arduino into your computer via the USB
cable
• Open the Arduino IDE software
• From the Tools drop down menu select:
Board  Arduino/Genuino UNO
Port  <whichever port is labeled Arduino/Genuino Uno>
• From the File drop down menu select:
Examples  01. Basics  Blink
The header
block
describes
the sketch
Import
libraries or
declare Global
variables here
The setup()
function
The loop()
function
User-defined
functions here
Example Sketch
Exercise – The “Blink” Sketch
• Plug your Arduino into your computer via the USB
cable
• Open the Arduino IDE software
• From the Tools drop down menu select:
Board  Arduino/Genuino UNO
Port  <whichever port is labeled Arduino/Genuino Uno>
• From the File drop down menu select:
Examples  01. Basics  Blink
• On the toolbar, click the “verify” button
• On the toolbar, click the “upload” button
Closer Look – the setup() function
• Run once when you power the Arduino or when
you send a new program
• Put everything in the setup() function that you
want to happen before the main program loop
starts
Closer look – the loop() function
• Runs continuously as long as the Arduino is
powered
• Yep – its an endless loop!
• Put everything in the loop() function that you want
to execute continuously
• Measurements
• Control logic
• Data output
• Etc.
How do we turn an Arduino into a
datalogger?
•Some things we have to figure out:
o Debugging
o Timing
o Interfacing with sensors and making
measurements
o Recording data to a file
Debugging Using the Output Pane
• When you
compile your
code, errors
will show up
here
Exercise – “Blink_Example2”
• Send the program, then open the serial monitor by
clicking the button on the toolbar (top right)
Start a serial
port and print a
line of text to it.
Print a line of
text with LED
status
Debugging with
Serial Output
• Useful when you want to
see what’s going on as
the program executes
• Print values and
messages to a serial
monitor
• The Arduino IDE has it’s
own serial monitor
• Super helpful for
debugging
Make sure the baud rate
matches your Serial.begin()
statement in your sketch
Timing
• The loop() function runs indefinitely as fast as it can
• The loop itself takes a couple of clock cycles, but
total time is dependent on what is in the loop
• Arduino UNO has no realtime clock (bummer!)
• But, it has some useful timing functions:
• millis() – number of milliseconds since the Arduino
board began running the current program
• micros() – same as millis, but for microseconds
• delay() – pauses the program for an amount of time (in
milliseconds)
• delayMicroseconds() – same as delay but for
microseconds
NOTE: millis() and micros() will overflow and go back to zero after a certain
period of time
Exercise – “Timing_Example1”
Timing
• millis() and delay() are great, but not exact
• Plus, delay() pauses the program and you can’t do
anything else at the same time
• What if I want the Arduino to do something (like
make a measurement) on a more precise, set time
interval?
• What if I want to do multiple things at the same
time?
Measurement Concepts
• Remember the scale triplet – support, spacing, and
extent
• We want to control these with our program
The Scale Triplet of Measurements
length or time
quantity
(a) Extent
length or time
quantity
(b) Spacing
length or time
quantity
(c) Support
Measurement Concepts - Spacing
How often should we record
values to capture this signal?
“When one can verify that additional
measurements will merely ‘connect
the dots’ between the existing
observations, the hydrochemical
record can be considered continuous
for all practical purposes.”
Kirchner, J.W., Feng, X., Neal, C., Robson, A.J. (2004). The fine structure of water-
quality dynamics: the (high-frequency) wave of the future, Hydrological Processes,
18(7), 1353-1359, http://dx.doi.org/10.1002/hyp.5537.
Remember this Slide?
Sampling Frequency
• Half hourly data
subsampled
-Hourly
-Daily
-Weekly
-Monthly
Half hourly
Hourly
Daily
Weekly
Monthly
Measurement Concepts - Spacing
Looks good…
But, what do we record?
One instantaneous value
every 5 seconds?
What if the sensor is “noisy?”
What if the signal is “noisy?”
Time Support and Spacing
• Generally handled using a scan interval and a
recording interval
• Scan Interval = the time between sensor measurements
• Recording Interval = the time between recorded
observations
What is the difference?
Measurement Concepts
Scan Interval vs. Recording Interval
• Recording Interval = spacing
• Scan Interval = what we do within a recording
interval that determines what values we record
• How many times we sample the sensor(s)
• What statistic (if any) we calculate
Measurement Concepts
Scan Interval vs. Recording Interval
Measurement Concepts
Scan Interval vs. Recording Interval
• There are several reasons to scan sensors more
frequently than you record data:
oReduce error in sensor observations by aggregation
(e.g., calculate an average value)
oReduce noise in the observed phenomena by
aggregation – again, averaging
oAdaptive sampling – record values at a slow rate until
something interesting happens (e.g., a storm event),
then increase recording frequency
• Tradeoff: Scanning sensors requires power
Measurement Concepts
Time Support
• The time window / footprint
over which an observation is
made
• Not always equal to the recording interval
• Depends on scanning and recording strategy
oInstantaneous values: time support = 0
oAverage (or other aggregate statistic) values: time
support = whatever time window over which you
calculate the statistic
• Regular averaging
• Burst sampling
Exercise – “Timing_Example2”
Pseduo-code of loop:
1. Get the current value of the micros() function
2. Check to see if a scan interval has passed
3. If a scan interval has passed
a. Perform scan instructions (e.g.,
measurements, calculations, etc.)
b. Check to see if a recording interval has passed
c. If a recording interval has passed
i. Perform necessary calculations
ii. Record an output record
Some Notes about Timing
• On the Arduino UNO, the micros() function has a
resolution of 4 microseconds
• The “Timing_Example2” sketch will accumulate
error in timing
• More sophisticated examples might use interrupts
and the UNO’s internal timers, but for our work,
this example will suffice
How do we turn an Arduino into a
datalogger?
•Some things we have to figure out:
 Debugging
 Timing
o Interfacing with sensors and making
measurements
o Recording data to a file
Summary
• Every hydrologic observation, regardless of how it was
created, has support, spacing, and extent
• The scale triplet determines how we interpret and use
data
• Arduino gives us an inexpensive prototyping platform
for environmental sensors and datalogging
• Arduino’s IDE and programming language provide a
coding environment for measurement and control
• Arduino sketches rely on setup() and loop() functions
• Controlling time support and spacing of observations
relies on Arduino’s timing functions (or an external
realtime clock)
• Timing/sampling strategies can be used to
capture/overcome noisy signals and sensors

More Related Content

PDF
What’s eating python performance
PPT
AN INTRODUCTION TO OPERATING SYSTEMS : CONCEPTS AND PRACTICE - PHI Learning
PDF
02 performance
PPTX
Keep Calm and Distributed Tracing
PDF
03 performance
PDF
Measuring Performance / iOS Apps
PPTX
c programming 1-1.pptx
PPTX
Ruby3x3: How are we going to measure 3x
What’s eating python performance
AN INTRODUCTION TO OPERATING SYSTEMS : CONCEPTS AND PRACTICE - PHI Learning
02 performance
Keep Calm and Distributed Tracing
03 performance
Measuring Performance / iOS Apps
c programming 1-1.pptx
Ruby3x3: How are we going to measure 3x

Similar to Class5_DataloggerProgrammingArduino.pptx (20)

PPTX
I/O systems chapter 12 OS
PDF
bec306c Computer Architecture and Organization
PDF
04 performance
PPT
01 introduction to cpp
PPTX
QuickIntroduction to Arduino and Sensors
PPTX
algorithms and data structure Time complexity
PPT
13223971.ppt
PPTX
Machine Learning and Apache Edgent with STM32F401 to Firebase
PDF
PILOT Session for Embedded Systems
PDF
2018 FRecure CISSP Mentor Program- Session 4
PDF
Android talks #08 android profiling
PDF
TechGIG_Memory leaks in_java_webnair_26th_july_2012
PDF
Compute fast of computer
PPTX
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
PPTX
Unit 1, ADA.pptx
PDF
Arduino Workshop @ MSA University
PPT
01CHAP_1.PPT
PPT
L-2 (Computer Performance).ppt
PPT
operating system basics including mac os
PDF
Computer architecture short note (version 8)
I/O systems chapter 12 OS
bec306c Computer Architecture and Organization
04 performance
01 introduction to cpp
QuickIntroduction to Arduino and Sensors
algorithms and data structure Time complexity
13223971.ppt
Machine Learning and Apache Edgent with STM32F401 to Firebase
PILOT Session for Embedded Systems
2018 FRecure CISSP Mentor Program- Session 4
Android talks #08 android profiling
TechGIG_Memory leaks in_java_webnair_26th_july_2012
Compute fast of computer
Using Metrics for Fun, Developing with the KV Store + Javascript & News from ...
Unit 1, ADA.pptx
Arduino Workshop @ MSA University
01CHAP_1.PPT
L-2 (Computer Performance).ppt
operating system basics including mac os
Computer architecture short note (version 8)
Ad

More from HebaEng (20)

PDF
lectNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN2.pdf
PDF
lectااتتتتاارررررررررررررررررررررررررررر1.pdf
PDF
M2M_250327_22434hjjik7_250411_183538.pdf
PDF
M3M_250327ggggt_224420_250411_183353.pdf
PDF
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
PPTX
Estimate the value of the following limits.pptx
PDF
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
PPTX
LECtttttttttttttttttttttttttttttt2 M.pptx
PDF
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
PDF
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
PPTX
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
PDF
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
PDF
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
PPT
lecture1ddddgggggggggggghhhhhhh (11).ppt
PDF
math6.pdf
PDF
math1مرحلة اولى -compressed.pdf
PDF
digital10.pdf
PDF
PIC Serial Communication_P2 (2).pdf
PPTX
Instruction 3.pptx
PPTX
IO and MAX 2.pptx
lectNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN2.pdf
lectااتتتتاارررررررررررررررررررررررررررر1.pdf
M2M_250327_22434hjjik7_250411_183538.pdf
M3M_250327ggggt_224420_250411_183353.pdf
MATHLECT1LECTUREFFFFFFFFFFFFFFFFFFHJ.pdf
Estimate the value of the following limits.pptx
lecrfigfdtj x6 I f I ncccfyuggggrst3.pdf
LECtttttttttttttttttttttttttttttt2 M.pptx
lect4ggghjjjg t I c jifr7hvftu b gvvbb.pdf
lect5.gggghhhhhhhhhhhhyyhhhygfe6 in b cfpdf
sensorshhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pptx
Homework lehhhhghjjjjhgd thvfgycture 1.pdf
PIC1jjkkkkkkkjhgfvjitr c its GJ tagging hugg
lecture1ddddgggggggggggghhhhhhh (11).ppt
math6.pdf
math1مرحلة اولى -compressed.pdf
digital10.pdf
PIC Serial Communication_P2 (2).pdf
Instruction 3.pptx
IO and MAX 2.pptx
Ad

Recently uploaded (20)

PPTX
mahatma gandhi bus terminal in india Case Study.pptx
PPTX
Special finishes, classification and types, explanation
PPT
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
PPTX
HPE Aruba-master-icon-library_052722.pptx
PPTX
Entrepreneur intro, origin, process, method
PPTX
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PPTX
Tenders & Contracts Works _ Services Afzal.pptx
PDF
Quality Control Management for RMG, Level- 4, Certificate
PPTX
YV PROFILE PROJECTS PROFILE PRES. DESIGN
PPT
Machine printing techniques and plangi dyeing
PPTX
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
PPTX
Implications Existing phase plan and its feasibility.pptx
PPTX
rapid fire quiz in your house is your india.pptx
PDF
Urban Design Final Project-Site Analysis
PDF
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
PPTX
building Planning Overview for step wise design.pptx
DOCX
actividad 20% informatica microsoft project
PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PPT
UNIT I- Yarn, types, explanation, process
mahatma gandhi bus terminal in india Case Study.pptx
Special finishes, classification and types, explanation
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
HPE Aruba-master-icon-library_052722.pptx
Entrepreneur intro, origin, process, method
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
Tenders & Contracts Works _ Services Afzal.pptx
Quality Control Management for RMG, Level- 4, Certificate
YV PROFILE PROJECTS PROFILE PRES. DESIGN
Machine printing techniques and plangi dyeing
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
Implications Existing phase plan and its feasibility.pptx
rapid fire quiz in your house is your india.pptx
Urban Design Final Project-Site Analysis
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
building Planning Overview for step wise design.pptx
actividad 20% informatica microsoft project
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
UNIT I- Yarn, types, explanation, process

Class5_DataloggerProgrammingArduino.pptx

  • 1. Datalogger Programming Using Arduino - Part 1 Jeffery S. Horsburgh Hydroinformatics Fall 2018
  • 2. Objectives • Learn basic data collection concepts for hydrologic data • Examine more closely observation dimensionality, including the scale triplet of support, spacing, and extent • Learn the basic datalogger program structure for logging data
  • 3. Arduino Programs – “Sketches” • Sketch = Program • Unit of code uploaded to and run on an Arduino board • 5 parts: 1. A descriptive header comment block 2. Definition of global variables 3. Setup() function 4. Loop() function 5. User-defined functions • Arduino Language Reference: https://www.arduino.cc/en/Reference/HomePage
  • 4. Arduino Language • Roughly based on C • All statements must end with a ; • Variables are storage compartments for numbers • Variables must be defined before use • // Comments are preceded by two forward slashes What’s the best way to learn the language? Study the examples and other people’s code!!!
  • 5. Exercise – The “Blink” Sketch • Plug your Arduino into your computer via the USB cable • Open the Arduino IDE software • From the Tools drop down menu select: Board  Arduino/Genuino UNO Port  <whichever port is labeled Arduino/Genuino Uno> • From the File drop down menu select: Examples  01. Basics  Blink
  • 6. The header block describes the sketch Import libraries or declare Global variables here The setup() function The loop() function User-defined functions here Example Sketch
  • 7. Exercise – The “Blink” Sketch • Plug your Arduino into your computer via the USB cable • Open the Arduino IDE software • From the Tools drop down menu select: Board  Arduino/Genuino UNO Port  <whichever port is labeled Arduino/Genuino Uno> • From the File drop down menu select: Examples  01. Basics  Blink • On the toolbar, click the “verify” button • On the toolbar, click the “upload” button
  • 8. Closer Look – the setup() function • Run once when you power the Arduino or when you send a new program • Put everything in the setup() function that you want to happen before the main program loop starts
  • 9. Closer look – the loop() function • Runs continuously as long as the Arduino is powered • Yep – its an endless loop! • Put everything in the loop() function that you want to execute continuously • Measurements • Control logic • Data output • Etc.
  • 10. How do we turn an Arduino into a datalogger? •Some things we have to figure out: o Debugging o Timing o Interfacing with sensors and making measurements o Recording data to a file
  • 11. Debugging Using the Output Pane • When you compile your code, errors will show up here
  • 12. Exercise – “Blink_Example2” • Send the program, then open the serial monitor by clicking the button on the toolbar (top right) Start a serial port and print a line of text to it. Print a line of text with LED status
  • 13. Debugging with Serial Output • Useful when you want to see what’s going on as the program executes • Print values and messages to a serial monitor • The Arduino IDE has it’s own serial monitor • Super helpful for debugging Make sure the baud rate matches your Serial.begin() statement in your sketch
  • 14. Timing • The loop() function runs indefinitely as fast as it can • The loop itself takes a couple of clock cycles, but total time is dependent on what is in the loop • Arduino UNO has no realtime clock (bummer!) • But, it has some useful timing functions: • millis() – number of milliseconds since the Arduino board began running the current program • micros() – same as millis, but for microseconds • delay() – pauses the program for an amount of time (in milliseconds) • delayMicroseconds() – same as delay but for microseconds NOTE: millis() and micros() will overflow and go back to zero after a certain period of time
  • 16. Timing • millis() and delay() are great, but not exact • Plus, delay() pauses the program and you can’t do anything else at the same time • What if I want the Arduino to do something (like make a measurement) on a more precise, set time interval? • What if I want to do multiple things at the same time?
  • 17. Measurement Concepts • Remember the scale triplet – support, spacing, and extent • We want to control these with our program The Scale Triplet of Measurements length or time quantity (a) Extent length or time quantity (b) Spacing length or time quantity (c) Support
  • 18. Measurement Concepts - Spacing How often should we record values to capture this signal?
  • 19. “When one can verify that additional measurements will merely ‘connect the dots’ between the existing observations, the hydrochemical record can be considered continuous for all practical purposes.” Kirchner, J.W., Feng, X., Neal, C., Robson, A.J. (2004). The fine structure of water- quality dynamics: the (high-frequency) wave of the future, Hydrological Processes, 18(7), 1353-1359, http://dx.doi.org/10.1002/hyp.5537.
  • 20. Remember this Slide? Sampling Frequency • Half hourly data subsampled -Hourly -Daily -Weekly -Monthly Half hourly Hourly Daily Weekly Monthly
  • 21. Measurement Concepts - Spacing Looks good… But, what do we record? One instantaneous value every 5 seconds?
  • 22. What if the sensor is “noisy?”
  • 23. What if the signal is “noisy?”
  • 24. Time Support and Spacing • Generally handled using a scan interval and a recording interval • Scan Interval = the time between sensor measurements • Recording Interval = the time between recorded observations What is the difference?
  • 25. Measurement Concepts Scan Interval vs. Recording Interval • Recording Interval = spacing • Scan Interval = what we do within a recording interval that determines what values we record • How many times we sample the sensor(s) • What statistic (if any) we calculate
  • 26. Measurement Concepts Scan Interval vs. Recording Interval
  • 27. Measurement Concepts Scan Interval vs. Recording Interval • There are several reasons to scan sensors more frequently than you record data: oReduce error in sensor observations by aggregation (e.g., calculate an average value) oReduce noise in the observed phenomena by aggregation – again, averaging oAdaptive sampling – record values at a slow rate until something interesting happens (e.g., a storm event), then increase recording frequency • Tradeoff: Scanning sensors requires power
  • 28. Measurement Concepts Time Support • The time window / footprint over which an observation is made • Not always equal to the recording interval • Depends on scanning and recording strategy oInstantaneous values: time support = 0 oAverage (or other aggregate statistic) values: time support = whatever time window over which you calculate the statistic • Regular averaging • Burst sampling
  • 29. Exercise – “Timing_Example2” Pseduo-code of loop: 1. Get the current value of the micros() function 2. Check to see if a scan interval has passed 3. If a scan interval has passed a. Perform scan instructions (e.g., measurements, calculations, etc.) b. Check to see if a recording interval has passed c. If a recording interval has passed i. Perform necessary calculations ii. Record an output record
  • 30. Some Notes about Timing • On the Arduino UNO, the micros() function has a resolution of 4 microseconds • The “Timing_Example2” sketch will accumulate error in timing • More sophisticated examples might use interrupts and the UNO’s internal timers, but for our work, this example will suffice
  • 31. How do we turn an Arduino into a datalogger? •Some things we have to figure out:  Debugging  Timing o Interfacing with sensors and making measurements o Recording data to a file
  • 32. Summary • Every hydrologic observation, regardless of how it was created, has support, spacing, and extent • The scale triplet determines how we interpret and use data • Arduino gives us an inexpensive prototyping platform for environmental sensors and datalogging • Arduino’s IDE and programming language provide a coding environment for measurement and control • Arduino sketches rely on setup() and loop() functions • Controlling time support and spacing of observations relies on Arduino’s timing functions (or an external realtime clock) • Timing/sampling strategies can be used to capture/overcome noisy signals and sensors