DS18b20 is a simple temperature sensor which gives digital output on single I/O pin based on 1-wire protocol, so this can be used with the Raspberry-Pi without the need of Analog to Digital Converter (ADC).
On Raspberry Pi, 1-wire interface can be enabled by using sudo raspi-config utility, select “Advanced Option” and enable the 1-Wire interface. raspi-config utility edit /boot/config.txt file. We can do this manually by editing /boot/config.txt file and adding
dtoverlay=w1-gpio # When use default 1-Wire I/O pin GPIO 4.
or
dtoverlay=w1-gpio, gpiopin=pinnum #example
dtoverlay=w1-gpio, gpiopin = 25
#and reboot the board.
There are two kernel modules w1-gpio and w1-therm for enabling 1-wire protocol and interfacing DS18b20. use modprobe command to insert these modules from /lib/modules/ of Raspberry pi. Once these modules successfully establish communication with digital thermometer (DS18b20) new folder is created in “/sys/bus/w1/devices/” along with w1_bus_master1.
Inside the directory created the file w1_slave gives the reading of the thermometer. Below image shows the sequence of commands used for reading temperature value for DS18b20 on Raspberry -Pi.
These values can be read programmatically by using Python, C file I/O APIs.