Arduino MKR WiFi 1010 - NTC Thermistor Temperature Sensor

In this tutorial, we are going to learn:

Arduino MKR WiFi 1010 reading a stainless steel 10K NTC thermistor probe as °C and °F

Hardware Preparation

1×Arduino MKR WiFi 1010
1×Micro USB Cable
1×10K NTC Thermistor 3950 Waterproof Probe (with 10K resistor)
1×Jumper Wires
1×Optionally, Breadboard

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of NTC Thermistor Temperature Sensor

Think of a thermistor as a resistor that cares about heat. Its value in ohms changes a lot when the temperature changes, and the MKR can measure that value and work out the degrees from it. The letters NTC mean Negative Temperature Coefficient. Put simply: warmer makes the resistance smaller, colder makes it bigger.

Here, the thermistor is sealed in the rounded end of a small stainless steel tube (5 x 25mm), so the tip may sit in water. Half a meter of black cable joins the tube to a white 2-hole JST XH2.54 connector. One pack gives you five probes plus five 10K resistors that match them, so the circuit needs no extra parts from the shop.

10K NTC thermistor probe pinout: sealed steel tube, 0.5m lead and 2-hole JST XH2.54 connector
image source: diyables.io
10K NTC 3950 Probe Kit
Thermistor NTC, 10kΩ ±1% at 25°C
B Constant 3950
Measuring Range -20°C to +105°C
Probe Tip stainless steel, waterproof, 5mm x 25mm, rounded end
Lead 0.5m black two-core cable
Connector JST XH2.54 (white), 2-pin
Insulation over 100MΩ
In the Box 5 probes, 5 x 10K resistors

You will not find an adapter board or any pin labels here. The connector simply has two openings, and a male jumper wire slides into each one. Both wires are the same, since a thermistor, like every resistor, works in either direction:

  • One probe wire (pick either): needs to be connected to the VCC pin of Arduino MKR WiFi 1010, which gives 3.3V
  • The other probe wire: needs to be connected to A0, an analog input of the MKR
  • The kit's 10K resistor: needs to be connected to A0 with one leg and to GND (0V) with the other leg

How the MKR Turns Ohms Into Degrees

The analog pins of the MKR measure a voltage, not a resistance. That is why the probe and its 10K partner are put in a row between 3.3V and GND, and A0 listens to the point in the middle. Two resistors used like this are called a voltage divider. A warm probe lets more current through, so A0 ends up with a bigger share of the 3.3V. A cold probe holds more of the voltage back, and A0 sees less. With a 12-bit reading, these are the numbers to expect:

Temperature of the Tip Probe Resistance A0 Voltage 12-bit analogRead()
-20°C 105.4kΩ 0.29V 355
20°C 12.5kΩ 1.46V 1817
37°C 6.0kΩ 2.06V 2561
60°C 2.5kΩ 2.64V 3280
80°C 1.3kΩ 2.93V 3633

The sketch walks this table backwards. From the analogRead() number it finds the probe resistance R, and from R it finds the temperature T in kelvin with the B formula (also known as the beta equation):

1/T = 1/T0 + (1/B) × ln(R/R0)

This probe uses B = 3950, R0 = 10000Ω and T0 = 298.15K (the kelvin value of 25°C). Subtracting 273.15 from T turns kelvin into °C. Some people use the Steinhart-Hart equation, a 3-coefficient formula that is a little more exact. For this probe, the single B value does the job well. Around room temperature, being off by about 1°C is normal. The real value of your 10K resistor and the MKR's ADC decide the rest.

Why the VCC pin and not 5V? There are two reasons:

  • The MKR WiFi 1010 is a 3.3V board, and an analog pin must never get more than 3.3V. With 5V on the divider, A0 would climb to about 4.4V once the probe reaches 80°C. That is too much for the SAMD21 chip.
  • The ADC of the MKR measures against the same 3.3V supply that comes out of the VCC pin. Because the divider hangs on that same supply, only the ratio raw / 4095 counts. If the 3.3V is a little high or low, both sides move together, so the code never needs the exact voltage.

Where can the probe go? Anywhere a wet or closed space needs watching: an aquarium, a freezer or fridge, a fermentation bucket for home brew, an egg incubator, a greenhouse or a hydroponic tank. The MKR WiFi 1010 adds one more thing: it can later send the temperature over WiFi, so you can check it without walking over.

Wiring Diagram

