OC
OceanRemote
Low-code IoT platform
← Back to Tutorials
← Previous Next →

Tutorial 20: Calibrating Temperature Sensors with Offset

📖 What You'll Learn in This Tutorial:
  • ✓ Why temperature sensors need calibration (even digital ones)
  • ✓ How OceanRemote's calibration offset feature works
  • ✓ Step-by-step calibration using ice water and boiling water
  • ✓ Using a reference thermometer for single-point calibration
  • ✓ Understanding the difference between raw and calibrated readings
  • ✓ How offset values persist across device reboots

Why Calibrate Temperature Sensors?

Even high-quality temperature sensors have manufacturing tolerances. The DHT22 and DS18B20 claim ±0.5°C accuracy, but individual sensors can be off by more. NTC thermistors can be off by ±2°C or more without calibration.

📊 Typical Sensor Accuracy Without Calibration:
Sensor Type Specified Accuracy Typical Real-World Error
DS18B20数字 ±0.5°C ±0.3°C to ±0.8°C
DHT22 ±0.5°C ±0.5°C to ±1.0°C
NTC Thermistor (uncalibrated) ±1% to ±5% of resistance ±1°C to ±3°C
NTC Thermistor (calibrated) ±0.2°C to ±0.5°C
💡 Why Calibration Matters:

If your greenhouse temperature reads 25°C but is actually 26°C, that 1°C difference might not matter. But for a refrigerator (4°C vs 5°C), aquarium (24°C vs 26°C), or fermentation (18°C vs 20°C), that error is critical. Calibration fixes this!

How OceanRemote's Calibration Works

OceanRemote uses a simple but effective offset calibration method:

Calibrated Temperature = Raw Sensor Reading + Offset

Where:
- Raw Sensor Reading = The actual temperature from DHT22, DS18B20, or NTC
- Offset = Your calibration value (positive or negative decimal number)
- Calibrated Temperature = What displays in your dashboard

Where to Find the Offset Field

In your OceanRemote dashboard, each device with a temperature sensor has a temperature card:

┌─────────────────────────────────────┐
│  🌡️ CALIBRATED TEMPERATURE         │
│                                     │
│          23.5 °C                    │
│                                     │
│  [ -0.5 ]  Calibration Offset (±°C) │
└─────────────────────────────────────┘
  • The large number is your calibrated temperature (raw + offset)
  • The input field lets you enter or change the offset value
  • Changes are saved immediately to the server
  • The offset persists even after device reboot
🔧 Technical Note:

Offset calibration is applied on the server side, not in the device firmware. This means:

  • You don't need to re-flash your device to change calibration
  • The raw sensor value is still stored in the database
  • You can change offset anytime from any device (phone, computer, tablet)
  • Different users can have different offsets? No - offset is per device, shared by all account users

Method 1: Ice Water Calibration (0°C Reference)

This is the most accurate method because 0°C is easy to create reliably.

What You Need:

  • Crushed ice (not large cubes - more surface area)
  • Distilled water (tap water works but distilled is more accurate)
  • Insulated container (thermos or foam cup)
  • Your NTC, DS18B20, or DHT22 sensor
  • Stirring utensil

Step-by-Step Procedure:

  1. Fill container with crushed ice: About 75% ice, 25% water. Don't use too much water.
  2. Add cold water: Just enough to fill gaps between ice pieces.
  3. Wait 5 minutes: Let the mixture reach thermal equilibrium (0°C exactly).
  4. Stir constantly: Ice water can have temperature gradients. Stirring ensures uniform 0°C.
  5. Submerge your sensor: Make sure the sensing element is fully in the ice/water mixture, not touching the container walls.
  6. Wait 2-3 minutes: Let the sensor stabilize to the ice water temperature.
  7. Read the raw temperature: Look at your OceanRemote dashboard or Serial Monitor.
  8. Calculate offset: Offset = 0°C - Raw Reading
  9. Enter offset: Type the value in the Calibration Offset field.
Example Ice Water Calibration:

Raw reading from dashboard: 0.8°C
Target temperature: 0°C

Offset = 0 - 0.8 = -0.8

Enter -0.8 in the calibration field.
Result: Calibrated = 0.8 + (-0.8) = 0.0°C ✓
⚠️ Critical Ice Water Tips:
  • Use crushed ice, not cubes: Cubes have less surface area and create uneven temperature.
  • Don't use salt: Salt lowers the freezing point below 0°C.
  • Keep stirring: Without stirring, the water near the sensor can warm above 0°C.
  • Avoid touching container walls: Plastic/glass containers aren't at 0°C on the inside surface.
  • Wait for stabilization: The sensor needs time to cool down from room temperature.

Method 2: Boiling Water Calibration (100°C Reference)

Boiling water is exactly 100°C at sea level. At higher altitudes, it's lower - so this method requires altitude adjustment.

Boiling Point by Altitude:

