It has been over two years since I have got my first Arduino Uno and just this January acquired my first Raspberry Pi. The excitement returned and got another one since I broke the first one’s SSD slot. Now I have full time two Raspberry Pi’s and two Arduino’s boards kicking in data and doing stuff.
I was presented by an Indoor/Outdoor digital thermometer as a gift. Lucky me! Then on a gloomy weekend which we had a few extra ones this season here in MN, I started looking around to create a basic temperature logging circuitry using Arduino Uno. I ran into this site. http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
All I needed was DS18B20 digital temperature sensor, a 4.7 kOhm resistor. The circuitry was pretty basic which is exactly what I wanted. Here it is:
As you can see, the wiring can’t be simpler than this. Here is my set up:
The close up circuitry for the record is this:
Then I modified the built-in sketch file for the Ethernet shield to accommodate the temperature sensor. As it turns out, you need two Arduino libraries shown below:
Next you will write a bit of code to publish your reading to the web site the Ethernet shield is serving.
Here it goes – first the setup():
Next the loop() in two images:
Apologize these are simple images, but this is really cookie-cutter Ethernet shield code modified. Please type it up and see how it works instead of cloning a piece of code from github or codeplex and contacting me a few years later because it won’t work in 2017. Who knows? Maybe it will, maybe it won’t. It works in 2013.
This code will render an html page on your local network (IP address : 192.168.1.177 in this case) as follows:
Now it is time to persist this data. How to do this? How about nodejs and postreSQL? My relatively new friends… Here is the nodejs code which scrapes this data and moves it into a postresql database running locally.
Yet another image, but come on. It is only a few lines of code. Should not be an issue. I promise next blog will have “github” pull downs & forks. Basically what the above code is doing is calling in two libraries, “request” and “cheerio” (hope they are available in 2017, but this is open source, you never know). First “request'” library kicks in. It hooks up the uri address, loads up the body, returns the text of the h2 element. How exciting is that? Yes, very!!
But I want to run this for every 5 minutes… How do I do that? Well, I have a full time running Windows machine, how about I create a “Scheduled Task” for that and be done. Yes, Virginia. It is simple and it works. Look at all other scheduled tasks in your system if you don’t believe me.
Now you read your data value, perhaps you want to persist it somewhere. AWS is a bit too pricey for my taste, for now I will stay local. How about a table inside a postgreSQL database. Here it is:
So that verifies that our data is being persistent and we are collecting it. Yeah! That is how I roll, or not. Who cares if no one would see your data?
How about a simple Rails app running on Raspberry Pi? Anyone? Yeah, okay me. After two hours of installing Rails on Raspberry Pi, found here, you will have it running in no time* (it took me over an hour to get it working)
Then you can write an app like this:
Note that I am using a 3rd party library called jquery.flot.js. Then index.html.erb is this:
Now that you have a web page to render your temperature data for a given date. If lucky, you can see the actual rendering here. How cool is that?
And it runs on Raspberry Pi. How cool is that? Well, the answer is always “it depends”. But what I have done and showed is using Arduino, NodeJs, PostgreSQL, Raspberry Pi, and Rails to collect and present temperature data.
Since then I have acquired this excellent book and completed the project within. Awesome book, by the way. It introduced me to Fritzing and other components and tools. Easy to follow, highly recommend it.
Well, now that this project is wrapped and published, I am looking at other ideas and suggestions with Arduino. I am also attending arduino.mn once a month as schedule allows to exchange other ideas and collaborate with others. Bluetooth, zigbee, wifi are all interesting and I have to explore more.
Please let me know what you think of this and love to hear your feedback.
Happy Hacking!