Temperature sensor comparison lab
Build it step by step
0 of 8 doneInstall the libraries
SSD1306 and GFX.
Wire the TMP36
5V, A0, GND, flat side facing you.
Wire the LM35
5V, A1, GND, same orientation.
Wire the display
A4 and A5 with power.
Upload the sketch
Three lines of readings appear.
Tape both sensors to a glass
Keep the legs dry.
Add warm water
Both readings rise together.
Compare
Note the offset against the thermometer.
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
| From | To | Why |
|---|---|---|
| TMP36 pin 1 | Uno 5V | Flat side facing you, left leg |
| TMP36 pin 2 | Uno A0 | Middle leg, signal |
| TMP36 pin 3 | Uno GND | Right leg |
| LM35 pin 1 | Uno 5V | Flat side facing you, left leg |
| LM35 pin 2 | Uno A1 | Middle leg, signal |
| LM35 pin 3 | Uno GND | Right leg |
| OLED VCC and GND | Uno 5V and GND | Check the label on your module |
| OLED SDA and SCL | Uno A4 and A5 | Shared 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.
| Check | Expected |
|---|---|
| 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 |
| Offset against a thermometer | Within one or two degrees |
| Cold glass | Both 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 →
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.