Altitude Boiling Point (°C) Example Location
Sea Level (0m) 100.0°C New York, London, Tokyo
500m (1,640 ft) 98.3°C Denver (1,600m - see below)
1,000m (3,280 ft) 96.7°C Albuquerque
1,500m (4,920 ft) 95.0°C Calgary
2,000m (6,560 ft) 93.3°C Mexico City
3,000m (9,840 ft) 90.0°C La Paz, Bolivia

Step-by-Step Procedure:

  1. Boil distilled water: Use a clean pot, avoid tap water minerals.
  2. Maintain a rolling boil: Gentle bubbles aren't enough - needs vigorous boiling.
  3. Submerge your sensor: Waterproof DS18B20 is ideal. DHT22 and bare NTC may be damaged! Check sensor specs.
  4. Wait 2-3 minutes: Let sensor stabilize.
  5. Read raw temperature: Look at your dashboard.
  6. Calculate offset: Offset = Boiling Point at your altitude - Raw Reading
  7. Enter offset: Type the value in the calibration field.
Example Boiling Water Calibration (Sea Level):

Raw reading from dashboard: 99.2°C
Target temperature (sea level): 100.0°C

Offset = 100.0 - 99.2 = +0.8

Enter +0.8 in the calibration field.
Result: Calibrated = 99.2 + 0.8 = 100.0°C ✓
⚠️ Safety Warning:

Boiling water is dangerous! Use caution. Only submerge waterproof sensors (encapsulated DS18B20). DHT22 and bare NTC sensors are NOT waterproof and will be destroyed in boiling water.

Method 3: Reference Thermometer Calibration

This is the easiest method if you have a known-accurate thermometer.

What You Need:

  • A known-accurate reference thermometer (certified digital thermometer or medical-grade)
  • Stable temperature environment (room temperature works fine)

Step-by-Step Procedure:

  1. Place sensors together: Put your reference thermometer right next to your OceanRemote sensor.
  2. Wait 10-15 minutes: Let both sensors stabilize to the same temperature.
  3. Read both temperatures: Note your reference value and the raw OceanRemote reading.
  4. Calculate offset: Offset = Reference Temperature - Raw Reading
  5. Enter offset: Type the value in the calibration field.
Example Reference Thermometer Calibration:

Reference thermometer: 22.3°C
OceanRemote raw reading: 22.8°C

Offset = 22.3 - 22.8 = -0.5

Enter -0.5 in the calibration field.
Result: Calibrated = 22.8 + (-0.5) = 22.3°C ✓
💡 Which Reference Thermometer to Use?
  • Best: Certified lab thermometer (accuracy ±0.1°C)
  • Good: Medical fever thermometer (accuracy ±0.2°C)
  • Acceptable: High-quality digital kitchen thermometer (accuracy ±0.5°C)
  • Avoid: Cheap analog dial thermometers, IR gun thermometers (surface temp only)

Method 4: Two-Point Calibration (Most Accurate)

For critical applications, use both ice water (0°C) and boiling water (100°C) to calibrate. This corrects for both offset and gain errors.

When to Use Two-Point Calibration:

  • NTC thermistors (non-linear response benefits from two-point calibration)
  • When you need accuracy better than ±0.3°C across a wide range
  • Scientific or medical applications

Step-by-Step Procedure:

  1. Calibrate at 0°C: Use ice water method. Note the raw reading.
  2. Calculate offset at 0°C: Offset_0 = 0 - Raw_0
  3. Calibrate at 100°C (or boiling point): Use boiling water method. Note the raw reading.
  4. Calculate offset at 100°C: Offset_100 = Boiling Point - Raw_100
  5. Choose an average offset: For most sensors, use the average: Offset = (Offset_0 + Offset_100) / 2
  6. For NTC with Beta parameter: You can calculate actual Beta using two known points (advanced).
Example Two-Point Calibration (NTC):

Ice water raw reading: 0.8°C → Offset at 0°C = -0.8
Boiling water raw reading (sea level): 99.2°C → Offset at 100°C = +0.8

Average offset = (-0.8 + 0.8) / 2 = 0.0

Result: The NTC reads 0.8°C too high at 0°C but 0.8°C too low at 100°C.
This suggests a gain error, not just offset. Consider adjusting Beta instead.

Using the Dashboard Offset Field

How to Enter an Offset:

  1. Log in to your OceanRemote dashboard
  2. Find your device's temperature card
  3. Locate the "Calibration Offset (±°C)" input field
  4. Type your offset value (e.g., -0.5 or +1.2)
  5. Press Enter or click outside the field
  6. The calibrated temperature updates immediately
Offset Examples:

Raw Reading: 23.5°C
- If actual is 24.0°C → Offset = +0.5 → Calibrated = 24.0°C
- If actual is 23.0°C → Offset = -0.5 → Calibrated = 23.0°C
- If actual is 22.5°C → Offset = -1.0 → Calibrated = 22.5°C

