Build and calibrate a thermometer

Arduino, a thermistor and four water baths

Physics · 3A · Lab 1
Client brief

You are the engineering team

  • A logistics company needs cheap temperature loggers for food shipments.
  • Its thermistors arrived with no calibration data.
  • Requirement: within 1 °C of a reference thermometer, from 0 °C to about 45 °C.
  • You deliver a working thermometer, a calibration record, and an honest statement of how far it can be trusted.
Before we start

What temperature is 524?

The Arduino returns a number from 0 to 1023. It has no unit.

  • about 5 °C
  • about 25 °C
  • about 50 °C
  • no way to tell yet
Plan

The 100 minutes

  • 10 min · introduction
  • 15 min · wiring
  • 10 min · first reading
  • 30 min · four calibration baths
  • 10 min · test bath
  • 25 min · report and discussion
Safety

Three rules

  • Hot water comes only from the teacher's thermos, and only the teacher pours it.
  • The sensor bag never goes into water hotter than 50 °C.
  • Arduino, breadboard and laptop stay on the far side of the desk. If water reaches them, unplug the USB cable first.
Part 1 · Wiring

What each group needs

  • Arduino Uno, USB cable, one laptop
  • breadboard and five male-to-male jumpers
  • the thermistor: a small black bead with two legs
  • one 10 kΩ resistor: brown, black, orange, gold
  • freezer bag, paper tape or rubber band, a piece of eraser or card
  • a digital reference thermometer, shared
  • tupperware, two cups, ice, tap water, spoon
  • millimetre graph paper, pen, ruler
Part 1 · Wiring

The circuit in one picture

  • The thermistor and the resistor sit in series between 5 V and ground.
  • The A0 pin reads the voltage at the point between them.
  • Warmer thermistor: its resistance falls, and the number goes up.
Part 1 · Wiring

The breadboard

  • Holes a to e of one row are connected.
  • Different rows are not connected.
  • Use rows 10, 20 and 25 only, holes a to e. Ignore f to j and the + and − rails.
Part 1 · Wiring · steps 1 and 2

Unplug, then extend the thermistor

  • Unplug the USB cable.
  • Wind each thermistor leg 3 or 4 turns around the metal pin of a jumper.
  • Keep the two joints at least 2 cm apart, with a piece of eraser or card between them, held by tape.
  • The bare legs must not touch each other.
Part 1 · Wiring · step 3

The resistor

  • 10 kΩ: brown, black, orange, gold.
  • One leg in c20.
  • The other leg in c25.
Part 1 · Wiring · steps 4 and 5

The thermistor wires

  • First thermistor wire into b10.
  • Second thermistor wire into a20.
Part 1 · Wiring · steps 6 and 7

5V and A0

  • Jumper from the 5V pin to a10.
  • Jumper from the A0 pin to b20.
Part 1 · Wiring · step 8

Ground

  • Jumper from a GND pin to a25.
  • Do not plug in the USB cable yet.
Part 1 · Wiring · step 9

Check the rows before plugging in

Look at your own breadboard. How many things sit in row 20?

  1. Two things
  2. Three things
  3. Four things
Three: thermistor wire 2 (a20), the A0 jumper (b20) and one resistor leg (c20). Row 10 holds two things and row 25 holds two.
Part 1 · Wiring

Put the thermistor in its bag

  • Bead in a bottom corner, both joints inside the bag.
  • Press the bag flat around the bead and squeeze the air out.
  • Wires leave through the top, closed with tape or a rubber band.
  • Only the bottom 3 cm goes into water. The opening stays dry.
Part 2 · First reading

Upload the sketch

  • Open the Arduino IDE, plug in the USB cable.
  • Tools, Board, Arduino Uno.
  • Tools, Port: the one marked Arduino Uno.
  • File, New Sketch: paste the code.
  • Click Upload, wait for Done uploading.
// raw reading on A0
void setup() {
  Serial.begin(9600);
}

void loop() {
  int raw = analogRead(A0);
  Serial.println(raw);
  delay(1000);
}
Part 2 · First reading

Open the Serial Monitor

  • Magnifier icon at the top right, 9600 baud at the bottom right.
  • In room air the number sits roughly halfway, around 500.
  • Pinch the bead through the bag: the number should rise slowly.
Part 2 · First reading

If it does not work

The reading is stuck near 1023. Which side of the circuit is open?

  1. the 5V side: a10, b10, the thermistor joints
  2. the ground side: c25, a25
  3. the A0 jumper
With the ground side open, A0 is pulled up to 5 V through the thermistor and reads 1023. Stuck near 0: the 5V side is open. Jumping about with no pattern: the A0 jumper is not in b20.
Part 3 · Calibration

Four baths, cold to hot

  • Bath 1 · ice cubes floating in cold water: 0 °C. Stir before measuring.
  • Bath 2 · cold tap water.
  • Bath 3 · room temperature.
  • Bath 4 · hot water from the teacher, diluted until the reference reads 40 to 50 °C.

Each bath at least 5 °C from the one before.

Part 3 · Calibration

In every bath

1
Bag and reference probe side by side, tips at the same depth.
2
Stir gently. Wait until N stays within about 3 counts for 30 seconds.
One to two minutes, sometimes more
3
Read the reference: T before.
4
Record five consecutive readings of N.
5
Read the reference again: T after.
Part 4 · Test bath

Does your thermometer work?

  • Prepare one more bath, at least 3 °C from all four calibration baths.
  • One person reads the reference and keeps the value secret.
  • Record five readings of N in this bath, as in every other bath, and take the mean: this mean is N in the equation below.
  • Quick equation from the ice bath and the hot bath, using the mean N and mean T already recorded for each:
