温度传感器技术

定制 DS18B20 传感器探头 & 1-电线电缆组件

DS18B20温度传感器1线防水电缆 + 转接板组

We offer a wide range of the best 1-Wire DS18B20 sensor connectors, including Nanoflex, DisplayPort, USB, Solar, SATA, HDMI, ATA IDE, SAS & many more. All cables are manufactured to the highest industry standards. Using Sensor Circuit Assembly for box builds allows you to focus on your design and marketing, reduce costs, and reap the benefits of our assembly lines, QA processes, and manufacturing expertise.

DS18B20 传感器使用以下方式进行通信 “1-金属丝” 协议, 这意味着它使用一条数据线与微控制器进行所有通信, 允许多个传感器连接在同一条线上并通过其唯一的 64 位串行代码进行识别; 该单条数据线通过电阻器拉高,传感器通过在特定时隙期间拉低线来发送信息位来传输数据.

DS18B20温度传感器: The DS18B20 waterproof probe is designed for underwater use, capable of operating in wet or moist environments without being damaged by water or moisture.
Temperature sensor supply voltage: 3.0V ~ 5.25V;
工作温度范围:-55 ℃ 至 +125 ℃ (-67 ℉ to +257 );
Provides from 9-bit to 12-bit Celsius temperature measurements;
Adapter module is equipped with a pull-up resistor, and directly connects to the GPIO of the Raspberry Pi without an external resistor;
Use this adapter module kit to simplify connecting the waterproof temperature sensor to your project.

DS18B20数字温度传感器探头 & XH2.54 to PH2.0 module

DS18B20数字温度传感器探头 & XH2.54 to PH2.0 module

China-made DS18B20 chip temperature acquisition TO-92 temperature sensor

China-made DS18B20 chip temperature acquisition TO-92 temperature sensor

DS18B20温度传感器1线防水电缆 + 转接板组

DS18B20温度传感器1线防水电缆 + 转接板组

1. Key points about the 1-Wire protocol:
Single data line:
Only one wire is needed for communication between the sensor and the microcontroller.
Half-duplex communication:
Data can be sent in both directions, but only one direction at a time.
Parasite power:
The DS18B20 can be powered directly from the data line during communication, eliminating the need for a separate power supply in some cases.
Unique device addresses:
Each DS18B20 sensor has a unique 64-bit serial code that allows the microcontroller to identify and address individual sensors on the bus.
Communication steps with a DS18B20:
1.1 Reset pulse:
The microcontroller initiates communication by pulling the data line low for a specific duration (复位脉冲).
1.2 Presence pulse:
If a DS18B20 is present on the bus, it will respond with a short pulse, indicating its presence.
1.3 ROM命令:
The microcontroller sends a ROM command to either read the unique 64-bit code of a specific sensor (“匹配ROM”) or to address all sensors on the bus (“跳过ROM”).
1.4 Function command:
Depending on the desired operation (like reading temperature), the microcontroller sends a specific function command to the sensor.
1.5 Data transfer:
Data is transmitted bit-by-bit, with the sensor pulling the data line low to send a ‘0’ and letting the line go high to send a ‘1’.

2. DS18B20的1-Wire通信协议详解
DS18B20传感器之所以被广泛应用,很大程度上得益于其独特的通信协议 – 1-有线通讯协议. 该协议简化了对硬件连接的要求,提供了一种有效的数据传输方式. 本章将深入剖析1线通信协议的工作机制和数据交换过程,为后续的编程实践打下坚实的基础.
2.1 1-Wire 通信协议基础知识
2.1.1 1-Wire 通信协议的特性:
DS18B20 1-Wire 通信协议也称为 “单总线” 技术. 它具有以下特点: – 单总线通讯: 仅使用一根数据线进行双向数据传输, 与传统的多线传感器通信方式相比,大大降低了布线的复杂性. – 多设备连接: 支持在一根数据总线上连接多个设备, 并通过设备识别码进行识别和通信. – 低功耗: 沟通过程中, 设备在不参与通信时可以处于低功耗待机状态. – 高精度: 数据传输时间更短, 减少外界干扰,提高数据准确性.
2.1.2 1-wire通信的数据格式和时序分析
1-wire通信协议的数据格式遵循特定的时序规则. 它包括初始化时序, 写时序和读时序:
初始化时序: 主机首先启动存在检测计时 (存在脉冲) 通过将总线拉下来一段时间, 然后传感器发送存在脉冲作为响应.
写入时序: 当主机发送写时序时, 它首先将总线拉下来大约 1-15 微秒, 然后释放总线, 并且传感器拉低总线 60-120 微秒响应.
读取时序: 主机通过拉低总线并释放来通知传感器发送数据, 传感器会在一定的延迟后将数据位输出到总线上.

