Page
Stránky / Súčiastky ku Arduinu / Meranie teploty /
DS18B20 is a digital temperature sensor with a 9-12 bit resolution. Communicates with One Wire. The Datasheet with details is on the manufacturer's page. The circuit is a must for any amateur experimentator and sooner or later you will end up trying to make a small meteorological station with it.
A regular user buys this circuit in the TO-92 case.
The circuit can be connected in two ways:
You need to install two libraries:
The connection is simple. Exactly according to the description of the connection. You only have to choose which digital input will read the data from the sensor. In this case, it is a digital pin 2.
Measurement resolution is inversely proportional to the time the A/D sensor needs.
Bit resolution | Time of measurement | Measurement resolution |
---|---|---|
9 | 93.75 ms | 0.5 °C |
10 | 187.5 ms | 0.25 °C |
11 | 375 ms | 0.125 °C |
12 | 750 ms | 0.0625 °C |
Of course, everyone will want to measure in the highest resolution and as often as possible, but one has to deal with several issues:
Sensor accuracy is:
In the datasheet, you can still read that the sensor has an internal memory of 8 bytes, and of which 3 bytes are backed up to the EEPROM. There are two bytes for the alarm, which is a function that you probably will not need in amateur condition. The last byte is the configuration register in which the measurement resolution is stored.
During measurement and during write to EEPROM, the sensor needs a 1.5 mA current.
We can also connect multiple sensors to one One Wire bus without problems. Each sensor has its unique number (address) that we communicate with.
Before testing with the sensor, it is advisable to test whether the sensor is properly connected. This is a useful example that comes with the OneWire library. It's called DS18x20_Temperature.ino. The attached picture is different from the pin on which the sensor is connected. The pin 10 is used in the example.
After running, it will list all the sensors found on the serial port. In this case, for example, it wrote information about the two connected sensors.
ROM = 28 8C 6E 45 6 0 0 8A Chip = DS18B20 Data = 1 A3 1 4B 46 7F FF D 10 CE CRC=CE Temperature = 26.19 Celsius, 79.14 Fahrenheit ROM = 28 49 BD 44 6 0 0 61 Chip = DS18B20 Data = 1 A2 1 4B 46 7F FF E 10 D8 CRC=D8 Temperature = 26.12 Celsius, 79.02 Fahrenheit No more addresses.
The second option is an example from DallasTemperature called Tester.ino. He writes the data in the following form.
Dallas Temperature IC Control Library Demo Locating devices...Found 2 devices. Parasite power is: OFF Found device 0 with address: 288C6E450600008A Setting resolution to 9 Resolution actually set to: 9 Found device 1 with address: 2849BD4406000061 Setting resolution to 9 Resolution actually set to: 9 Requesting temperatures...DONE Temperature for device: 0 Temp C: 24.50 Temp F: 76.10 Temperature for device: 1 Temp C: 24.50 Temp F: 76.10
List of articles describing this temperature sensor:
07.09.2019