Projects / Temperature sensor comparison lab

Temperature sensor comparison lab

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. UNO14.5 mASSD1306

    Install the libraries

    SSD1306 and GFX.

  2. UNOTMP3625.9°C

    Wire the TMP36

    5V, A0, GND, flat side facing you.

  3. UNOLM3525.9°C

    Wire the LM35

    5V, A1, GND, same orientation.

  4. UNO

    Wire the display

    A4 and A5 with power.

  5. UNO

    Upload the sketch

    Three lines of readings appear.

  6. UNO

    Tape both sensors to a glass

    Keep the legs dry.

  7. UNO

    Add warm water

    Both readings rise together.

  8. UNO

    Compare

    Note the offset against the thermometer.

In short

How do you build a temperature sensor comparison lab?

Two analog temperature sensors read the same glass of water, and you compare their offset and noise. You need Arduino Uno R3, TMP36 temperature sensor, LM35 temperature sensor, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 8 steps and about 75 minutes.

Level
Beginner
Time
About 75 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
TMP36 pin 1Uno 5VFlat side facing you, left leg
TMP36 pin 2Uno A0Middle leg, signal
TMP36 pin 3Uno GNDRight leg
LM35 pin 1Uno 5VFlat side facing you, left leg
LM35 pin 2Uno A1Middle leg, signal
LM35 pin 3Uno GNDRight leg
OLED VCC and GNDUno 5V and GNDCheck the label on your module
OLED SDA and SCLUno A4 and A5Shared I2C bus

Code

The TMP36 and the LM35 both give 10 millivolts per degree Celsius, but the TMP36 has a 500 millivolt offset so it can show below zero, while the LM35 starts at zero volts and so reads from about 2 degrees upwards on a single supply. The sketch switches the Uno to its 1.1 volt internal reference so each ADC step is about a tenth of a degree, which is much finer than the default 5 volt range, and averages 32 readings to cut noise. The TMP36 is only valid up to 125 degrees but at 1.1 volts it reads up to about 60 degrees, which is enough for this test. Keep the sensors dry: do not put bare legs into water. Tape them side by side to the outside of a glass, or seal them in a small plastic bag, and compare the readings with a kitchen thermometer. You will usually find a constant offset of a degree or so between the sensors and the thermometer, which you can remove with a calibration constant, and the noise tells you how many averages you need. Keep the sensors away from the Uno chip, which warms them.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const int TMP_PIN = A0, LM_PIN = A1;
const float REF_V = 1.1;                 // internal reference, about 1.1 V
const int SAMPLES = 32;

float readVolts(int pin) {
  long sum = 0;
  for (int i = 0; i < SAMPLES; i++) { sum += analogRead(pin); delay(2); }
  return (sum / (float)SAMPLES) * REF_V / 1023.0;
}

void setup() {
  Serial.begin(9600);
  analogReference(INTERNAL);              // finer steps, about 0.1 C per count
  delay(50);
  analogRead(TMP_PIN); analogRead(LM_PIN); // discard the first readings after switching reference
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println("OLED not found"); while (1) { } }
  oled.setTextColor(SSD1306_WHITE);
}

void loop() {
  float tmpC = (readVolts(TMP_PIN) - 0.5) * 100.0;   // TMP36: 10 mV per C, 500 mV offset
  float lmC  = readVolts(LM_PIN) * 100.0;            // LM35: 10 mV per C, no offset

  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setCursor(0, 0);
  oled.print("TMP36 "); oled.print(tmpC, 1); oled.println(" C");
  oled.print("LM35  "); oled.print(lmC, 1); oled.println(" C");
  oled.print("Diff  "); oled.print(tmpC - lmC, 1); oled.println(" C");
  oled.display();

  Serial.print(tmpC, 2); Serial.print(","); Serial.println(lmC, 2);
  delay(1000);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

5.03,55.06
5.05,55.04
5.05,55.05
5.06,55.04
5.05,55.04
5.06,55.05

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Room temperatureAbout 20 to 25 C on both
Warm glassBoth rise by the same amount
Finger on one sensorThat reading rises first
Offset against a thermometerWithin one or two degrees
Cold glassBoth fall, LM35 not below about 2 C

If it does not work

Both read wrong

Check that the flat sides face the same way.

Sensors very hot

A leg is wired to 5V and GND the wrong way round, unplug at once.

Readings jump

Increase the number of samples.

LM35 reads high

Warmth from the board or your hand.

Display blank

Try address 0x3D instead of 0x3C.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the temperature sensor comparison lab?

Arduino Uno R3, TMP36 temperature sensor, LM35 temperature sensor, SSD1306 OLED Display and Breadboard 830 Tie Points.

How long does the temperature sensor comparison lab take to build?

About 75 minutes for a beginner maker, in 8 steps.

How do I know the temperature sensor comparison lab works?

Room temperature: About 20 to 25 C on both. Warm glass: Both rise by the same amount. Finger on one sensor: That reading rises first.

Both read wrong: what should I check?

Check that the flat sides face the same way.

Sensors very hot: what should I check?

A leg is wired to 5V and GND the wrong way round, unplug at once.

Readings jump: what should I check?

Increase the number of samples.

LM35 reads high: what should I check?

Warmth from the board or your hand.