Science allows us to ask our most pressing questions and explore all sorts of curiosities. With some thought, hard work, and patience, we can use our explorations to build a better understanding and appreciation of the complex and beautiful world around us.
This tutorial will teach you how to use an Arduino (uno) microcontroller, how to use different types of sensors, and how to gather and visualize data. Along the way, we'll build three projects: a tilt switch, a temperature and humidity sensor, and a light sensor!
Difficulty Level: Beginner
Read Time: 20 min
Build Time: Depends on your project! (Projects in this tutorial take about 15 - 20 min)
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Pssst, What's the Difference Between Citizen Science and "official Science"?
The biggest difference is that citizen science is, as I love to say, "hand wavy", which means that there are lots of errors and uncertainties and no rigorous process to identify them. Because of this, conclusions reached through citizen science are much less accurate than science-science and should not be relied upon to make serious/life-altering/life-threatening claims or decisions.*
That being said, citizen science is a great way to build a fundamental understanding of all sorts of fascinating scientific phenomenon and is good enough for most day-to-day applications.
*If you are doing citizen science and you discover something potentially dangerous (e.g. high lead levels in water), inform your educator (if applicable) and contact the relevant authorities and professionals for assistance.
Step 2: What Is Arduino??
Arduino is a microcontroller board and Integrated Development Environment ("IDE"), which is a fancy way of saying "coding program". For beginners, I highly recommend Arduino Uno boards because they are super robust, reliable, and powerful.
Arduino boards are a good choice for citizen science projects because they have lots of input pins to read in both Analog and Digital sensors (we'll get more into this later).
Of course, you can use other microcontrollers for citizen science depending on your (or your students') needs, abilities, and comfort level. Here is an overview of microcontrollers to help ya decide what is best for you!
To flash, or program, an Arduino board, plug it in via USB, then:
1. Select the type of Arduino you're using under Tools -> Boards. (Photo 2)
2. Select the port (aka where it's connected to your computer). (Photo 3)
3. Click the Upload button and check that it finishes uploading. (Photo 4)
Step 3: Tools & Materials
If you're just getting started, getting a kit is a quick & easy way to get a bunch of parts at once. The kit I'm using in this tutorial is the Elegoo Arduino Starter Kit.*
- Arduino Uno
- USB A to B cable (aka printer cable)
- Jumper Wires
- 3 male-to-male
- 3 male-to-female
- Optional but recommended to make your life easier and more fun :)
For the projects covered in this tutorial, you'll need these parts from the Elegoo Arduino Starter Kit:
- Tilt Switch
- DTH11 Temperature and Humidity Sensor
- 100 Ohm Resistor
*Full disclosure: I purchase these same kits for workshops, but the kit used in this tutorial was donated by the lovely folks at Elegoo.
Step 4: What Kinds of Sensors Can We Use?
When designing a science experiment, we typically start with a question: How much CO2 do plants absorb in a day? What is the impact force of a jump? What is consciousness??
Based on our question, we can then identify what we want to measure and do some research to figure out what sensor we can use to gather data (although it miiight be a bit tricky to gather data for that last question!).
When working with electronics, there are two main types of sensor data signals: Digital and Analog. In the photo, the first two rows of parts are all digital sensors, while the top two rows are analog.
There are many different types of digital sensors, and some are more challenging to work with than others. When doing research for your citizen science project, always check how the sensor puts out data (srsly tho) and make sure you can find an (Arduino) library for that specific sensor.
In the three projects covered in this tutorial we'll use two types of digital sensors and one analog sensor. Let's get a-learnin!
Step 5: Digital Sensors! Part 1: the Easy Ones!
Most sensors you'll use output a Digital Signal, which is a signal that is either on or off.* We use binary numbers to represent these two states: an On signal is given by a 1, or True, while Off is 0, or False. If we were to draw a picture of what a binary signal looks like, it would be a square wave like the one in Photo 2.
There are some digital sensors, like switches, that are super easy and straightforward to measure because either the button is pushed and we get a signal (1), or it is not pushed and we have no signal (0). The sensors pictured in the bottom row of the first photo are all simple on/off types. The sensors on the top row are a bit more complex and are covered after our first project.
The first two projects in this tutorial will teach you how to use both types! Onward to build our first project!!
*On means an electrical signal in the form of electric current and voltage. Off means no electrical signal!
Step 6: Project 1: Tilt Switch Digital Sensor
For this first project, let's use a tilt switch, that black cylindrical sensor with two legs!
Step 1: Insert one leg of the tilt switch into Arduino Digital Pin 13, and the other leg into the GND pin right next to pin 13. Orientation doesn't matter.
Step 2: Write a sketch that reads in and prints out the status of Digital Pin 13.
If you're just getting started in coding, read through the comments to better understand how the sketch works and try changing some things to see what happens! It's OK to break things, that's a great way to learn! You can always re-download the file and start over :)
Step 3: To see your live data, click on the Serial Monitor button (photo 2).
.. aaaand that's it! You can now use the tilt switch to measure orientation! Set it up to call out your kitty when it knocks something over, or use it to keep track of how tree branches move during storms! .. & there are probably other applications in between those two extremes.
Step 7: Digital Sensors! Part 2: PWM and Serial Communication
There are many ways to create more complex digital signals! One method is called Pulse Width Modulation ("PWM"), which is a fancy way of saying a signal that is on for a certain amount of time and off for a certain amount of time. Servo motors (which can be used to measure position) and ultrasonic sensors are examples of sensors that use PWM signals.
There are also sensors that use serial communication to send data one bit, or binary digit, at a time. These sensors require some familiarity with reading datasheets and can be pretty tricky if you're just getting started. Fortunately, common serial sensors will have code libraries* and sample programs to pull from so you can still cobble together something functional. More details on serial communication protocols is beyond the scope of this tutorial, but here is a great resource on serial communication from SparkFun to learn more!
For this sample project, let's use the temperature and humidity sensor (DHT11)! This is a lil' blue square with holes and 3 pins.
First we'll need a couple of special libraries for the DHT11 sensor: the DHT11 library and the Adafruit Unified Sensor library.
To install these libraries (and most other Arduino libraries):
Step 1: Open up the Arduino library manager by going to Sketch -> Libraries -> manage Library (Photo 2)
Step 2: Install and activate the DHT library by searching for "DHT" and then clicking Install for the "DHT Arduino Library" (Photo 3)
Step 3: Install and activate the Adafruit Unified Sensor library by searching for "Adafruit Unified Sensor" and clicking install.
Step 4: Insert the DHT library into your open sketch by going to Sketch -> Libraries, and clicking on the "DHT Arduino Library. (Photo 4) This will insert a couple of new lines at the top of your sketch, which means our library is now active and ready to use! (Photo 5)
*Just like your fav local library, code libraries are a wealth of knowledge and other folks' hard work that we can use to make our lives easier, yay!
Step 8: Project 2: Temp and Humidity Digital Serial Sensor
Grab 3 male-to-female jumper wires from the Elegoo Arduino Starter Kit and we're ready to go!
Step 1: With the header pins facing you, connect the rightmost header pin on the DHT11 to an Arduino ground ("GND") pin.
Step 2: Connect the middle header pin to Arduino 5V output pin.
Step 3: Connect the leftmost header pin to Arduino Digital Pin 2.
Step 4: Finally, read the DHT library and try your hand at writing a sketch! Oooor you can use mine or the DHT test example sketch within Arduino -> Examples!
When you've got it up and running, go forth and measure the temperature and humidity of all the things! .. Like an animal's breath, a greenhouse, or your favorite climbing spot at different times of the year to find the *perfect* sending temp.
Step 9: Analog Sensors!
After the difficult dive into digital sensors, analog sensors can seem like a breeze! Analog signals are a continuous signal, as shown in the 2nd photo. Most of the physical world exists in analog (e.g. temperature, age, pressure, etc.), but since computers are digital*, most sensors will output a digital signal. Some microcontrollers, like Arduino boards, can also read in analog signals**.
For most analog sensors, we give the sensor power, then read in the analog signal using the Analog Input pins. For this test, we'll use an even simpler setup to measure the voltage across an LED when we shine a light on it.
*Computers use digital signals to store and transmit info. This is because digital signals are easier to detect and are more reliable, since all we've got to worry about is getting a signal or not versus having to worry about the quality/accuracy of the signal.
** To read in an analog signal on a digital device, we must use an Analog-to-Digital, or ADC, converter, which approximates the analog signal by comparing the input to a known voltage on the device, then counting how long it takes to reach the input voltage. For more info, this is a helpful site.
Step 10: Project 3: LED As a Light Sensor!
Grab an LED (any color except white), a 100 Ohm resistor, and 2 jumper cables. Oh, and a breadboard!
Step 1: Insert the LED into the breadboard with the longer leg on the right side.
Step 2: Connect a jumper wire from Arduino Analog Pin A0 and the longer LED leg.
Step 3: Connect the resistor between the shorter LED leg and the breadboard negative power rail (next to the blue line).
Step 4: Connect the Arduino GND pin to the negative power rail on the breadboard.
Step 5: Write a sketch that reads in Analog Pin A0 and prints to the Serial Monitor!
Step 11: Visualizing Data: Arduino IDE!
The Arduino IDE comes with built-in tools to visualize data. We've already explored the basics of the Serial Monitor which allows us to print sensor values. If you want to save and analyze your data, copy the output directly from the Serial Monitor and paste into a text editor, spreadsheet, or other data analysis tool.
The second tool we can use to see our data in the Arduino program is the Serial Plotter, a visual version (aka graph) of the Serial Monitor. To use the Serial Plotter, go to Tools --> Serial Plotter. The graph in Photo 2 is the output of the LED as a light sensor from Project 3!*
The plot will auto-scale and as long as you're using Serial.println() for your sensors, it will also print all of your sensors in different colors. Hooray! That's it!
*If you look at the end, there is a super interesting wave pattern which is likely due to the Alternating Current ("AC") in our overhead lights!
Step 12: Visualizing Data: Excel! Part 1
For more serious data analysis, there's a super cool (and free!) add-in for Excel called Data Streamer*, which you can download here.
This add-in reads from the serial port, so we can use the exact same coding technique of printing data to serial to get data directly into Excel.. heck yes!!
How to use the Data Streamer Add-In:
1. Once you've installed it (or if you have O365), click on the Data Streamer tab (far right) in Excel.
2. Plug in your Arduino and click "Connect Device", then select the Arduino from the drop-down menu.(Photo 1)
3. Click "Start Data" to start data collection! (Photo 2)You'll see three new sheets open up: "Data In", "Data Out", and "Settings".
Live data is printed in the Data In sheet. (Photo 3) Each row corresponds to a sensor reading, with the newest value printed in the last row.
By default we only get 15 rows of data, but you can change this by going to "Settings". We can gather up to 500 rows (limit is due to Excel bandwidth -- there's a lot happening in the background!).
*Full disclosure: Although this tutorial is not affiliated, I do work w/ the Microsoft Hacking STEM team which developed this add-in.
Step 13: Visualizing Data: Excel! Part 2
4. Add a Plot of your data! Do some data analysis!
Scatter plots show you how the sensor readings change over time, which is the same thing we saw in the Arduino Serial Plotter.
To add a Scatter Plot:
Go to Insert -> Charts -> Scatter. When the plot pops up, right click on it and choose "Select Data", then Add. We want our data displayed on the y-axis, with "time"* on the x-axis. To do this, click the arrow next to the y-axis, go to the Data In sheet, and select all of the incoming sensor data (Photo 2).
We can also do calculations and comparisons in Excel! To write a formula, click on an empty cell and type an equals sign ("="), then the calculation you want to do. There are lots of built-in commands like average, maximum, and minimum.
To use a command, type the equals sign, the command name, and an open parenthesis, then select the data you're analyzing and close the parentheses (Photo 3)
5. To send more than one column of data (AKA more than one sensor), print the values on the same line separated by a comma, with a final blank new line, like this:
Serial.print(sensorReading1); Serial.print(","); Serial.print(sensorReading2); Serial.print(","); Serial.println();
*If you want the actual time to be on the x-axis, select the timestamp in Column A on the Data In sheet for the x-axis values in your Scatter Plot. Either way, we'll see our data as it changes over time.
Step 14: Go Forth and Measure All the Things!!
Alright folks, that's all! Time to go outward and upward! Use this as a foundation to start exploring sensors, Arduino coding, and data analysis to tackle your questions, curiosities, and fav mysteries in this big, beautiful world.
Remember: there are lots of folks out there to help you along the way, so please leave a comment if you have a question!
Like this tutorial and want to see more? Support our projects on Patreon! :D
Participated in the
Arduino Contest 2019