Blake Brewer
Created April 28, 2016 © GPL3+

Temperature and Humidity Sensor Raspberry Pi IOT

Sends data accessible online for temperature and humidity

IntermediateProtip5 hours989
Temperature and Humidity Sensor Raspberry Pi IOT

Things used in this project

Hardware components

DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1

Story

Read more

Code

Raspberry Pi DH22 IOT

Python
The following code takes data collected from the dht22 temperature and humidity sensor and sends it to Ubidots where it can be viewed online.
from ubidots import ApiClient
import Adafruit_DHT
import RPi.GPIO as GPIO
import time

sensor = Adafruit_DHT.DHT22

pin = 4

humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
# Create an ApiClient object

api = ApiClient(token='blRKvyxIkkWGqVSWRqSya2pfGKogcB')

GPIO.setmode(GPIO.BCM)
GPIO.setup(1, GPIO.OUT)
GPIO.setup(7, GPIO.IN)
GPIO.setup(6, GPIO.OUT)
# Get a Ubidots Variable

try:
    variable1 = api.get_variable("5711025d76254250de6dac65")
    variable2 = api.get_variable("571ba07976254240aa73c7c7")

except ValueError:
    print"It is not possible to obtain the variable"

while(1):
    try:

        # sends data to ubidots.
        # temperature reading is in fahrenheit since thats what Americans         like

        value1 = (temperature)*1.8+32

        value2 = humidity

        variable1.save_value({'value': value1})
        variable2.save_value({'value': value2})

        print "Value sent"
        time.sleep(1)
    except ValueError:
        print "Value not sent"

Credits

Blake Brewer

Blake Brewer

1 project • 2 followers
Thanks to techprolet.

Comments