A simple way to measure temperature using my Raspberry Pi I came across the DS18B20 1-wire digital temperature sensor.
The diagram on the right shows the DS18B20 device. It has three pins and comes in a TO-92 package which means it looks similar to other devices you may have used such as transistors.
Pin 1 is Ground. Pin 2 is the data pin and Pin 3 is the power pin. The only external component required is a single 4.7Kohm resistor.In my testing I didn’t have one of these so I used 2 x 2.2Kohm resistors in series. This worked fine.
Pin 2 was connected to P1-07 (GPIO4)
Pin 3 was connected to P1-02 (3.3V)
A 4.7Kohm resistor was placed between Pin 2 and Pin 3.
It is important to double check that you don’t confuse Pin 1 and Pin 3 on the device otherwise the power will be applied the wrong way round!
Once you have connected everything together you can power up your Raspberry Pi.
Command for config Sensor
#sudo
modprobe w1-gpio
#sudo
modprobe w1-therm
commands below to go to the directory that contains the detected 1-wire devices
#cd
/sys/bus/w1/devices
# ls
This will list the directories associated with your 1-wire devices. Each one has a unique ID and in my case it is 28-00000482b243. Your ID will be different so be sure to use that in the example code below. Using “cd” we can change to the temperature sensor directory, list the contents and then view the “w1_slave” file :
# cd
28-00000482b243
# ls
# cat
w1_slave
Credit : http://www.raspberrypi-spy.co.uk/2013/03/raspberry-pi-1-wire-digital-thermometer-sensor/
No comments:
Post a Comment