viewof rawDecimal = Inputs.range([-2048, 2047], {
value: 464,
step: 1,
label: "Raw Value (decimal, signed 16-bit)"
})
viewof resolutionBits = Inputs.select([9, 10, 11, 12], {
value: 12,
label: "Resolution (bits)"
})
// DS18B20 always divides by 16 regardless of resolution.
// Lower resolutions leave the least-significant bits undefined.
undefinedBits = 12 - resolutionBits
stepSizeC = Math.pow(2, undefinedBits) / 16
tempFromRaw = rawDecimal / 16
rawHex = rawDecimal >= 0 ? "0x" + rawDecimal.toString(16).toUpperCase().padStart(4, '0') : "0x" + ((rawDecimal + 65536) >>> 0).toString(16).toUpperCase().padStart(4, '0')
conversionTime = resolutionBits === 9 ? 93.75 : resolutionBits === 10 ? 187.5 : resolutionBits === 11 ? 375 : 750
isErrorValue = rawDecimal === 1360
isCrcError = rawDecimal <= -2032
html`<div style="background: var(--bs-light, #f8f9fa); padding: 15px; border-radius: 8px; border-left: 4px solid #16A085; margin-top: 10px;">
<h4 style="margin-top: 0; color: #2C3E50;">DS18B20 Raw-to-Temperature Converter</h4>
<p style="font-size: 14px; line-height: 1.8; margin: 8px 0;">
<strong>Raw hex:</strong> ${rawHex}
<br><strong>Temperature:</strong> ${tempFromRaw.toFixed(4)}°C
<br><strong>Resolution step:</strong> ${stepSizeC.toFixed(4)}°C (${resolutionBits}-bit mode; ${undefinedBits} LSB${undefinedBits > 1 ? 's' : ''} undefined)
<br><strong>Conversion time:</strong> ${conversionTime} ms
${isErrorValue ? '<br><span style="color: #E74C3C; font-weight: bold;">Warning: This is the power-on reset value (85°C). The sensor may not have completed conversion yet.</span>' : ''}
${isCrcError ? '<br><span style="color: #E74C3C; font-weight: bold;">Warning: This value is at or below -127°C, which typically indicates a CRC error or disconnected sensor.</span>' : ''}
</p>
<p style="font-size: 13px; color: #7F8C8D; margin: 8px 0; font-style: italic;">
Formula: T = raw_value / 16 = ${rawDecimal} / 16 = ${tempFromRaw.toFixed(4)}°C
</p>
</div>`DS18B20 Raw Value Converter
DS18B20 Raw Value Converter
animation
sensors
temperature
Try Keep the decimal raw reading (signed 16-bit) at 464 and change Resolution (bits) from 12 to 9.
Observe The opening value is 0x01D0, or 29.0000°C, with a 0.0625°C step and 750 ms conversion time. Lowering Resolution (bits) changes the step and time, not the decoded temperature.
Explain The raw reading is always divided by 16; Resolution (bits) determines the undefined low bits and the listed conversion time.
Technical boundaries. The converter assumes the entered integer is already signed and restricts it to -2048 through 2047 despite the 16-bit label. Lower-resolution undefined bits are reported but not masked, and warnings use fixed raw-value thresholds.
Interactive: DS18B20 Raw Value Converter
Convert a raw DS18B20 value and compare the result with the sensor resolution.
Tip
Use this calculator to convert DS18B20 raw register values to temperature, or enter a temperature to see its raw encoding.