Raspberrypi-dht22-ubidots

This project uses a Raspberry Pi connected to a DHT22 sensor to read the temperature and humidity of its surroundings to a website called Ubidots, this site then plots these readings as charts and allows real-time analytics to be performed.

View project on GitHub

RaspberryPi-DHT22-Ubidots

This project uses a Raspberry Pi connected to a DHT22 sensor to read the temperature and humidity of its surroundings to a website called Ubidots, this site then plots these readings as charts and allows real-time analytics to be performed.

Components

  1. Raspberry Pi B+ [or later]
  2. Gobbler
  3. Breadboard
  4. Connecting wires
  5. DHT22 [or DHT11] Digital Humidity and Temperature Sensor
  6. Power Source for Raspberry Pi
  7. An ethernet cable or a Wifi Module [USB ones work fine]

Requirements

  • Router with DHCP capability
  • Wired or wireless Router

Circuit Diagram

Download Fritzing from here and open the Fritzing project to have a better idea about the connections.

Pre Connection Procedure

  1. Flash the Raspbian Jessie OS into the MicroSD card of your Raspberry Pi using the Win32 Disk Imager Software
  2. Insert the MicrSD card into your Rapsberry Pi
  3. Download and run Putty, a SSH Client.
  4. Power up the Raspberry Pi and connect it to your router using an ethernet cable
  5. Determine the IP Address of your Raspberry pi from the router and enter that IP Address as hostname in the Hostname text field in putty
  6. Connect to the Pi using putty, even if the connection refuses once or twice, its okay, try again, it will connect.
  7. The default username is "pi" and password is "raspberry", login to your pi using these credentials
  8. Expand the file system in Raspberry pi sudo raspi-config
  9. Set the time zone of the system in Raspberry pi sudo raspi-config
  10. Run the udpate a few times sudo apt-get update
  11. Install the necessary softwares sudo apt-get install git-core python-dev python-pip python-smbus .These will come in handy later
  12. Then reboot, sudo reboot

Preparing the Pi for DHT22 / DHT11

  1. Connect the sensor to the Pi as shown in the circuit diagram
  2. git clone https://github.com/adafruit/Adafruit_Python_DHT.git to clone the ADafruit DHT repository into your Pi
  3. cd Adafruit_Python_DHT
  4. sudo apt-get install build-essential python-dev python-openssl to install the necessary packages needed to install external python libraries
  5. sudo python setup.py install to install the external library
  6. cd examples
  7. sudo ./AdafruitDHT.py 2302 4 to run the example and check if the sensor is working or not

Installing Ubidots package

This is a simple three step procedure, just run the following commands
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install ubidots

The Python Script

  1. Sign up at Ubidots
  2. Go to Sources and create a new source
  3. Click on the source you just created
  4. Add two variables, one called Humidity and other called Temperature, honestly you can create as many variables as you want and call them whatever you want, but for this project what we need are these two.
  5. In the right bottom of the screen, select the Device wizard and select Raspberry Pi, then give the units for each variable, the number of seconds you want the delay between each reading to be and hit generate code.
  6. The code needed to send the data to the Ubidots source is generated, copy it and create a python script.
  7. This script sends random data and it is not the actual data we want to send, now we need to use the Adafruit Python DHT library and create the rest of the script needed.
    Add these lines of code in the appropriate places
    import sys
    import Adafruit_DHT
    #Set the type of sensor and the pin for sensor
    sensor = Adafruit_DHT.DHT22
    pin = 4

    Within the try block inside the While(1): add this line
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    And replace the variables value1 with humidity and value2 with temperature
    Remove the lines that assign values to value1 and value2.
  8. Run the code using sudo python fileName.py
  9. Check the values in the variable, they keep updating as and when the Pi sends the value
  10. You can create widgets with the values, download the data, or send that data as a public link.

Snapshots

The data when viewed in the Data Soruce

The data when viewed as widgets