Raspberry Pi and temp sensor DS18B20 part 1

I’ve been keen to do some temperature monitoring. This is IoT basics 101. I thought of a use case for my Beer Brewing.

Jaycar had DS18B20 temperature sensors at $7.90$ NZ each. They are cheaper than the DH11 & DH22 which are more expensive as they do humidity as well.

So I thought I’d start off with these units. So found a couple of tutorials online:

Tutorial 1-Measuring Temperature with a Raspberry Pi Temperature Sensor (1-Wire) and

Tutorial 2- DS18B20+ One Wire Digital Temperature Sensor and the Raspberry Pi.

Tutorial 3- Temperature Sensor Project using DS18B20.

The interactive RPi pinout for gpio is quite handy.

I have since found the data sheet of the DS18B20.

Part 1- Abject failure-breaking the temperature sensors

To begin with I looked on YouTube but got confused with some of their setups and they were not using breadboards, or had LED screens which increased the complexity of the wiring. So I looked at the first tutorial and sort of looked at the breadboard/wiring layout and followed that (but missed the black wire to GPIO 6, so when I came to look in the /sys/bus/w1/devices/ directory there were no files there.

So I went on to tutorial 2 and tried to wire up to that one. I had all the wires but then started to reverse them and the temperature sensor started to get hot. I had 2 temp sensors and basically have moggerdored them both. I think I’ve burned them out.

The 2nd tutorial at least used Live/Ground and after reviewing the data sheet I can see NOW which pin should have gone where.

So for the time being an expensive mistake. $16 NZ down the drain and nothing to show for it.

I have ordered a multi sensor pack online to play with but that wont come for a few weeks, so I have time to dwell on being a bit less cavalier about the wiring.

Things to think about:

  • See if I can understand the wiring diagram first in relation to the sensors before buggering them up.
  • Do some testing with the breadboard or get thicker wires. Some of the wiring seemed very loose so I thought that there was not a circuit.
  • Maybe get some LED’s to put in part of the circuit to check that the connections do work.
  • Try tutorial 3 above. This one does not use breadboard but will be the final wiring for the sensors. Its also good for 2 or more sensors. So may be worth pursuing.

Now I have to wait for some more sensors and proceed more slowly

Maybe I was over confident with proceeding, although I did turn the Pi off while I did the first wiring up. I had such easy success with the camera module. Now I’m $16NZ poorer and no further ahead.

New sensors Friday 30th August

I bought a couple of DS18B20 online from a NZ outlet, they looked quite reasonable, they were the bare bones temperature sensor, a black blob with 3 wires sticking out, but I got done on delivery prices, so in the end not much less than what I could have got in Jaycar, these ones were about $6.50 with out the board and LED light. Ce la vie.

I ended up wiring the first one up wrong AGAIN. I seem to be dyslexic with the pins for some reason, anyway, if it gets hot and smells, its the wrong way around.

This time it created a sub-directory after adding the extra line in the config.txt file but it did not initially have the sensor directory. So that took a few re-boots to get those to work, but I finally got there.

I finally used a bit of a sticker to mark the Ground prong from the thermometer sensor and things went fine after that.

I now have 2 sensors working in parallel sending results to files w1_slave in the specific sensor directory.

2 sensors- I’m using a sticker to make sure I know which one is Ground.

End comment

That took a lot of breakages to get a couple of temperature sensors working. I can only get their output by interrogating the file, so it is a live temp. It is not saving any data anywhere at this point.

The next part of the process is to explore methods to log the data over time, say, take a reading every minute/5 minutes etc and store that data somewhere.

Also to send the data to another computer using MQTT or something similar. Initially I might use the cloud to act as a broker, then later install the broker on the RPi.

Overall a success for the first step, but it was not as simple as I thought. Lessons learnt? Be very careful about pins on sensors & wiring things up.

Add a Comment