Skip to content

Arduino Digital Temperature Sensor

    In this tutorial you will learn how to connect Arduino with digital temperature sensor, what is Elegoo Sensor Module, and how to create Arduino based digital thermometer.

    What is NTC Thermistor?

    An NTC thermistor is a type of resistor that changes its resistance with temperature. It is used in temperature sensors, and is often used in conjunction with a digital temperature sensor.

    NTC Thermistor
    NTC Thermistor

    The NTC thermistor has a negative temperature coefficient, meaning that the resistance decreases as the temperature increases. This means that when the NTC thermistor is heated up, it will have less resistance and more current will flow through it. Typical applications for NTC thermistors are in a temperature sensor, the control circuit for a refrigerator or heating element, or the control circuit for an oven. It’s used as a sensing element to provide it to the controller to regulate the temperature.

    NTC voltage divider

    The basic circuit for temperature measurement is a voltage divider. The resulting voltage can be connected directly to the Arduino analog port of the Arduino as shown below:

    The circuit consists of two resistors, one with a fixed value and the other with a variable value. The variable resistor is called the thermistor and it has a resistance that changes depending on the temperature. When the temperature changes, its resistance changes, which results in changing the voltage at the Analog pin A0.

    Arduino Thermistor Circuit
    Arduino Thermistor Circuit

    Elegoo Digital Temperature Sensor

     The Elegoo Temperature sensor module uses an NTC thermistor.

    Elegoo Digital Temperature Module. Source: Elegoo Inc.
    Elegoo Digital Temperature Module. Source: Elegoo Inc.

    Its output signal A0 provides an analog voltage corresponding the temperature value. Its output signal at D0 switches high when the preset (adjustable by the blue trimmer) temperature is reached.

     Elegoo Digital Temperature Sensor pin Configuration

    • Pin DO: Digital output
    • Pin +: Vcc (3.3V or 5V)
    • Pin G: GND
    • Pin AO: Analog output

    How to Connect Arduino with Elegoo temperature sensor module ?

    Connecting Arduino with elegoo temperature sensor is by connecting pin Vcc to 5V on Arduino, G to GND, and AO to A0 or other Arduino’s analog ports.

    Connectecting Arduino with Elegoo temperature sensor module
    Connectecting Arduino with Elegoo temperature sensor module

    Arduino based digital temperature sensor

    There is many types of temperature sensors we can use with Arduino such as this tutorial LM35 or this DHT11 sensor. Anyway, in this tutorial we are going to show you some more details about NTC thermistor and their calculations.

    What is Steinhart–Hart Equation

    Steinhart-Hart Equation is mathematical expression for resistance temperature relationship of NTC thermistors and NTC prob. The equation is:

    Steinhart-Hart Equation
    Steinhart-Hart Equation 1. Source: ametherm.com

    Where T corresponds to temperature in degrees Kelvin, and the coefficients A, B, and C are as follows:

    First, measure the thermistor at three different temperatures. The temperatures should be evenly spaced at least 10 degrees apart. Use the three temperatures to solve these equations using these steps:

    Steinhart-Hart Equations parameters
    Steinhart-Hart Equations parameters. Source: ametherm.com

    Then solving the coefficients of Steinhart-Hart Equation as follows. Knowing A, B and C for a thermistor allows you to use the Steinhart and Hart equation in Equation 1 above.

    Solving Steinhart-Hart Equation coefficients
    Solving Steinhart-Hart Equation coefficients. Source: ametherm.com

    We have cited the above equation just for your reference. Now, it’s time for practical implementation.

    Arduino thermistor code

    The Arduino sketch below reads the NTC value (output signal A0 of Temperature Sensor Module). And converts the ADC value to temperature according to Steinhart-Hart Equation, and finally prints out the results on the serial monitor.

    #define NTC_PIN A0
    #define SERIES_RES 10000
    #define NOMINAL_RES 10000
    #define NOMINAL_TEMP 25
    #define BCOEFFICIENT 3950
    
    void setup()
    {
      Serial.begin(9600);
    }
    void loop()
    {
      float valAdc, res, steinhartTemp;
      
      // Read ADC value
      valAdc = analogRead(NTC_PIN);
      
      // convert value to resistance
      res = SERIES_RES /((1023 / valAdc) - 1);
    
      steinhartTemp =  (1.0 / ((log(res / NOMINAL_RES)/BCOEFFICIENT) + 1.0 / (NOMINAL_TEMP + 273.15))) - 273.15;
      Serial.print("Resistance in Ohm = ");
      Serial.println(res);
      Serial.print("Temperature in °C = ");
      Serial.println(steinhartTemp);
      delay(1000);
    }
    

    Sources:

    arduino.cc
    ametherm.com
    wikipedia.org
    elegoo.com