Range: -100°C to +100°C (you won't need more than ±10°C)
🔧 How Offset Persists:

When you save an offset, OceanRemote stores it in the database. Every time you view the dashboard, the server applies your offset to the latest raw reading. This works even if:

  • Your device reboots
  • You power cycle your board
  • You regenerate firmware
  • You log in from a different computer

The offset is tied to the device, not your browser session.

Raw vs Calibrated: What's Stored?

OceanRemote stores both raw and calibrated values:

Value Where It's Used Notes
Raw Temperature Device details section, database Unmodified sensor reading, shown as "Raw Temp"
Calibrated Temperature Temperature card, API responses Raw + Offset, what most users see
Temperature Offset Dashboard input, database Your calibration value, per-device
API Response Example (from /api/debug-data/):

{
  "temperature": 23.5,      // Raw temperature from sensor
  "calibrated_temperature": 23.0,  // Raw + Offset
  "temperature_offset": -0.5       // Your calibration value
}

Calibration by Sensor Type

DS18B20 Calibration

DS18B20 sensors are factory-calibrated to ±0.5°C. Most need little or no offset (±0.3°C typical). Use ice water method if accuracy matters.

DHT22 Calibration

DHT22 sensors have ±0.5°C specified accuracy but can vary more. They also suffer from self-heating if read too frequently (OceanRemote respects the 2-second limit).

NTC Thermistor Calibration

NTCs need the most calibration. Use two-point calibration (ice water + boiling water) for best results. The dashboard offset works, but adjusting the Beta parameter in firmware generation is more accurate for wide ranges.

💡 NTC Beta vs Offset:

For NTC thermistors:

  • Offset calibration works well for narrow temperature ranges (±10°C from calibration point)
  • Adjusting Beta in firmware generation is better for wide temperature ranges (-20°C to 80°C)
  • If your NTC reads high at low temps and low at high temps, adjust Beta, not offset

Troubleshooting Calibration

Problem: Calibrated temperature doesn't change after entering offset

  • Solution: Refresh the page. The offset saves immediately but the display may need a refresh.
  • Solution: Check browser console for errors. Your offset might be invalid (letters, too large).
  • Solution: Wait for the next auto-refresh (5 seconds). The dashboard updates automatically.

Problem: Offset resets after page reload

  • Solution: Your browser might have cached an old version. Hard refresh (Ctrl+Shift+R).
  • Solution: Check that you're logged in with the correct account.
  • Solution: The offset is per-device. Make sure you're editing the correct device.

Problem: Different temperatures at different times of day

  • Explanation: Single-point offset works best near the calibration temperature. For wide ranges, use two-point calibration or adjust Beta (NTC).
  • Solution: Calibrate at the temperature you care about most. If monitoring a refrigerator at 4°C, calibrate at 4°C, not room temperature.

Problem: Raw temperature jumps around

  • Solution: This isn't a calibration issue. Check your wiring, add a capacitor (0.1μF) between ADC and GND, or use averaging (OceanRemote already averages 5 samples).
⚠️ Common Mistake:

Many users forget to stir ice water during calibration. Without stirring, the water near the sensor can be several degrees above 0°C. Always stir continuously for accurate 0°C reference.

Calibration Best Practices

  • Calibrate at your target temperature: If monitoring a refrigerator at 4°C, calibrate at 4°C (using a reference thermometer), not at 0°C or 25°C.
  • Allow stabilization time: Sensors need 2-5 minutes to reach thermal equilibrium. Don't rush.
  • Use multiple points for NTC: NTCs are non-linear. Single-point offset works best within ±10°C of calibration point.
  • Document your offset: Keep a record of calibration dates and offsets. Sensors drift over years.
  • Re-calibrate annually: Sensors can drift, especially in harsh environments.
  • Use the same units: All OceanRemote temperatures are in Celsius. Convert Fahrenheit references before calculating offset.
📊 Quick Reference: Fahrenheit to Celsius Conversion
Celsius = (Fahrenheit - 32) × 5/9
Fahrenheit = (Celsius × 9/5) + 32

Examples:
32°F = 0°C
68°F = 20°C
77°F = 25°C
98.6°F = 37°C (body temperature)
212°F = 100°C

Next Steps

Now that you've calibrated your temperature sensor, continue with:

  • Tutorial 21: Connecting Relays to Your Board
  • Tutorial 22: Understanding Positive vs Negative Relay Logic
  • Tutorial 23: Customizing Relay Names and Logic
  • Return to Dashboard: Monitor your calibrated temperatures
🎯 Summary:

Calibration corrects sensor inaccuracies using a simple offset: Calibrated = Raw + Offset. Use ice water (0°C) for the most accurate reference, a reference thermometer for convenience, or boiling water (adjust for altitude). Offsets are saved per-device and persist across reboots. For NTC thermistors, consider two-point calibration or Beta adjustment for wide temperature ranges.