As I had to quickly come up with two DS18B20 Sensors for the Raspberry Pi, I decided to built them "quick and dirty" without any breadboard. It is not the most beautiful nor the best way, but it works out quite well. With one exception: It seems like the sensor is too near to the Pi and picks up heat from it :/. Anyway, here are some photos:
That is how it would look like later.
Adding some female header to the base. We need 5 Pins for that. The first pin is going to be connected to 3,3V, the fourth to the GPIO Pin 4 and the fifth to ground. So just cut the pins 2 and 3 from that header.
Add an resistor to pull the Data Pin high to 3,3V. You should use an 4,7k Ohm, but anything between 4,7k - 10k Ohm should work out. I used an 10k Ohm here.
Solder the two pins of the resistor to Pin 1 and Pin 4. Do NOT short with Pin 5!
Add some silver wire to the fifth Pin.
Solder the DS18B20 to the Pins. Watch out for the curved side of the Sensor, it has to face upwards!
I choose to secure the whole sensor against short circuits and stuff with hot glue. Looks ugly, but does the trick.
Last thing is installing the sensor in the left upper corner of the GPIO Pins of your Raspberry Pi.
After booting you have to activate the One Wire protocol like this:
sudo modprobe w1-gpio
sudo modprobe w1-therm
Then you can read your sensor by using this command:
cat /sys/bus/w1/devices/28*/w1_slave
If you want to get your reading nicely formatted, you should install bc with
sudo apt-get install bc
and use this code:
echo "`cat /sys/bus/w1/devices/28*/w1_slave | grep t | cut -d= -f2`/1000" | bc -l | awk '{printf "%.2f \n", $1}'
Be aware the the sensor is not water-proof. Once humid it shows 5° to 8° more than real temperature. Check if the temperature is in this range different to real temperature... so it was humid.
Workaround: As it will stay wrong in tempeature ("stable wrong"), just correct it by software.
Generally you should buy the same type as water-proof version. At aliexpress.com you get two for ~4 Euro - tax and delivery inclusive! Same costs 6 Euro (piece) @ Reichelt or Amazon.
Hope it helps.
Regards Samazw
Thanks for your hint :)!
Regards,
Nico