viewof rawLow = Inputs.range([0, 4095], {
value: 512,
step: 1,
label: "Raw ADC at low reference point"
})
viewof rawHigh = Inputs.range([0, 4095], {
value: 3584,
step: 1,
label: "Raw ADC at high reference point"
})
viewof actualLow = Inputs.range([-100, 200], {
value: 0,
step: 0.1,
label: "Actual value at low point"
})
viewof actualHigh = Inputs.range([-100, 200], {
value: 100,
step: 0.1,
label: "Actual value at high point"
})
viewof testRaw = Inputs.range([0, 4095], {
value: 2048,
step: 1,
label: "Test raw ADC reading"
})
slope = (rawHigh - rawLow) !== 0
? (actualHigh - actualLow) / (rawHigh - rawLow)
: 0
calibratedValue = slope !== 0
? actualLow + slope * (testRaw - rawLow)
: 0
html`<div style="background: var(--bs-light, #f8f9fa); padding: 20px; border-radius: 8px; border-left: 4px solid #E67E22; margin-top: 15px; font-family: Arial, sans-serif;">
<h4 style="color: #2C3E50; margin-top: 0;">Calibration Results</h4>
<table style="width: 100%; border-collapse: collapse; margin-top: 10px;">
<tr style="background: #fef5ec;">
<td style="padding: 10px; border-bottom: 1px solid #f5e5d3; font-weight: bold; color: #2C3E50;">Calibration Slope (m)</td>
<td style="padding: 10px; border-bottom: 1px solid #f5e5d3; color: #2C3E50;">${slope.toFixed(6)}</td>
</tr>
<tr>
<td style="padding: 10px; border-bottom: 1px solid #f5e5d3; font-weight: bold; color: #2C3E50;">Test Raw Reading</td>
<td style="padding: 10px; border-bottom: 1px solid #f5e5d3; color: #2C3E50;">${testRaw}</td>
</tr>
<tr style="background: #fef5ec;">
<td style="padding: 10px; font-weight: bold; color: #2C3E50;">Calibrated Value</td>
<td style="padding: 10px; color: #E67E22; font-weight: bold; font-size: 18px;">${slope !== 0 ? calibratedValue.toFixed(2) : "N/A"}</td>
</tr>
</table>
<p style="margin-top: 15px; color: #555; font-size: 14px; font-style: italic;">
Formula: Calibrated = actualLow + slope × (raw - rawLow), where slope = (actualHigh - actualLow) / (rawHigh - rawLow)
</p>
${(rawHigh - rawLow) === 0 ? `<p style="color: #E74C3C; font-weight: bold; margin-top: 10px;">Error: rawHigh must differ from rawLow to calculate slope!</p>` : ''}
</div>`Two-Point Calibration Calculator
Two-Point Calibration Calculator
animation
sensors
calibration
Try Keep Raw ADC at low reference point at 512 and Raw ADC at high reference point at 3584, then move Test raw ADC reading from 2048.
Observe With actual reference values of 0 and 100, the initial slope is 0.032552 and the calibrated value is 50.00.
Explain The reference span of 100 divided by the raw span from 512 to 3584 gives slope; multiplying that slope by the test reading above 512 gives the calibrated result.
Technical boundaries. The conversion assumes a straight line through the two reference pairs and permits extrapolation beyond them. Equal raw reference points force slope to zero and show an error; any zero slope also makes the calibrated output N/A.
Try It: Two-Point Calibration Calculator