Thermal Sensor (DS18B20)

In this tutorial, we will be writing a program to read the temperature sensor data connected to pin number7 (GPIO4).

Assumes EduBoard already attached to Your Raspberry Pi, through the GPIO pins.

 

DS18B20 temperature sensor connected to pin 7 (GPIO4)

Diagram showing how to connect DS1820 sensor to Raspberry Pi

 

The DS18B20 digital thermometer provides 9 – bit to 12 – bit Celsius temperature measurements and has an alarm function with nonvolatile user – programmable upper and lower trigger points. The DS18B20 communicates over a 1- Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of – 55°C to +125°C and is accurate to ± 0.5 ° C over the range of – 10°C to +85°C. In addition, th e DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply. Each DS18B20 has a unique 64 – bit serial code, which allows multiple DS18B20s to function on the same 1 -W ire bus . T hus, it i s simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment , or machinery, and pr ocess monitoring and control systems.

 Before you begin to install any software it’s best to make sure the package files are up-to-date. Tutorial 3

Once a user is logged on to the Pi, type these commands into a terminal.

Depending on the version of Raspian, you might need to make a small change to the config.txt file using :

add the following line to the bottom :

The entry on the screen that is mostly numbers is the serial number of the sensor. The sensor used for this tutorial has the serial number “28-0004640252ff”. Replace the serial number in the next command with the one for the sensor used.

 The cat command is considered as one of the most frequently used commands on Linux or UNIX like operating systems. It can be used for the following purposes under UNIX or Linux:

  • Display text files on screen.
  • Copy text files.
  • Combine text files.
  • Create new text files.

Two lines of text will be printed. On the second line, the section starting “t=” is the temperature in degrees Celsius. A decimal point goes after the first two digits, so the example value of “t=30687″ is in fact “t=30.687″ degrees Celsius:

Temp Sensor