O'Reilly logo

Raspberry Pi For Dummies by Mike Cook, Sean McManus

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Taking the Temperature

Finally here is a quick way to measure temperature. The LM335 is a cheap temperature sensor. In its cheapest form, it’s in a plastic package and looks just like a transistor. However, with the simple addition of a 1K resistor, it can produce a voltage across it that is proportional to the absolute temperature in degrees Kelvin. The connection to the Raspberry Ripple is shown in Figure 17-17. The resistor goes from the +ve to the analog input, along with the center pin of the LM335, and the right pin goes into the ground. The LM335 can be clamped to a surface to measure its temperature, or if you seal the wires with silicone rubber, you can measure the temperature of liquids.

Note that the left pin is not connected to anything. For each degree Kelvin increase in temperature, the output increases by 10mV or 0.01 of a volt. Because the Raspberry Ripple can detect a change of about 15mV, we can use this chip to measure to the nearest two degrees. For a more accurate reading with this sensor, you need to use an A/D converter that has more resolution; that is, more bits. To calibrate this temperature measuring system, you need to take the difference between the reading and the real temperature. A simple addition or subtraction of a constant is all that you need to do. The code, called Read_temp.py, is on this book’s website. For more on accessing the website, see the Introduction to this book.

Figure 17-17: Attaching an LM335 temperature sensor.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required