The Dallas Temp Sensor: Sensing Principle and Digital Output
When makers and engineers refer to a 'Dallas temp sensor', they are almost always talking about the DS18B20 (originally designed by Dallas Semiconductor, now manufactured by Analog Devices/Maxim). Unlike thermistors that change resistance or the LM35 that outputs an analog voltage, the DS18B20 is a silicon bandgap temperature sensor. It measures temperature by calculating the difference in base-emitter voltage between two internal bipolar transistors operating at different current densities. This delta-V is inherently proportional to absolute temperature, allowing the onboard ASIC to digitize the reading directly.
Because of this internal architecture, the output of a Dallas temp sensor is strictly digital. It does not output a varying voltage or current. Instead, it communicates via the 1-Wire protocol, sending a discrete digital data packet containing the temperature reading, a unique 64-bit ROM serial number, and configuration registers. This means your microcontroller doesn't need an analog-to-digital converter (ADC) to read it; it just needs a single digital GPIO pin and precise microsecond timing to bit-bang the 1-Wire bus.
Wiring the DS18B20: Pinout, Pull-Ups, and Power Modes
The physical wiring of the TO-92 package is straightforward, but the 1-Wire protocol demands a specific hardware pull-up to function. The bus line is open-drain, meaning the sensor can only pull the line LOW; it relies on a pull-up resistor to bring the line HIGH.
| Pin Number | Name | Function | Notes |
|---|---|---|---|
| 1 | GND | Ground | Connect to MCU GND. |
| 2 | DQ | Data In/Out | Requires a 4.7kΩ pull-up to VDD. This is the 1-Wire bus. |
| 3 | VDD | Power Supply | Supply range: 3.0V to 5.5V DC. (See parasitic mode below). |
External Power vs. Parasitic Power Mode
You have two choices for powering the sensor:
- External Power Mode (Recommended): Connect Pin 3 to 3.3V or 5V, Pin 1 to GND, and Pin 2 to your GPIO with a 4.7kΩ pull-up to the same VDD rail. This provides the most stable readings and allows multiple sensors to share the bus without voltage sag.
- Parasitic Power Mode: Tie Pin 3 (VDD) to GND. The sensor harvests power from the DQ line via an internal capacitor when the bus is HIGH. While this saves a wire, it requires your microcontroller GPIO to source up to 1.5mA during temperature conversions, and it limits the number of sensors you can put on a single bus. Avoid this unless you are constrained to a 2-wire cable.
Output Math: Converting Raw 1-Wire Data to Celsius
Because the output is digital, there is no analog scaling or reference voltage math required. The DS18B20 defaults to a 12-bit resolution, meaning the temperature is stored as a 16-bit two's complement number where the least significant bit (LSB) represents 0.0625°C.
Here is the exact math to convert the raw register data into physical units:
- Read the 16-bit raw value: The sensor returns two bytes (LSB first, then MSB). Combine them into a single 16-bit signed integer.
- Handle Negative Temperatures: If the MSB (bit 15) is 1, the temperature is negative. In two's complement, you can simply cast the 16-bit value to a signed integer in C/C++.
- Multiply by the LSB weight: Multiply the raw decimal value by 0.0625 (or divide by 16) to get degrees Celsius.
Worked Numeric Example
Suppose your microcontroller reads the raw bytes 0x50 (LSB) and 0x05 (MSB).
- Combined hex:
0x0550 - Convert to decimal:
(5 * 256) + 80 = 1360 - Apply LSB math:
1360 * 0.0625 = 85.0°C
For a negative example, a raw reading of 0xFF90 translates to a decimal of -112 (in 16-bit signed two's complement). Multiplying -112 * 0.0625 yields -7.0°C. If you use the standard Arduino DallasTemperature library, calling sensors.getTempCByIndex(0) handles this bit-shifting automatically, but understanding the raw math is critical when debugging I2C/1-Wire logic analyzers or writing bare-metal C drivers for an ESP32.
Interference, Calibration, and Long-Run Gotchas
One of the main reasons engineers choose the Dallas temp sensor over analog alternatives is that it is factory calibrated. The sensor guarantees ±0.5°C accuracy from -10°C to +85°C. You do not need to perform user calibration, burn offsets into EEPROM, or account for ADC voltage reference drift. The digital packet is either received perfectly or it fails the onboard CRC check.
However, the 1-Wire bus is highly susceptible to specific interference sources:
- Cable Capacitance: The 4.7kΩ pull-up resistor and the parasitic capacitance of your wire form an RC low-pass filter. If you run a standard Cat5e cable longer than 20 meters, the rising edge of the 1-Wire signal becomes too slow, causing bit errors. Fix: Drop the pull-up resistor to 2.2kΩ or 1.5kΩ for long runs to charge the line faster.
- EMI and Crosstalk: Running the 1-Wire data line parallel to AC mains or PWM-driven motor wires will induce phantom voltage spikes that the sensor interprets as bus resets. Fix: Use twisted-pair cable (like standard Ethernet) and keep the bus away from high-current switching nodes.
- Phantom Powering: If you wire the sensor in External Power mode but forget to connect VDD (leaving Pin 3 floating), the sensor will attempt to draw power backward through the DQ pin's internal protection diodes. This results in erratic readings and bus lockups. Always tie unused VDD pins to GND if you intend to use parasitic mode.
Decision Tree: Which DS18B20 Variant and Config to Pick
Use this decision path to finalize your hardware and firmware configuration. Do not default to parasitic mode or lower resolutions unless your physical constraints demand it.
| If your project requires... | Then choose this configuration... |
|---|---|
| Maximum accuracy and fastest bus recovery on a standard PCB | DS18B20+ TO-92, External Power, 12-bit resolution, 4.7kΩ pull-up. |
| Liquid temperature monitoring (aquariums, brewing, pipes) | Waterproof stainless-steel probe, External Power, silicone jacketed cable. |
| High-speed data logging (multiple reads per second) | 9-bit resolution (yields 93.75ms conversion time vs 750ms at 12-bit), but accept ±0.5°C step quantization. |
| Long cable runs (>20 meters / 65 feet) | Twisted pair cable, External Power, 2.2kΩ or 1.5kΩ pull-up resistor, active 1-Wire master (like DS2480B) if exceeding 50m. |
| Only 2 wires available in the wall/conduit | Parasitic Power Mode (VDD tied to GND), strong pull-up via MOSFET during conversion phase. |
By treating the Dallas temp sensor as a digital node rather than an analog component, and respecting the RC time constants of the 1-Wire bus, you will achieve rock-solid temperature telemetry for your ESP32 or Arduino builds.






