Catalog
- DS18B20 Digital thermometer ( One ) Electrical characteristics , Parasitic power supply mode and remote wiring
- DS18B20 Digital thermometer ( Two ) Thermometry , ROM and CRC Algorithm
- DS18B20 Digital thermometer ( 3、 ... and ) 1-WIRE Bus ROM search algorithm
DS18B20
DS18B20 Is a common digital thermometer chip , Because the temperature measurement is accurate , Cheap and easy to connect , Widely used in practice , In all kinds of teaching experiment suits, the appearance rate is also very high .
Doing it FwLib_STC8 GPIO Example I wrote it when I was DS18B20, This model looks simple , But using the mechanism is more interesting , I can't write in one space , So take out the content and introduce it separately .
Parameters
- 1-Wire Bus Bus structure , It is allowed to connect multiple on one bus DS18B20 And communicate separately
- At ordinary temperature , You can take power directly from the data port , At this time, only two wires are needed .
- Supply voltage [3.0V, 5.5V]
- Temperature detection range [-55°C, +125°C] Centigrade , [-67°F, +257°F] Fahrenheit
- Accuracy : stay [-10°C, +85°C] by ±0.5°C
Parameter description
- The error under normal temperature shall not exceed ±0.5°C
Cheap for domestic products DS18B20 Actually measured , Basically in this range to , At room temperature of twenty or thirty degrees Celsius , The individual error of the actual test is ±0.35°C within . - Low power consumption
Single DS18B20 Use one 0.1uF The capacitor can drive - Temperature monitoring can be carried out through three wire or two-wire connection
Get rid of Vcc and GND, In fact, only one is needed IO Line , Very economical MCU Of IO resources - Support the connection of multiple chips on a single line bus
Only one communication bus is required IO, This line can also be connected to multiple at the same time DS18B20 signal communication , And the distance is very long , It can reach hundreds of meters .
About the maximum communication length and DS18B20 Number of nodes
1-Wire Bus On the bus DS18B20 The quantity and distance of are related to the wiring form , Fifty or sixty are connected at a short distance of more than ten centimeters DS18B20 No problem , If it is a long distance connection of hundreds of meters , Suggest 10 Within a , Don't exceed at most 20 individual . The above premise is that the power supply is sufficient . DS18B20 These characteristics are particularly advantageous in industrial environments , For example, one IDC Computer room , Only one of dozens of temperature measuring points is needed 8 position MCU You can complete the collection , Low power consumption and reliability .
Pin foot
What you usually see is 3pin Of To-92 encapsulation , Like an ordinary triode , Make the plane face towards yourself , Pin Feet down , From left to right is : GND, DQ, VDD

Single DS18B20 The wiring of the cable
Single DS18B20 Is the most basic way to connect
Normal power supply mode
The normal power supply mode uses a three wire connection , The voltage can be selected 3.3V or 5V
- MCU IO -> DQ
- GND -> GND
- 5V/3.3V -> VDD
Parasitic power supply mode
The parasitic power supply mode uses a two-wire connection . Now DS18B20 Of GND and Vdd Be grounded . DQ The pin is both a data communication pin , It is also a power supply pin , The upper computer needs to use a pull-up resistor on this pin to connect to VCC On , about STC8, It can be done through registers PxPU Set it up .
It should be noted that , Is not All online purchases DS18B20 Can work in parasitic power supply mode , There are some batch numbers DS18B20 It can not work under the circuit of parasitic power supply mode , Reading only outputs 0. I suspect it's cutting corners , The capacitor and diode needed for parasitic power supply are omitted . For this kind of DS18B20, Some additional circuits are needed to make it work in two-wire mode .
- MCU IO -> DQ
- GND -> GND & VDD
Simulate parasitic power supply mode
If DS18B20 Cannot operate in parasitic power supply mode , You can use one 0.1uF A capacitor and a 1N4148 Diodes realize two-wire connection . Now DS18B20 In fact, it works in normal power supply mode .
+-----1N4148-|>|-----+
| |
| |DS18B20|-VCC--+
| | | |
MCU IO--+-DQ--|DS18B20| 0.1uF
| | |
GND ----GND-|DS18B20|-GND--+
The parasitic power supply mode is simulated by bread board , There are only two wires behind it 
Multiple DS18B20 connection
In the actual scene , DS18B20 Often use in groups , Used to collect temperature information of an area , The area spans from tens of centimeters ( The case , Cabinet , Lathe ), To hundreds of meters ( residential , Computer room , workshop ) It's possible . There are different choices for different distances and environments , To sum up, there are several situations
You can refer to this one 1-wire Bus wiring https://www.loxone.com/enen/kb/wiring-1-wire-devices/
Bus connection mode
In the following structure S representative Sensor, DS18B20. MCU It's MCU .
Bus mode is the recommended wiring mode , be-all DS18B20 All connected to the same line . The longest distance communication can be achieved by using bus connection
MCU-------8m---S---3m----S----3m----S-----10m-----S
Or there are individual forks , The fork is very close to the bus
MCU-------8m----------+--S---3m----S--+--10m-----S
| |
1m 1m
| |
S S
Star connection mode
If more and longer forks occur on the bus , It becomes a star connection , Similar to the following wiring method , Star connection is only recommended for small area scenarios , Compared with the bus connection mode , The length is much shorter .
S---------8m----MCU
|
4m
|
S------6m-----+----3m------S
|
8m
|
S--+------4m-----+----6m------------S
|
2m
|
S
Power supply mode
Centralized power supply
Most scenarios use centralized power supply . In this scenario , By the control end (MCU End ) Power supply .
If three wires are used, there is no need to pay attention to , If two-wire connection is used , We need to pay attention to
- Because communication IO At the same time, it is responsible for power supply , So you need to configure the pull-up resistor , Pull up resistor in short distance scene 5KR enough , But in the long-distance scene, it needs to be reduced , You can try to use 2KR The resistance of .
- In case of parasitic power supply mode simulated using normal power supply mode , Voltage usage 5V, Capacitors need to be close DS18B20 Deploy , Every DS18B20 Match one 0.1uF The capacitance of .
Terminal power supply
In a conditional scenario , Every DS18B20 It can be supplied separately , At this time, the control end is connected with DS18B20 Common land , Connection communication IO that will do . For the sake of stability DS18B20 The end can be equipped with 0.1uF capacitance .
Reference resources
- DS18B20 Maximum distance https://forums.raspberrypi.com/viewtopic.php?t=36163#p1337521
- 40 rice CAT5 Network cable connection 7 individual DS18B20 https://raspberrypi.stackexchange.com/questions/41234/max-length-of-wire-w-3-3v-or-other-issue
- Parasitic power supply mode https://learn.openenergymonitor.org/electricity-monitoring/temperature/DS18B20-temperature-sensing
- Parasitic power supply mode https://e-radionica.com/en/blog/hum-how-to-use-the-ds18b20-with-parasitic-power-supply/


![Reverse analysis of Huawei housekeeper software [transfer]](/img/85/7af372808e75f8791936c59918466f.jpg)





