Skip to main content

Grove Temperature Sensor v1.2: how it works

Lab 3a reads this sensor. The lab sheet has the sketch; this page explains the numbers so you can tell a wiring fault from a code fault.

What is inside​

A thermistor: a resistor whose resistance drops as it gets warmer (100 kΩ at 25 °C). The module turns that into a voltage between 0 and 5 V on its SIG pin. Range −40 to 125 °C, accuracy about ±1.5 °C.

Because the output is a voltage (analog), it goes on an analog pin (A0–A5). The Raspberry Pi has no analog inputs, which is one reason the Arduino reads this sensor and sends the result to the Pi.

ArduinoGrove cableSensor
5VRedVCC
GNDBlackGND
(not used)WhiteNC
A0YellowSIG

From reading to °C​

analogRead(A0) gives 0–1023 for 0–5 V. The lab's formula does three steps:

StepCode (idea)Example
1. Reada = analogRead(A0)512 (half of 5 V)
2. ResistanceR = (1023.0 / a - 1.0) * R0 with R0 = 100000≈ 100 kΩ
3. Temperature1.0 / (log(R / R0) / B + 1 / 298.15) - 273.15 with B = 4275≈ 25 °C
  • B = 4275 is the thermistor's "B value" from its datasheet: how strongly it reacts to temperature.
  • 298.15 is 25 °C in Kelvin, the temperature where it is exactly R0.
  • log is the natural logarithm, from <math.h>.

Reading the raw value tells you a lot​

Print analogRead(A0) to the Serial Monitor before the formula:

Raw valueMeans
~400–600 at room temperatureWorking
0SIG not connected, wrong pin in the code, or the sensor has no power. The formula gives −273.15 or inf.
1023SIG shorted to 5V, or VCC/SIG swapped. The formula gives nonsense (often also −273.15).
Jumps by 100sLoose wire or no common GND
Rises when you hold itCorrect: warmer = lower resistance = higher reading

Integer maths trap​

float R = (1023 / a - 1) * R0; // wrong: 1023 / a is integer division (512 -> 1)
float R = (1023.0 / a - 1.0) * R0; // right

In C/C++, int ÷ int = int (the decimals are thrown away). Writing 1023.0 forces decimal maths. The same trap catches averages: sum / count with two ints loses the decimals.

Making readings steadier​

  • Average several readings: read 10 times, add them up, divide by 10.0.
  • Do not touch the sensor or breathe on it while testing.
  • The Uno's own warmth and sunlight on the desk affect it by a degree or two.

Problems​

ProblemFix
-273.15, inf or nanRaw reading 0 or 1023: check the yellow wire is on A0 and the pin in the code matches.
Always the same numberWrong pin in the code, or integer maths (see above).
A few degrees offNormal for ±1.5 °C. Compare against another thermometer, not your feeling.
'log' was not declaredAdd #include <math.h> at the top.
Shows on Serial but not the LCDLCD problem, not the sensor: see Grove LCD.