Keyes 18B20 Temperature Sensor and Raspberry Pi 2
I recently got my hands on a Keyes 18b20 temperature sensor.
These are great little modules but it took awhile to figure out how to get it connected to the raspberry pi and the necessary Raspberry pi config.txt changes.
Keyes 18B20 Pinout
Here are the Pinouts for the Module.
The Module already has the 4.8 K pull-up resistor you'd typically have to wire up along with the DS18b20 so the only components you need are the Keyes module and a Raspberry pi.
The Module also has an LED that will flash when the temperature is read.
Raspberry Pi2 GPIO Header
The 18B20 is a 1 wire device so the Signal pin needs to be connected to Pin #7 GPIO04 (GPIO_GCLK).
For the GND we'll use Pin# 06.
For the 5v we'll pick Pin #02
Wiring it up
To wire it all up.
Keyes GND -> Pin# 06.
Keyes 5V -> Pin #02
Keyes Signal -> Pin #07
Config the Pi w1-gpio
By default the w1-gpio is not enabled. You need to enable w1-gpio in the config.txt or the Pi will not recognize any 1 wire devices.
To enable w1-gpio open the config.txt file in nano with the command:
sudo nano /boot/config.txt
Add the following line to the config.txt file.
dtoverlay=w1-gpio
save and exit nano.
Reboot your Pi.
Reading the Temperature Sensor
To read from the temperature sensor you need to find the device Id. Each 1-Wire device is identified by with a unique id consisting of a family code and identifier. The Temperature sensors will have a family code of 0x28.
Go to the directory that contains the 1 wire devices and list the contents.
cd /sys/bus/w1/devices
ls
There will be a list of the devices on the 1 wire bus.. You will see something like 28-031465885cff.
To read the data you'll read the contents of the w1_slave file substituting the ID of your device for 28-031465885cff.
cat "/sys/bus/w1/devices/28-031465885cff/w1_slave
The temperature will be at the second line of the file in the form
t=22300
Value is in Celcius*1000 so in the above example it would be 22.3 degrees celcius.
Hi! I am a content-detection robot. I found similar content that readers might be interested in:
http://bigfieldsblog.cloudapp.net/keyes-18b20-temperature-sensor-and-raspberry-pi-2/
Congratulations @rogergrambihler! You received a personal award!
Click here to view your Board of Honor
Congratulations @rogergrambihler! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!