Only three pins of the MKR take part: VCC, GND and A0. VCC and GND sit next to each other on one header row, while A0 is on the other row. That is why, in the picture, the A0 wire comes around from the opposite side of the board. The wire on VCC carries the tag 3V3, which is the voltage this pin gives out.

The wiring diagram between Arduino MKR WiFi 1010 NTC thermistor probe  with the 10K resistor on A0

This image is created using Fritzing. Click to enlarge image

Thermistor Circuit Arduino MKR WiFi 1010 Pin
Probe wire, either one VCC (3.3V)
Other probe wire A0
10K resistor, one leg A0
10K resistor, other leg GND

The picture puts the 10K resistor right between the yellow A0 wire and the black GND wire. On a desk, a small breadboard is the easiest way to make those joints: put the two resistor legs into two different rows, plug the second probe wire and the A0 jumper into the first row, and plug the GND jumper into the second row. No breadboard? Bend each resistor leg into a small hook around its jumper end and squeeze it closed, or solder the joints for a project that has to last.

Keep the probe wire on VCC. The 5V pin of the MKR is only for parts that really need 5V, and here it would push A0 over its 3.3V limit as the probe gets hot.

How To Program For NTC Thermistor

  • Nothing to install: the Arduino core already has analogRead() and log().
  • Give names to the pin and the probe numbers: const int NTC_PIN = A0;, const float SERIES_RESISTOR = 10000.0;, const float NTC_R25 = 10000.0;, const float NTC_T25 = 298.15; and const float NTC_BETA = 3950.0;
  • Switch to 12 bits in setup(): analogReadResolution(12);. The MKR then counts from 0 up to 4095 (out of the box it stops at 1023), so one step is only about 0.8mV.
  • Take ten readings and average them: sum += analogRead(NTC_PIN); inside a for loop, then float raw = sum / (float)SAMPLE_COUNT;. This keeps the last digit of the temperature calm.
  • Look at the raw value before any math. Under 20 means there is no probe (the 10K resistor pulls A0 to 0V). Over 4075 means a short, or a resistor that is not on GND. Both would end in inf or nan, so a short warning is printed in place of the temperature.
  • Work out the probe resistance: float ntcOhms = SERIES_RESISTOR * (ADC_FULL_SCALE / raw - 1.0);. This form is right because the probe is on the VCC side and the 10K resistor is on the GND side.
  • Turn ohms into kelvin with the B formula, where log() means the natural log (ln): float kelvin = 1.0 / (1.0 / NTC_T25 + log(ntcOhms / NTC_R25) / NTC_BETA);
  • Change kelvin into everyday units: celsius = kelvin - 273.15; and fahrenheit = celsius * 9.0 / 5.0 + 32.0;
  • Let the Serial Monitor catch up: while (!Serial && millis() < 3000); comes after Serial.begin(9600);, because the MKR talks to the PC through its own native USB port.

Arduino Code - Temperature from the NTC Thermistor Probe

Every second, this sketch prints one line: the probe resistance in kilohms, the averaged raw number from A0, and the temperature in °C and °F. A missing or shorted probe gives a warning line instead.

/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-ntc-thermistor-temperature-sensor */ const int NTC_PIN = A0; // Arduino MKR WiFi 1010 pin A0: the point where the thermistor meets the 10K resistor const float SERIES_RESISTOR = 10000.0; // the 10K resistor from A0 to GND (it comes with the probe) const float NTC_R25 = 10000.0; // resistance of the thermistor at 25°C const float NTC_T25 = 298.15; // 25°C written in kelvin const float NTC_BETA = 3950.0; // B value of the probe const float ADC_FULL_SCALE = 4095.0; // 12-bit reading: 0 to 4095 const int SAMPLE_COUNT = 10; // how many readings to average void setup() { Serial.begin(9600); while (!Serial && millis() < 3000); // native USB: give the Serial Monitor up to 3 seconds to connect analogReadResolution(12); // the SAMD21 ADC can give 12 bits (0 to 4095), so use them all } // read A0 several times and return the average, because one single reading jumps a little float readAverageRaw() { long sum = 0; for (int i = 0; i < SAMPLE_COUNT; i++) { sum += analogRead(NTC_PIN); delay(10); } return sum / (float)SAMPLE_COUNT; } void loop() { float raw = readAverageRaw(); if (raw < 20) { // the 10K resistor pulls A0 down to GND when the probe is missing Serial.println("No thermistor found: check the probe wires on VCC and A0"); } else if (raw > 4075) { // A0 sits at the 3.3V top: shorted probe, or the 10K resistor is not on GND Serial.println("A0 is at the top: check for a short or a missing 10K resistor"); } else { // the thermistor is on the VCC side of the divider float ntcOhms = SERIES_RESISTOR * (ADC_FULL_SCALE / raw - 1.0); // B (beta) formula, log() is the natural logarithm float kelvin = 1.0 / (1.0 / NTC_T25 + log(ntcOhms / NTC_R25) / NTC_BETA); float celsius = kelvin - 273.15; float fahrenheit = celsius * 9.0 / 5.0 + 32.0; Serial.print("Thermistor "); Serial.print(ntcOhms / 1000.0, 2); Serial.print(" kOhm (raw "); Serial.print(raw, 0); Serial.print(") = "); Serial.print(celsius, 1); Serial.print(" °C, "); Serial.print(fahrenheit, 1); Serial.println(" °F"); } delay(1000); }

