Since I've discovered that it's relatively easy to access Raspberry Pi's GPIO pins, I'm constantly looking for stuff to connect to it. Fortunately the Internet is full of them.
One of Raspberry Pi's limitations (compared to, say, an Arduino) is that it doesn't have analog pins, only digital ones. So to connect a sensor with analog output, you have to go through an analog-to-digital converter (ADC). The fine folks at Adafruit have written a tutorial on how to talk to an MCP3008 ADC from a Raspberry Pi to read the state of a potentiometer. I swapped the potentiometer for a TMP36 temperature sensor and now my Raspberry Pi knows what the temperature is.
Here's a nice looking diagram of how the connections go:
And here's a considerably more messy real-life shot:
I monitored the temperature in my room for some time and decided that it was boring. So then I put my new creation in the fridge to see how cold it is in there. Initially I wanted to put just the sensor in and keep the Raspberry Pi outside, but with all the cables going from the Pi to the breadboard, it was easier to just put everything inside with only the power cable going out. The Pi didn't mind the low temperature and I hope the small amount of heat it produces didn't affect the fridge and the measurement. And if you ever wondered whether wifi would work from inside a fridge, I'm happy to report that it works just fine.
Here's what it looked like inside my otherwise mostly empty fridge:
And here are the results:
(I averaged the data a bit, because the readings from the sensor were pretty noisy.)
It turns out that the temperature inside my fridge varies quite a bit, from around 3 °C to around 8 °C. The compressor runs for about 37% of the time (though that number probably depends on outside temperature and possibly the contents of the fridge).
Here's the script I used to read the temperature from the sensor, but it's mostly identical to the one in Adafruit's tutorial. One interesting thing about it is that it uses what's called a "bit banging" SPI implementation (the Raspberry Pi also has hardware SPI and we could use that just as well).
Thank you for your tutorial. It is very useful for me.
ReplyDeleteI like your fridge
ReplyDelete