Home‎ > ‎

old temperature tutorial

Note: There is a newer tutorial that replaces this one that supports multiple temperature sensors.

This tutorial will guide you through the process of building a digital temperature gauge with your Raspberry Pi that can be viewed on the WWW or your smart phone.
For support, queries or suggestions please email support@privateeyepi.com or leave comments in our blog.
Step 1: Build and test the Electronics:
  • Purchase a DS18B20 digital thermometer 
  • Purchase a 4.7k (ohm) resistor
  • Put the resistor between pins 2 and 3 as in the diagram
  • Connect Pin 3 of the temperature gauge to 3.3v GPIO Pin
  • Connect Pin 2 of the temperature gauge to GPIO4 (Pin 7)
  • Connect Pin 1 of the temperature gauge to ground (Pin 6)
Once built, follow the following steps to test that it is working:
Log in to your Raspberry Pi
At the prompt pi@raspberrypi / $
sudo modprobe w1-gpio
sudo modprobe w1-therm
cd /sys/bus/w1/devices/
You will see a listing of the current directory. There should be a directory that is the serial number of your temperature gauge. The serial number of my thermometer 28-0000040be5b6, but every one will be unique. Make a note of yours as you will need it later in step 4.
If you don't see a directory with lots of numbers and letters like the one above then:
  • Check your circuit wiring.
  • Make sure you have the correct resistor (this is very important - yellow, violet, red, gold).
  • Feel the temperature gauge with your finger. If it feels hot then you have it wired back to front.
If you do see the directory then type cd followed by the directory name:
cd 28-0000040be5b6
cat w1_slave
You will now see a dump of the w1_slave file that contains the temperature data in celcius. 20812 is 20.812 degrees celcius. The dashboard does support a Fahrenheit setting that we will cover later if that is your preference.
Step 2: Register user and password
If you have not yet registered a user and password with PrivateEyePi follow the following steps, otherwise proceed to Step 3. Note this is a completely free service and has no trial period.
  • Go to www.privateeyepi.com
  • Click on "New User" option top right of the screen.
  • Enter your the details on the screen and click update.
Step 3: Configure GPIO 4
This configuration tells the system that you have connected a temperature gauge to GPIO 4 and to display it on your dashboard.
  • Click on the GPIO menu option 
  • Click "Add"
  • Type 7 in the "number" field
  • Give it a Description of "GPIO 4", or anything else you like


  • Click "Update"
  • Click the "Location" menu item 
  • Enter a Description, e.g. "Temperature Gauge"
  • Select GPIO Port 4
  • Select Type "Temperature"
  • Click "Update"
Step 4: Download version 2 of alarm.py
cd /home
rm alarm.py
Step 4: Configure the alarm.py
  • Edit the alarm.py file in order to enter your user and password
cd /home
sudo nano alarm.py
Make sure that the version at the top of the program is version 2


Page down and enter your user, password, and SMTP details. The SMTP details are not relevant for the temperature gauge, but if you have email alerts configured for the alarm system project then you need to enter the SMTP details here.
Lastly configure the temperature gauge directory you made note of in step 1 above. So in the diagram below you would replace "28-0000040be5b6" with the serial number of your temperature gauge.
If you want your temperature to be display in Fahrenheit instead of Celsius then find the following line:
#Indicator to record temperature in Farenheit
And change Farenheit=True
Press CTRL-X
Then press Y to save the file
Step 5: Run alarm.py program
cd /home
sudo python alarm.py
If you are getting errors or problems see here for diagnostic steps.
Step 6: View your dashboard
  • Go to www.privateeyepi.com
  • Log in, or click on the "Dashboard" link on top left
  • You should now see the temperature displayed