Internet of Things Temperature sensor

My first IoT project is a room temperature sensor publishing data to cloud.

Google DS18B20 + Raspberry Pi and you fill find many posts about it. I followed one of them

https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/temperature/

Purchasing the hardware and electronics part was a big difficult in India. The parts are cheap, but finding the correct ones on internet or local shops was a bit challenging for me.

Once I procured all the hardware, the only change in the above circuit diagram is to use 5V rather than 3.3V. With 3.3V, sensor was getting detected, but there was no reading from it.

Data is read by Python function

def read(precision):
inputfile = open("/sys/bus/w1/devices/28-031464907dff/w1_slave")
text = inputfile.read()
inputfile.close()
tempdata = text.split("\n")[1].split(" ")[9]
temp = float(tempdata[2:])
temp = temp / 1000
temp = int(round(temp,precision))
return temp

To upload use API provided by data.sparkfun.com

import urllib2
def publishtoInternet(temp):
url = "http://data.sparkfun.com/input/<public_key>?private_key=<your_key>&temp=" + temp
result = urllib2.urlopen(url).read()
print result

And that’s it! This is an always on temperature sensor. You can not only publish it to internet, you can also use the reading to take decisions like controlling other IoT things.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s