Analog Devices DS18B20+, MAXIM Programmable Resolution 1-Wire Digital Thermometer

Analog Devices DS18B20+, MAXIM Programmable Resolution 1-Wire Digital Thermometer

DS18B20 12-bit 1-Wire Digital Temperature Sensor w/ 1 Meter Cable

DS18B20 12-bit 1-Wire Digital Temperature Sensor w/ 1 Meter Cable

DS18B20 sensor probe dedicated to temperature and humidity collection in cold chain cold storage

DS18B20 sensor probe dedicated to temperature and humidity collection in cold chain cold storage

2.2 Software implementation of data communication
2.2.1 Initialization and reset of 1-line communication
At the software level, initialization and reset of 1-Wire communication is the first step of communication. The following is the pseudo code to implement this process:

// OneWire communication initialization function
void OneWire_Init() {
// Set the bus to input mode and enable the pull-up resistor
SetPinMode(DS18B20_PIN, INPUT_PULLUP);
// Wait for the bus to be idle
DelayMicroseconds(1);
// Send a reset pulse
OneWire_Reset();
}

// OneWire communication reset function
void OneWire_Reset() {
// Pull down the bus
SetPinMode(DS18B20_PIN, OUTPUT_LOW);
DelayMicroseconds(480);
// Release the bus
SetPinMode(DS18B20_PIN, INPUT_PULLUP);
DelayMicroseconds(70);
// Wait for the presence of a pulse
如果 (!WaitForOneWirePresence())
// No pulse was detected, maybe the sensor is not connected or the initialization failed
HandleError();
DelayMicroseconds(410);
}

// Waiting for the presence of a pulse
bool WaitForOneWirePresence() {
return ReadPin(DS18B20_PIN) == 0; // Assume low level is a signal presence
}

2.2.2 Data reading and writing operations

Data reading and writing operations are the core part of sensor communication. The following code shows how to write a byte to a one-wire bus:
// Write a byte to a one-wire bus
void OneWire_WriteByte(byte data) {
为了 (int i = 0; 我 < 8; 我++) {
OneWire_WriteBit(data & 0x01);
data >>= 1;
}
}

// Write a bit to a one-wire bus
void OneWire_WriteBit(bit data) {
SetPinMode(DS18B20_PIN, OUTPUT_LOW);
如果 (data) {
// Release the bus when writing 1
SetPinMode(DS18B20_PIN, INPUT_PULLUP);
DelayMicroseconds(1);
} 别的 {
// Continue to pull the bus low when writing 0
DelayMicroseconds(60);
}
SetPinMode(DS18B20_PIN, INPUT_PULLUP);
DelayMicroseconds(1);
}

Next is the function to read a byte:
// Read a byte from the one-wire bus
byte OneWire_ReadByte() {
byte data = 0;
为了 (int i = 0; 我 < 8; 我++) {
data >>= 1;
如果 (OneWire_ReadBit())
data |= 0x80;
}
return data;
}

// Read a bit from the one-wire bus
bit OneWire_ReadBit() {
SetPinMode(DS18B20_PIN, OUTPUT_LOW);
SetPinMode(DS18B20_PIN, INPUT_PULLUP);
DelayMicroseconds(3);
bool result = ReadPin(DS18B20_PIN);
DelayMicroseconds(57);
return result;
}

2.2.3 Verification mechanism of OneWire communication

The OneWire communication protocol uses a simple verification mechanism in the data exchange process, usually by reading back the written data to verify the correctness of the data. The following is a sample code for verifying the written data:

byte data = 0x55; // Assume that the data to be sent

OneWire_WriteByte(data); // Write data to the OneWire bus

byte readData = OneWire_ReadByte(); // Read back data from the OneWire bus

如果 (readData != data) {
HandleError(); // If the read-back data does not match the written data, handle the error