m=\dfrac{N_{hot}-N_{ice}}{T_{hot}-T_{ice}}\qquad T=T_{ice}+\dfrac{N-N_{ice}}{m}

Announce T. Then read out the reference. Difference = T calculated − T reference, with its sign.

Lab report

The report, in order

  1. Question
  2. Prediction
  3. Variables
  4. Instruments
  5. Method
  6. Results
  7. Graph
  8. Gradient and equation
  9. Test bath
  10. Sensitivity and errors
  11. Conclusion
Lab report · Variables

What you change, what you measure

  • Independent: the reference temperature. You choose the bath.
  • Dependent: N, the sensor's response.
  • Controlled: same sensor, bag, wiring, depth, stirring, waiting time, same reference thermometer.
At the end you use the response backwards
T=\dfrac{N-N_0}{m}
Lab report · Results

What to record

  • The resolution and reading uncertainty of each instrument — worked out on the vademecum slides just ahead.
  • T before and T after, for every bath.
  • The time N took to settle.
  • Five readings of N, their mean and their half range.
Vademecum · Instruments

Resolution

Definition
The smallest change an instrument can show you. It is fixed by how the instrument is built — it does not depend on how carefully you use it.
InstrumentResolution
Reference thermometer (digital)0.1 °C — its smallest displayed step
Millimetre ruler (analogue, for comparison)1 mm — its smallest printed division
Arduino, reading N on A01 count out of 1024 — its smallest possible step
Vademecum · Instruments

One reading, how sure are you?

Analogue scale
Your eye can judge a position between two printed marks.
\pm \tfrac{1}{2}\,\text{smallest division}
e.g. a mm ruler → ±0.5 mm
Digital display
The display jumps from one value to the next. There is nothing to interpolate.
\pm 1\,\text{smallest increment}
e.g. reference thermometer → ±0.1 °C; Arduino N → ±1 count
Vademecum · Instruments

Sensitivity

Definition
The gradient of your calibration line, in counts per °C. Unlike resolution, it is not a fixed spec of the sensor — you only learn it by calibrating with several points.
Vademecum · Errors

Random error and half range

Random error
The reading scatters when you repeat the measurement under the same conditions — tiny stirring differences, thermal noise, timing.
Half range, from your five readings
\text{half range}=\dfrac{N_{max}-N_{min}}{2}
This is your estimate of the random error on the mean — usually bigger than the ±1-count reading uncertainty, because it also picks up settling and thermal noise that a single reading cannot show.
Vademecum · Errors

Systematic error and anomalous results

  • Systematic error: it moves every reading the same way, for example reading before the sensor has settled. Repeating the measurement does not remove it.
  • Anomalous result: a point far from the trend. Check it, repeat it if you can, and say what you did. Do not delete it quietly.
Homework · Graph

By hand, on millimetre paper

  • N on the vertical axis, T on the horizontal axis, labelled N / counts and T / °C.
  • Scales use more than half the grid. Points are small crosses.
  • One straight best-fit line, with about as many points above as below.
  • Do not join the first and last points.
  • Gradient from a big triangle with two points that are not data points. Intercept N₀ at 0 °C.
Optional, for the curious

Want the computer to do the maths?

  • Not needed for the report — everything in it comes from the Serial Monitor and a pen.
  • For groups that finish early: a small Python script can take ten readings automatically and compute the mean and spread for you.
  • Everything below is written for the Windows laptops in this room.
Optional · Step 1

Install pyserial

  • Click Start, type PowerShell, open it.
  • Type the line below and press Enter.
  • Wait for a line ending in "Successfully installed pyserial".
py -m pip install pyserial
Optional · Step 2

Find the COM port

  • Close the Arduino IDE's Serial Monitor first — only one program can read the port at a time.
  • Open Device Manager (Start, type "Device Manager").
  • Expand Ports (COM & LPT).
  • Note the number next to "Arduino Uno", e.g. COM3.
Optional · Step 3

Ten readings, mean and spread

  • Save this as acquire.py in a new folder.
  • Change COM3 to your own port.
  • In PowerShell, move into that folder and run: py acquire.py
import serial, statistics, time

PORT = "COM3"   # change to your port
ser = serial.Serial(PORT, 9600, timeout=2)
time.sleep(2)
ser.reset_input_buffer()

readings = []
while len(readings) < 10:
    line = ser.readline().decode().strip()
    if line.isdigit():
        readings.append(int(line))

print(readings)
print("mean =", statistics.mean(readings))
print("stdev =", statistics.stdev(readings))
Optional · Going further

A live graph

  • Install once: py -m pip install matplotlib
  • Save as live_plot.py, change the port, run the same way.
  • Close the window to stop it.
import serial, time
import matplotlib.pyplot as plt

ser = serial.Serial("COM3", 9600, timeout=2)
time.sleep(2)
xs, ys = [], []
plt.ion()
fig, ax = plt.subplots()
line, = ax.plot(xs, ys)
t0 = time.time()

while True:
    raw = ser.readline().decode().strip()
    if raw.isdigit():
        xs.append(time.time() - t0)
        ys.append(int(raw))
        line.set_data(xs, ys)
        ax.relim(); ax.autoscale_view()
        plt.pause(0.05)
Hand in

What to hand in

  • One lab report per group, on the template.
  • The graph on millimetre paper, attached.
  • Every member's name on the report.
  • Deadline: Tuesday 29/09.