Plotting DHT11 sensor data at using Raspberry Pi Model A+ 1

Internet Of Things

Feeling left behind, I too want to get on board the Internet Of
bandwagon by putting a sensor on the net. For this experiment,
I decided to attach a DHT11 Temperature/Humidity sensor to a Raspberry
Pi Model B+ and use to plot the data. I also
looked at which offers a similar service, but it
doesn’t actually plot your data.


ThingSpeak is an “open data platform for the Internet Of Things”. To
get started, you need to create a channel that specifies what you
are plotting – title, range, number of fields, etc. You then update
data in your channel with an HTTP request of the form:

The data stream itself can be viewed at the following URL:

ThingSpeak provides a lot of options for displaying your channel’s
data – make it public/private, changing extents, layouts, etc. The
only limitation is the rate of data updates – it has to be no more
frequent than 15 seconds. But the whole software is Open Source,
which means you could host it on your own if you need faster updates.

Raspberry Pi and DHT11

I’ve written before about the DHT11 sensor here. Here is how I
connected it to Raspberry Pi:

Plotting DHT11 sensor data at using Raspberry Pi Model A+ 2

Here is how it looks on a breadboard:

Plotting DHT11 sensor data at using Raspberry Pi Model A+ 3

Now we need to connect this to the internet.

The Code

I used Python to communicate with the DHT11 sensor and put the data on
ThingSpeak. To talk to the sensor, I used the Adafruit DHT
. Here is the code, and the output from ThingSpeak is what
you saw at the beginning of this article.


Temperature/Humidity monitor using Raspberry Pi and DHT11.
Data is displayed at

Author: Mahesh Venkitachalam


import sys
import RPi.GPIO as GPIO
from time import sleep  
import Adafruit_DHT
import urllib2

def getSensorData():
    RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 23)
    # return dict
    return (str(RH), str(T))

# main() function
def main():
    # use sys.argv if needed
    if len(sys.argv) < 2:
        print('Usage: python PRIVATE_KEY')
    print 'starting...'

    baseURL = '' % sys.argv[1]

    while True:
            RH, T = getSensorData()
            f = urllib2.urlopen(baseURL +
                                "&field1=%s&field2=%s" % (RH, T))
            print 'exiting.'

# call main
if __name__ == '__main__':

You run it by uploading it to your Pi and doing:



I was looking for a quick way to put sensor data on the Internet, and
ThingSpeak fits the bill. And now I can claim to be part of the IOT
buzz. 😉