Introduction: Room Temperature With Pi

Hello everyone.
Today I have a Small Project I've done using the Raspberry Pi. This Project is a Thermometer that Reads the Room Temperature every 5 minutes, lights one LED and then Writes the Temperature to a File.

This is a Beginner Project that anyone who wants to get into Electronics can do. It's very Simple to Setup and requires almost no knowledge. I will try to explain how to Complete it as Easy as I can.

Let's get Started!

Step 1: Materials You Need.

For this Project you will need the following Materials:

  • Raspberry Pi (including all the other Components for it to Work)
  • BreadBoard
  • One LED
  • One 330ohm Resistor
  • One 4.7kOhm Resistor
  • DS18B20+ Programmable Resolution 1-Wire Digital Thermometer
  • Wires

For the Raspberry Pi, any Operative System will work as long as you can Run Python Code. I'll be using Wheezy. But NOOBS should work as well.

My BreadBoard is a Small One. And all the other components came from ModMyPi. Or if you want the Pack I Bought its this one: ModMyPi - Youtube Kit.

Step 2: The Setup

Okey, in this Step we are going to Setup all the Components.

The Raspberry Pi, like I said before, any Operating System that runs Python Code should suffice. I'm not going to show you how to Mount a SD Card with the OS but if you want to know just visit This Site. There is also a little fix we have to do in order for the Thermometer to Work. You can find it here.

As for the BreadBoard I have the Schematics in Image. Just Follow them it shouldn't be too Hard (keep in mind that the Images have more than what is necessary to complete the project).

Insert the LED Wire in the GPIO 17 on the Pi and the Thermometer wire in the GPIO 28 (if GPIO 28 is being used you can insert it in any other pin). Insert the Ground and Power Wires in the BreadBoard and in the Pi (these are the Black and Red Wire in the Schematics). And don't forget the Resistors, both the LED and the Thermometer need them.

Step 3: The Code

Now I'm going to talk a little about my Code. First of all I'm not very skilled in Python, I just know some Basics.

The Code has 3 Functions and a Main Loop:

  • read_temp_raw(): Reads the Temperature from the File that the Thermometer generates.
  • read_temp(): Reads and Parses the Temperature so you can Understand it. This also does the Conversion to ºC.
  • write_to_file(): Writes the Temperature to a File so you can see it later.
  • main loop: This is the Heart of the Program, it Lights the LED, Reads the Temperature, Writes the Temperature to a File and turns the LED off. Then it sleeps for 300 seconds (5 minutes) and Repeats the Cycle for ever.

We also have 4 Variables on this Program, they are:

  • base_dir: This Directory is the Root for the Devices connected to the Pi.
  • device_folder: This is the Directory that the Thermometer uses to store his Data.
  • device_file: This is the File used to store the Thermometer Data.
  • output_file: This is the File where we Write the Temperature. You can change this Location to wherever you want. Mine is in a Folder called "Temp" in the Desktop.

Now all you have to do is to write: "sudo python" in the Folder where the Python Code is Located in order to Run the Program. This will Run forever so, in order to Stop it all we have to do is Press Ctrl + C and the Program will Stop.


Step 4: Conclusion

Finally checking the Temp01.txt file that our Program creates we can see the Temperature as well as the Time that Temperature was Read.

And with that we Conclude this Instructable. I would like to say that this is my First time writing one Instructable. If you happen to have any Problems with this Build you can Comment in here and I will try and Help you.

Furthermore if you have something you would like to see build also comment it here, or else you can send me a e-mail. You can find my e-mail in my Profile.

Thanks all for reading. And I hope you Liked this Project.