Detailed Instructions

  • Connect Arduino MKR WiFi 1010 to PC via Micro USB cable.
  • Make the three connections from the wiring diagram. One probe wire goes on VCC, not on 5V.
  • Navigate to the Arduino IDE, then select the Arduino MKR WiFi 1010 board and its port. Using this board for the first time? See Getting Started with Arduino MKR WiFi 1010 first.
  • Copy the above code and paste it into Arduino IDE.
  • Click the Upload button to send the code to Arduino MKR WiFi 1010.
How to upload Arduino MKR WiFi 1010 code on Arduino IDE
  • Open the Serial Monitor and pick 9600 baud.
  • Let the probe rest on the desk while the first lines appear. Meanwhile, mix water from the kettle with tap water in a mug until it feels like a warm bath. Then dip the steel tip into the mug.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino MKR WiFi 1010
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino MKR WiFi 1010' on 'COM15')
New Line
9600 baud
Thermistor 12.09 kOhm (raw 1854) = 20.8 °C, 69.4 °F Thermistor 12.03 kOhm (raw 1859) = 20.9 °C, 69.6 °F Thermistor 12.14 kOhm (raw 1850) = 20.7 °C, 69.3 °F Thermistor 12.09 kOhm (raw 1854) = 20.8 °C, 69.4 °F Thermistor 8.96 kOhm (raw 2160) = 27.5 °C, 81.5 °F Thermistor 6.27 kOhm (raw 2517) = 35.9 °C, 96.6 °F Thermistor 5.18 kOhm (raw 2698) = 40.6 °C, 105.1 °F Thermistor 4.72 kOhm (raw 2782) = 42.9 °C, 109.2 °F Thermistor 4.56 kOhm (raw 2813) = 43.8 °C, 110.8 °F Thermistor 4.49 kOhm (raw 2827) = 44.2 °C, 111.6 °F Thermistor 4.51 kOhm (raw 2823) = 44.1 °C, 111.4 °F
Ln 11, Col 1
Arduino MKR WiFi 1010 on COM15
2

Lines one to four were taken in room air, close to 21°C. Once the tip was in the mug, the raw number shot up and the resistance dropped from about 12kΩ to 4.5kΩ. After some five seconds the reading stopped near 44°C, the temperature of the water. Lift the probe out and you will see the numbers slowly walk back down.

Something looks wrong?

  • Warming the probe makes the number fall: thermistor and resistor sit in each other's places. The probe belongs between VCC and A0, the resistor between A0 and GND.
  • You only see "No thermistor found": a jumper wire came loose from the white connector, or the A0 wire sits on another pin.
  • The readings are steady but always a few degrees off: check that the resistor is the kit's 10K one and not some other value. A multimeter tells you for sure.

Tips for the waterproof probe:

  • The steel tube is the only sealed part. Hold the connector, the jumpers and the resistor joints above the water line.
  • Give the tip a few seconds at each new temperature. The steel needs a moment to warm up or cool down all the way through.
  • Stay at 105°C or below. For hotter jobs such as a pizza oven, a thermocouple sensor like the MAX6675 module is the better tool.

What to try next: print the temperature on an LCD, or let a relay switch a fan or a heater at the temperature you choose. If you prefer a probe that does the math itself and sends a ready digital value, the waterproof DS18B20 is covered in Arduino MKR WiFi 1010 - Temperature Sensor.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!