Ingredients
Special items
When explorers sailed the seven seas finding new (to them) places, plants, and peoples, they often kept careful logs—a diary noting the day, the time, and what they observed. Arduinos may not be seaworthy, but they are excellent at logging their observations. With this project, we’ll get Arduino logging and we’ll put that log online.
Keeping track of observations is super useful. With lots of observations over time, you can see the peaks and valleys in your numbers and discover things you didn’t know.
We’ll be tracking the temperature inside your house (or wherever you set up your Arduino). If you were to do this by hand, you might set an alarm clock to check a thermometer every hour and then write it down. That’s exactly what we’ll have your Arduino do—with the added bonus that it’ll work even when you are asleep or away!
Instead of paper, we’ll use a free online service called data.sparkfun.com to store the temperatures—which will allow you to see and use the data.
The wifi board is the same one we assembled in the chapter “Get Your Arduino Online.” If you’ve skipped ahead, you’ll need to go back to that section before doing this project.
The thermistor comes in almost every Arduino starter kit, and can be also purchased separately online. For links to kits and parts for this project, visit http://keefe.cc/temp-tracker.
The setup for this project almost exactly the same as the one in “Ice, Ice Blinky,” but with the SparkFun wifi board mounted on top of the Arduino.
Here’s how to wire it up:
5V
pin on the wifi board and connect the other end to the breadboard’s Row 1—let’s use Column e.A0
pin, and the other to the breadboard’s Row 2 at Column e. Notice that we’re staying on the same side of the breadboard’s center canal.GND
pins, and the other end of the wire to the breadboard’s Row 3 at Column e.Use your favorite code-fetching method one last time, with feeling:
family-projects-sketches-master
folder, and double-click it to open it.temp_tracker
folder.No matter how you got the project code into your Arduino software, be sure to save your work, using File → Save.
To store your data online, you need to create a free account at data.sparkfun.com. So let’s do that:
temp
. This one is important; make sure it’s just temp
and that it’s lower-case.karenstemps
.Okay! Now you get to a page with a lot of numbers and letters on it, including things like a “Private Key.” You’ll need all of these, and should have them handy down the road. SparkFun makes keeping track of them really easy with a box at the bottom to “Send yourself a copy of your keys.” Let’s do that now.
YourPublicKeyHere
.
////////////////////////
// SparkFun Data Keys //
////////////////////////
const String publicKey = "YourPublicKeyHere";
const String privateKey = "YourPrivateKeyHere";
YourPrivateKeyHere
.Great! We’re almost there.
Once again, we need to put your wifi network information into the Arduino program. So switch back to your Arduino software.
//////////////////////////////
// WiFi Network Definitions //
//////////////////////////////
const char mySSID[] = "YourWiFiNetworkNameGoesHere";
const char myPSK[] = "YourWiFiPasswordGoesHere";
YourWiFiNetworkNameGoesHere
with the name of your home wifi network, keeping the quotes.YourWiFiPasswordGoesHere
.On startup, and every two minutes after that, the Arduino will take a reading from the temperature sensor and send it to your page on data.sparkfun.com. Let’s see if it’s there.
If you don’t see information like this, check out the “Fixes” section below.
Try holding the thermistor in your hand or touching it to a piece of ice. Wait at least a minute and then refresh the data page again. See if the new values reflect what you did.
If all is well, let’s make the check every hour instead of every two minutes.
///////////////////
// Sensor Values //
///////////////////
int waitMinutes = 2;
Now you’re set!
Your temperature logger no longer needs your computer to function, so you can disconnect the USB cable from your computer and your Arduino. To make it operate solo, simply plug in the Arduino power supply. The code will automatically start running again once the Arduino is powered up, and it’ll check—and post—the temperature every hour as long as it has power.
If you are seeing entries on data.sparkfun.com, but they are all zeros, there are a couple of things to check:
Here’s the entire chain of events:
This all happens super quickly!
Whether you’re printing data to the screen in the Serial Monitor or “printing” data to another server, via the wifi board, how you format your printing can be key.
Throughout this book, you’ve probably seen Serial.println()
and Serial.print()
. Notice the subtle differences—the first one has an extra ln
after the print
part. That reads as “print-line,” which means print what’s in the parentheses, and then make a new line.
So this code . . .
Serial.print("The number of legs on an octopus is ");
Serial.println(8);
. . . would show up in the Serial Monitor as . . .
The number of legs on an octopus is 8
Notice the extra space I added after is
so the 8
wouldn’t smash up against it, like is8
.
Instead of the number 8, I could have used a variable in that second set of parentheses, like so:
int legs = 8;
Serial.print("The number of legs on an octopus is ");
Serial.println(legs);
which would output the same result.
This is the niftiest way to get variables into lines that you print to the Serial Monitor.
Once you have your data online, now what?
Well, you can download it to your own computer if you wanted, using the “CSV” button. The file you download will open in any spreadsheet program. From there, you can analyze it as you please.
You’ve also created a kind of API (remember: Another Person’s Information or, really, application programming interface). If you right-click the JSON button, you can copy the link location of that button. That Internet address is a live link to your data. Since you made your data public, that link can be used by other programmers to make their own smart objects!
More fun for you, though, may be to visualize your data.
Since your data is now online, you can use many different services to play with it. One is called Plot.ly, at http://plot.ly, which will allow you to quickly chart your data for free.
Enter
or Return
.With those settings, you should see your data visualized!
Plot.ly has lots of other features you can explore to adjust and share your chart. The entire service is just one example of how you can use your data once it’s online and available to play with.