Pico two-sensor thermometer comparison
Build it step by step
0 of 7 doneIdentify the pins
Flat face towards you, legs down: +Vs, Vout, GND from the left.
Wire the LM35
+Vs to VBUS, Vout to GP26, GND to GND.
Wire the TMP36
+Vs to 3V3(OUT), Vout to GP27, GND to GND.
Wire the OLED
3V3(OUT), GND, SDA to GP0, SCL to GP1.
Install the ssd1306 module
Using Thonny packages.
Run the program
Both temperatures and the difference appear.
Pinch both sensors together
Both rise by a few degrees.
How do you build a pico two-sensor thermometer comparison?
A Pico reads an LM35 and a TMP36 side by side and shows both temperatures and the difference on an OLED, to learn about sensor accuracy. You need Raspberry Pi Pico H, LM35 temperature sensor, TMP36 temperature sensor, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 7 steps and about 130 minutes.
- Level
- Beginner
- Time
- About 130 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 |
|---|---|---|
| LM35 pin 1 (+Vs) | Pico VBUS pin 40 | The LM35 needs at least 4 V, so it uses the 5 V pin |
| LM35 pin 2 (Vout) | Pico GP26 pin 31 | ADC0, 10 millivolts per degree |
| LM35 pin 3 (GND) | Pico GND pin 38 | Common ground |
| TMP36 pin 1 (+Vs) | Pico 3V3(OUT) pin 36 | Power at 3.3 V |
| TMP36 pin 2 (Vout) | Pico GP27 pin 32 | ADC1, 500 millivolt offset |
| TMP36 pin 3 (GND) | Pico GND pin 38 | Common ground |
| OLED VCC and GND | Pico 3V3(OUT) pin 36 and GND pin 3 | Power at 3.3 V |
| OLED SDA and SCL | Pico GP0 pin 1 and GP1 pin 2 | I2C data and clock |
Code
Both of these chips turn temperature into a voltage that rises by 10 millivolts for every degree Celsius. The LM35 gives 0 volts at 0 degrees, so at 25 degrees it gives 250 millivolts. The TMP36 adds an offset of 500 millivolts so that it can also report below zero, which means it gives 750 millivolts at 25 degrees. The program reads each voltage with the Pico's analog converter, averages 64 readings to calm the noise, and applies the right formula for each chip. The LM35 needs a supply of at least 4 volts, so it is powered from the 5 volt pin, while the TMP36 works from 3.3 volts. Neither is exact: each has a stated accuracy of about half a degree or a degree, and the Pico's converter adds a little error of its own, especially at the low voltage of the LM35. Hold both sensors together between your fingers and watch how they differ, and try ice water as a check at 0 degrees.
import time
from machine import Pin, I2C, ADC
from ssd1306 import SSD1306_I2C
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
lm35 = ADC(26)
tmp36 = ADC(27)
def millivolts(adc):
total = 0
for _ in range(64):
total += adc.read_u16()
return (total / 64) * 3300 / 65535 # average to reduce noise
while True:
t_lm = millivolts(lm35) / 10.0 # 10 mV per degree, zero at 0 C
t_tmp = (millivolts(tmp36) - 500) / 10.0 # 10 mV per degree, 500 mV at 0 C
oled.fill(0)
oled.text("LM35 %.1f C" % t_lm, 0, 4)
oled.text("TMP36 %.1f C" % t_tmp, 0, 22)
oled.text("Diff %.1f C" % (t_lm - t_tmp), 0, 40)
oled.show()
time.sleep_ms(500)Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Both in room air | Within about 2 degrees of each other |
| Pinched between fingers | Both rise together |
| Held in ice water, sealed in a bag | Both fall towards 0 degrees |
| Blow on them | Both fall a little |
| Difference | Stays within a degree or two |
If it does not work
Reads very hot or very cold
Check the chips are the right way round, a reversed sensor gets hot.
LM35 reads wrong
Check it has 5 V on VBUS, not 3.3 V.
Both read low
Check the pin order and the wire to the ADC pin.
Difference is large
Let both settle for a minute and keep them together.
Nothing on the display
Check the I2C wires and the address 0x3C.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the pico two-sensor thermometer comparison?
Raspberry Pi Pico H, LM35 temperature sensor, TMP36 temperature sensor, SSD1306 OLED Display and Breadboard 830 Tie Points.
How long does the pico two-sensor thermometer comparison take to build?
About 130 minutes for a beginner maker, in 7 steps.
How do I know the pico two-sensor thermometer comparison works?
Both in room air: Within about 2 degrees of each other. Pinched between fingers: Both rise together. Held in ice water, sealed in a bag: Both fall towards 0 degrees.
Reads very hot or very cold: what should I check?
Check the chips are the right way round, a reversed sensor gets hot.
LM35 reads wrong: what should I check?
Check it has 5 V on VBUS, not 3.3 V.
Both read low: what should I check?
Check the pin order and the wire to the ADC pin.
Difference is large: what should I check?
Let both settle for a minute and keep them together.
