Unit D - Sensors & Buses

20. Thermistors, LDRs & Calibration

Convert resistance changes into calibrated measurements.

Estimated time 5 hours

Learning outcomes

  • Explain NTC and LDR behavior
  • Calculate divider resistance
  • Convert an NTC reading to temperature
  • Calibrate thresholds with hysteresis

Parts and preparation

Uno, 10 k ohm NTC thermistor, 10 k ohm resistor, LDR, LEDs and breadboard.

Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.

Thermistors, LDRs & Calibration instructional connection diagram
Open the diagram for a larger view. Trace every connection before building.

Resistive sensors

An NTC thermistors resistance falls as temperature rises. An LDRs resistance usually falls as light rises. Arduino measures their divider voltage, not resistance directly.

Divider calculation

With sensor to 5 V and fixed resistor to GND: Rsensor = Rfixed * (1023.0 / ADC - 1.0). Swapping positions changes the formula and direction.

Beta equation

For an NTC: 1/T = 1/T0 + ln(R/R0)/B, using kelvin. R0 is specified at T0 (often 10 k ohm at 25 C) and B comes from the datasheet.

Calibration and hysteresis

Real sensors and tolerances vary. Record readings at known conditions. Use separate ON and OFF thresholds to prevent rapid output chatter.

Your own library

Once the maths works in a sketch, package it as a reusable library with a .h header and .cpp source file in Documents/Arduino/libraries/. See the course extension: How to create a SimpleThermistor library.

Wiring and safe build sequence

Breadboard wiring for lesson 20: Thermistors, LDRs & Calibration
Breadboard layout for this lesson. Match colours and pins before powering the circuit. Click the image for a larger view.
  1. 5 V -> NTC -> A0 junction -> 10 k ohm -> GND
  2. Use a separate similar divider on A1 for the LDR
  3. Drive any fan through the MOSFET circuit from lesson 12
Power rule: switch off before moving wires. Arduino I/O pins are control signals; high-current loads require a driver and suitable external supply.
#include <math.h>

const float seriesR = 10000.0;
const float nominalR = 10000.0;
const float nominalK = 25.0 + 273.15;
const float beta = 3950.0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int raw = analogRead(A0);
  if (raw <= 0 || raw >= 1023) {
    Serial.println("Divider fault");
    delay(500);
    return;
  }
  float resistance = seriesR * (1023.0 / raw - 1.0);
  float invT = 1.0 / nominalK + log(resistance / nominalR) / beta;
  float celsius = 1.0 / invT - 273.15;
  Serial.print(celsius, 1);
  Serial.println(" C");
  delay(500);
}

How the code works

  1. The formula assumes the shown sensor/fixed-resistor order.
  2. Boundary checks avoid division by zero and identify open/short wiring.
  3. Use datasheet R0 and beta values for the actual thermistor.

Test and record evidence

Expected result: Temperature changes smoothly when the thermistor is warmed gently; open/short faults are reported.

Practical evidence checklist

Common faults and checks
  • If temperature moves backwards or is unrealistic, check divider order and constants.
  • Do not heat a thermistor with a flame or high-power source.
Extension challenge: Follow the course library example and package this maths as SimpleThermistor (.h + .cpp), then use it from a short test sketch.

Check your understanding

Q1. Why use a voltage divider?

Show answer

The ADC measures voltage, while the sensor changes resistance.

Q2. What is hysteresis?

Show answer

Different switch-on and switch-off thresholds that prevent chatter.