溫度感測器技術

客製化 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 Temperature Sensor: 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 command:
The microcontroller sends a ROM command to either read the unique 64-bit code of a specific sensor (“Match 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. Detailed explanation of DS18B20’s 1-Wire communication protocol
The reason why DS18B20 sensors are widely used is largely due to its unique communication protocol – 1-Wire communication protocol. This protocol simplifies the requirements for hardware connections and provides an efficient way to transmit data. This chapter will deeply analyze the working mechanism and data exchange process of the 1-line communication protocol to lay a solid foundation for subsequent programming practice.
2.1 Basics of 1-Wire Communication Protocol
2.1.1 Features of 1-Wire Communication Protocol:
DS18B20 1-Wire Communication Protocol is also calledsingle bus” 科技. It has the following features: – Single bus communication: Only one data line is used for bidirectional data transmission, which greatly reduces the complexity of wiring compared to the traditional multi-wire sensor communication method. – Multi-device connection: Supports connecting multiple devices on one data bus, and identifies and communicates through device identification codes. – Low power consumption: 溝通過程中, the device can be in a low-power standby state when not participating in communication. – 高精度: With a shorter data transmission time, it can reduce external interference and improve data accuracy.
2.1.2 Data format and timing analysis of 1-wire communication
The data format of the 1-wire communication protocol follows a specific timing rule. It includes initialization timing, write timing and read timing:
Initialization timing: The host first starts the presence detection timing (Presence Pulse) by pulling down the bus for a certain period of time, and the sensor then sends a presence pulse in response.
Write timing: When the host sends a write timing, it first pulls down the bus for about 1-15 微秒, then releases the bus, and the sensor pulls down the bus in 60-120 microseconds to respond.
Read timing: The host notifies the sensor to send data by pulling down the bus and releasing it, and the sensor will output the data bit on the bus after a certain delay.

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(數據 & 0x01);
數據 >>= 1;
}
}

// Write a bit to a one-wire bus
void OneWire_WriteBit(bit data) {
SetPinMode(DS18B20_PIN, OUTPUT_LOW);
如果 (數據) {
// 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; 我++) {
數據 >>= 1;
如果 (OneWire_ReadBit())
數據 |= 0x80;
}
傳回數據;
}

// 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(數據); // 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