Interfacing NTC Sensor with Arduino

1,335 views

Introduction

Arduino is a popular open-source electronic platform used for building interactive projects. One of the most important components of an electronic project is the temperature sensor. The NTC (Negative Temperature Coefficient) sensor is a common type of temperature sensor that measures the resistance changes with respect to the temperature. In this article, we will discuss how to connect an “NTC sensor with Arduino” to measure the temperature.

What is NTC Sensor?

An NTC sensor is a type of temperature sensor that works based on the principle of negative temperature coefficient. The resistance of an NTC sensor decreases with an increase in temperature, and the resistance increases as the temperature decreases. NTC sensors are commonly used in applications where accurate temperature measurements are required, such as in temperature control systems, HVAC systems, and industrial process control systems. They are simple, reliable, and cost-effective sensors that can detect temperature changes with high accuracy.

Hardware Components

To interface an NTC Sensor with Arduino, you’ll need the following hardware components to get started:

ComponentsValueQty
Arduino UNO1
USB Cable Type A to B1
DC Power for Arduino1
NTC Sensor1
Jumper Wires1

NTC Sensor Pinout

NTC Sensor Pinout
NTC Sensor Pinout
Pin namePin Description
GNDNegative supply (GND)
5VPositive Power Supply
SIGSignal (resistive divider output)

NTC Sensor Arduino Circuit

Make connections according to the circuit diagram given below.

Wiring / Connections

ArduinoNTC Sensor
5V5V
GNDGND
A0SIG

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Arduino Code NTC Basic

Now copy the following code and upload it to Arduino IDE Software.

const float BETA = 3950; // should match the Beta Coefficient of the thermistor
 
void setup() {
  Serial.begin(9600);
}
 
void loop() {
  int analogValue = analogRead(A0);
  float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
  Serial.print("Temperature: ");
  Serial.print(celsius);
  Serial.println(" ℃");
  delay(1000);
}

Code Explanation

This Arduino code is used to read the temperature using an NTC thermistor sensor connected to an analog input pin of the Arduino. The code initializes a constant variable “BETA” with a value of 3950, which is the Beta Coefficient of the thermistor used. The Beta Coefficient represents the temperature sensitivity of the thermistor, and it is used to calculate the temperature based on the resistance of the thermistor.

In the setup function, the code initializes the serial communication at a baud rate of 9600, which is used to send the temperature readings to a connected computer.

In the loop function, the code reads the analog value from pin A0 using the analogRead function. The analog value is converted to temperature using a formula that calculates the resistance of the thermistor based on the analog value and the Beta Coefficient value. The temperature is then calculated using the Steinhart-Hart equation, which is a mathematical formula that relates the resistance of a thermistor to its temperature.

Finally, the temperature value is printed on the serial monitor using the Serial.print function, with a delay of 1000 milliseconds between each reading. The output shows the temperature in Celsius units with the “℃” symbol.

Arduino Code NTC Advance

// SPDX-FileCopyrightText: 2011 Limor Fried/ladyada for Adafruit Industries
//
// SPDX-License-Identifier: MIT
 
// Thermistor Example #3 from the Adafruit Learning System guide on Thermistors
// https://learn.adafruit.com/thermistor/overview by Limor Fried, Adafruit Industries
// MIT License - please keep attribution and consider buying parts from Adafruit
 
// which analog pin to connect
#define THERMISTORPIN A0        
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000      
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25  
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950
// the value of the 'other' resistor
#define SERIESRESISTOR 10000    
 
int samples[NUMSAMPLES];
 
void setup(void) {
  Serial.begin(9600);
  analogReference(EXTERNAL);
}
 
void loop(void) {
  uint8_t i;
  float average;
 
  // take N samples in a row, with a slight delay
  for (i=0; i< NUMSAMPLES; i++) {
   samples[i] = analogRead(THERMISTORPIN);
   delay(10);
  }
 
  // average all the samples out
  average = 0;
  for (i=0; i< NUMSAMPLES; i++) {
     average += samples[i];
  }
  average /= NUMSAMPLES;
 
  Serial.print("Average analog reading ");
  Serial.println(average);
 
  // convert the value to resistance
  average = 1023 / average - 1;
  average = SERIESRESISTOR / average;
  Serial.print("Thermistor resistance ");
  Serial.println(average);
 
  float steinhart;
  steinhart = average / THERMISTORNOMINAL;     // (R/Ro)
  steinhart = log(steinhart);                  // ln(R/Ro)
  steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart = 1.0 / steinhart;                 // Invert
  steinhart -= 273.15;                         // convert absolute temp to C
 
  Serial.print("Temperature ");
  Serial.print(steinhart);
  Serial.println(" *C");
 
  delay(1000);
}

Code Explanation

This Arduino code reads the temperature using an NTC thermistor sensor connected to an analog input pin of the Arduino. The code initializes several constants, such as the analog pin to which the thermistor is connected (THERMISTORPIN), the nominal resistance of the thermistor (THERMISTORNOMINAL), the temperature at which the nominal resistance is measured (TEMPERATURENOMINAL), the number of samples to take and average (NUMSAMPLES), the Beta Coefficient of the thermistor (BCOEFFICIENT), and the value of the series resistor (SERIESRESISTOR).

In the setup function, the code initializes the serial communication at a baud rate of 9600 and sets the analog reference to EXTERNAL, which is used to provide a stable reference voltage to the analog-to-digital converter.

In the loop function, the code reads the analog value from the thermistor pin multiple times using a for loop and calculates the average value of the readings. The average value is then converted to resistance using a formula that takes into account the series resistor value and the voltage divider equation.

The resistance value is then used to calculate the temperature using the Steinhart-Hart equation, which relates the resistance of the thermistor to its temperature. The temperature value is printed on the serial monitor using the Serial.print function, with a delay of 1000 milliseconds between each reading.

Applications

Here are some applications of NTC sensors:

  • Temperature sensing and control in HVAC systems (heating, ventilation, and air conditioning)
  • Temperature sensing and control in household appliances, such as refrigerators and ovens
  • Temperature sensing and control in industrial equipment, such as kilns and furnaces
  • Temperature sensing and control in automotive systems, such as engine coolant and cabin air temperature
  • Temperature sensing and control in medical devices, such as patient monitors and incubators
  • Temperature sensing and control in food processing and storage, such as refrigeration and cooking equipment
  • Temperature sensing and control in agricultural applications, such as greenhouses and livestock enclosures
  • Temperature sensing and control in aerospace and defense systems, such as avionics and missile guidance systems.

Conclusion

NTC sensor with an Arduino microcontroller is a straightforward process that can be done by anyone with basic electronics knowledge. By following the steps discussed in this article, you can easily connect an NTC sensor to an Arduino and read temperature values accurately.