Generating Genius Computing Exercise

These instructions will lead you through how to build your temperature and humidity sensor.

What is the Raspberry Pi computer that we will be using?


  • A good introduction can be found here
  • The computer that we've lent each of you is a Raspberry Pi 3. The figure below labels what some of the generic bits are:

    1. sensor
  • The Raspberry Pi has no power button, it switches on as soon as the power cable is connected - so before we connect the power we need to connect each of the following:

  • Once your Raspberry Pi is plugged in it will load to a screen looking something like that below. Feel free to have a bit of a play and get a feel for it - you will find that it is very similar to what you are used to with any other computer.

    1. sensor

    Setting up the sensor hardware


  • Make sure that your Raspberry Pi has been shut down and is unplugged from the power supply

  • We then need to plug the temperature and humidity sensor:

    1. sensor
  • into the Raspberry Pi's General Purpose Input Output (GPIO) pins:

    1. sensor
  • These pins (or connectors) allow the Raspberry Pi to talk to and receive input from the real world. The diagram below shows you what the different pins are and names them. The ones that you will have to worry about are the ones that output electric current at 3.3v (similar to a battery), and any of the 'Ground' pins which are the points against which the voltage to any other pin can be measured - see http://en.wikipedia.org/wiki/Ground_(electricity). In this situation we've chosen to use GPIO pin 4 (as well as the 3.3V and ground pins).

    sensor

  • The temperature/humidity sensor you've got is called a DHT22.

  • Background: If you are interested in the details about this sensor see here. It measures temperature by measuring how hard it is to push electricity through a thermistor (a conductor that conducts better at higher temperatures and worse at lower temperatures), it then measures humidity by measuring how efficiently a special capacitor inside the sensor can work - this works because moist air allows the charge held by the capacitor to leak away. Rather than us having to convert the resistance and capacitance within this sensor into a temperature and humidity as we would have to do if this was an analogue sensor, the DHT22 converts this information into a digital signal. This digital signal is communicated to the Raspberry Pi by very briefly diverting the current that was coming in from the 3.3v pin and out to the ground pin, across to the middle (brown) wire coming out of the sensor. The length and pattern of this voltage across the middle wire is encoding the information about temperature and humidity. All we need to do therefore is measure when there is a voltage change across out GPIO pin on the Raspberry Pi and we can work out what the temperature and humidity is - simple!

  • The sensor has a white, brown and purple wire soldered to it, then three arbitrary coloured connector wires soldered to the ends of them:

    sensor

  • The black bits on the end of the wires can slide over the Raspberry Pi GPIO pins to connect the sensor to the Raspberry Pi. You now need to connect:
    1. The white wire coming from the sensor to the 3.3v pin (see diagram above)
    2. The brown wire coming from the sensor to the GPIO pin 4
    3. The purple wire coming from the sensor to one of the ground pins
    4. REMEMBER THAT THE COLOURED WIRES THAT PUSH ON TO THE GPIO PINS ARE RANDOM COLOURS, IGNORE THE COLOURS OF THESE!
    It should look something like this:


    sensor


    Setting up the software

  • Make sure the ethernet cable is connected to your Raspberry Pi (and to the wall), then plug in the power cable to started the Raspberry Pi up...

  • To allow us to read data from the sensor, and store this data, we need to install various pieces of software. To do this we need to open the 'terminal', and type various commands in to this. The 'terminal' window is our way of controling the computer powerfully - the image below explains how to open it.

  • terminal


  • Next, type (or copy) the following in to the terminal, pressing enter after each one. NOTE, read the output from each command, and if it asks you a question type 'Y' to say 'yes', then press enter.
  • You are now ready to run the downloaded software to see what temperature and humidity the sensor is reading. Do this by typing:
  • Background: This is saying that as a superuser (so that you have the correct permissions) run a python script in the directory /home/pi/Adafruit_Python_DHT/examples/ called AdafruitDHT.py, and feed it two numbers, 22 is the name of the sensor (DHT22) and 4 is the number of the GPIO pin it will be receiving the signal on. Does it work? If not, go back and follow the instructions carefully again to make sure that you have done everything exactly right! If it does, well done! You've made your Raspberry Pi do something that you could not make any normal computer, phone, tablet do without buying some very expensive equipment!


    terminal

    Setting up the final piece of software which will log the temperature and humidity data

  • We will start by downloading a script we've written for you to make the measuremenst and upload them to the web. To download the script, type the following in to your terminal (pressing enter after each line):