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.
After the difficult dive into digital sensors, analog sensors can seem like a breeze! Analog signals are a continuous signal, like the photo below.
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.
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!
Here is a sample code to get ya started.
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 below 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!
Visualizing Data: Excel!
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.
3. Click “Start Data” to start data collection! You’ll see three new sheets open up: “Data In”, “Data Out”, and “Settings”.
Live data is printed in the Data In sheet. 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!).
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.
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.
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:
*Full disclosure: Although this tutorial is not affiliated, I do work w/ the Microsoft Hacking STEM team which developed this add-in.
**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.
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!
Need some more ideas? Here’s how to make a wearable state change switch, a solar-powered remote temperature sensor, and an Internet-connected industrial scale!
Like this tutorial and want to see more? Support our projects on Patreon! 😀