Created 18 March 2016
Last updated 2 December 2016
For many years I have wanted to set up a small weather station using an Arduino microcontroller . Recently I have resumed work on my clock pendulum characterization project. That project includes the need to measure and record the temperature, pressure and humidity inside a pendulum clock case. In preparation for that project I decided to experiment with and setup a temperature data logger using an Arduino and parts that I had on hand.
This has been a very interesting little ‘sub’ project and includes the following features:
- DS18B20 digital onewire temperature sensor
- DS1307 real time clock
- SD card to store a CSV format log file
- daily synchronization of the real time clock with an NTP server to keep it on time
- ethernet connectivity of the Arduino Mega microcontroller
- webserver on the Arduino to display the current temperature and a historical chart
- automatic upload of temperature data to a Phant telemetry server (viz data.sparkfun.com)
- Google Charts graphing of data embedded in the Arduino hosted webpage
[UPDATE 27/10/2016: I’m sorry but the above link is down. I recently relocated abroad so the Arduino has been packed a way for transport. It will be back up within the next month or two in a new climate. Sorry I didn’t put up a screen shot of how the page looked. My bad.]
[UPDATE 30/11/2016: The above link should be back up now. The sensor is now relocated to Australia from Germany. It seems that the data.sparkfun.com Phant server is not working well. My personal (local) Phant server is working fine with this code. This explains why the temp reading is up to date but the Google Chart is still being fed by yet to be updated Phant data at data.sparkfun.com. Hopefully they will fix it soon. Your best bet then is to run your own Phant server, which is quite easy – instructions at data.sparkfun.com]
[UPDATE 1/12/2016: While the above link to my Arduino temperature sensor web page is working, the Google Chart is still only representing old data from before my relocation. I believe this is being caused by problems with Sparkfun’s free Phant server. The Arduino has not been able to successfully send an update to that server and often get errors when I try and access it’s web site/interface. This is a bit sad and other have noted this on Github. Hopefully it will come good. We could solve this problem by hosting our own Phant server (see paragraph above). My own personal Phant server is not public and so the Google Charts engine would not be able to access the data for display on the chart at the above link. Let’s wait and see if Sparkfun’s Phant server comes good. Don’t be put off by any of this – host your own Phant server!]
Here are some photos of the DS18B20 sensor package and the Arduino with ethernet shield and real time clock mounted on a piece of wood. There’s also a low res screen shot of how the Arduino page above looks like if it is offline for whatever reason.
I am not a programmer. I have cobbled together code from a couple of sources, inlcuding the blog at Bajdi.com. The code seems to work fine, but it might be a little messy (because of my changes not Bajdi.com!). I am still learning how to programme Arduinos. If you have found any major flaws I would be interested to know. Please leave a comment below.
I would really like to know if you have found this page and work useful. Please leave a comment or send me a message via the Contact page!
I modified Arduino code that I found on a post at the blog Bajdi.com (see links and References section below). In addition to this, I added code to send the data to the Phant server using http post requests (see the spakfun tutorial on this). That code was for a temperature data logger recording to an SD card and using a real time clock for the recording timestamps. The DS1307 real time clock is known to drift a bit each day, so the code I found on this website synchronized the real time clock to a NTP (network time protocol) server once per day to keep everything on time.
The SD card recording and the timestamp functions have become redundant in my implementation. The reason for this is that I now have the datalogger sending each reading to the Phant server of data.sparkfun.com. This service replaces the SD card and automatically adds a timestamp to each sensor reading my datalogger sends it. This service is very cool. In the Arduino code I have included below I have left the SD card, real time clock and NTP synchronizing functions in. This is for reference. By leaving them in I effectively have a local backup of my temperature readings, but if I didn’t need that I could remove these functions and rely solely on the Phant server. This would of course free up some space on the Arduino. For now I will leave it in.
Once you understand what the Phant server is and how it works you should read this post on their website Graphing Live Data With Google Charts. I took the example code on that page and manually encapsulated it, one line at a time, within the part of my Arduino code that generates the little website. This then generated a simple but sleek Google Chart from my data stored on the Phant server at data.sparkfun.com. You should also be sure to read the tutorial on the sparkfun website about pushing your data to their Phant server.
Arduino code extract: