In this tutorial I will be going through the steps on how to setup your very own Raspberry Pi temperature sensor. Like most of the sensor tutorials they are pretty straight forward consisting of a basic circuit and some code.
I will be using a ds18B20 waterproof sensor, this probe can provide temperatures over a one wire interface. Even better this is waterproof making it perfect if you need to use the sensor in a wet environment.
The equipment that you will need for this Raspberry Pi temperature sensor is listed below. Keep in mind the breadboard and the breadboard wire are optional but I highly recommend investing in these as they may work working circuitry a lot easier.
Building the Raspberry Pi ds18b20 Circuit
The circuit that we will need to build is pretty straight forward as we only need a resistor and the temperature sensor.
The sensor that I am using in this tutorial is a waterproof version of the DS18B20 sensor. It simply looks like a very long cord with a thick part on the end. If you have just a plain version without wiring and waterproofing, then it looks exactly like a transistor.
This sensor is pretty accurate being within 0.05°C of the actual temperature. It can handle temperatures of up to 125°C (260°F) but it’s recommended you keep it below 100°C (210°F). This device also has an on-board analogue to digital converter so we’re able to easily hook it up to a digital GPIO pin on the Pi.
Keep in mind not all temperature sensors are the same something like the TMP36 will not simply replace the ds18b20 in this tutorial. The TMP36 is an analogue device making it slightly harder to integrate with the Pi. This is basically the same problem we had with the light sensor and is because the Raspberry Pi doesn’t have any analogue pins.
Putting this circuit together is super simple, I will quickly go through some basic instructions below. If you’re having trouble following them then please refer to the video or diagram. If you need more information on the GPIO pins then be sure to check out my guide on getting started with the Raspberry Pi GPIO pins.
- First connect the 3v3 pin from the Pi up to the positive rail & a ground pin to the ground rail on the breadboard.
- Now place the DS18B20 sensor onto the breadboard.
- Place a 4.7k resistor between the positive lead and the output lead of the sensor.
- Place a wire from the positive lead to the positive 3v3 rail.
- Place a wire from the output lead back to pin #4 (Pin #7 if using physical numbering) of the Raspberry Pi.
- Place a wire from the ground lead to the ground rail.
Once done your circuit should look similar to the diagram below. Keep in mind some versions of the temperature sensor may have more wires than just 3. Refer to the datasheet for more information for each of the wires.
For more detail: Raspberry Pi Temperature Sensor: Build a DS18B20 Circuit