NTC test circuit

I am using the attached NTC and connected it in series with a 10k resistor, supplying the series with 5V from Arduino.
It is a very ordinary circuit to detect temperature ... but I measure a temperature of 17 C° when I have about 23 C° at home.

I can't figure out what is going wrong.

The voltage at the ends of the NTC is sent to pin A5 of Arduino and I wrote the code to calculate the temperature.
Since the NTC is connected (soldered) to two wires that act as an "extension" to get to the Arduino, I did not state the R0=33k at T0=25°C as on the datasheet ... but with the multimeter I measured the resistance of the NTC (at 25°C) ... that is 37k ... so on the Arduino I used R0=37k and not 33k.

(If I leave 33k measure 15°C)

NTC-2.pdf (165,8 KB)

circuit

sketch.ino (3,9 KB)

Please post your entire sketch, not a snippet.

Post updated

Edit - please post your code in line, in a following message. Please do not edit your original post. Do not add code as an attachment again.

There is the sketch.ino file atatched

Please read the forum guidelines.


This is from:

1 Like

As I was pasting the code here I realized that I had not initialized the NTC pin ... what a stupid mistake I made! :upside_down_face:

pinMode(readPin, ntc_pin);

Sorry for wasting your time, the important thing is to have solved and understood the error.

1 Like

It starts with the NTC.
I think that a 37k NTC does not exist. If you have a 37k NTC, then you have to know its Beta. The best accuracy is when using a lookup table from the manufacturer.

Since you have a unknown NTC, you can not calculate the temperature, you can only make guesses.
Was the NTC overheated perhaps ? and now it is damaged ?

I came across this document that shows how the formula is not ideal: https://catalogs.kyocera-avx.com/NTC-Thermistors.pdf

Please explain what that line of code is. Can you show your whole sketch ?

Don't assume you will get exactly 5v from there...........

This does not look right. Your sketch has ntc_pin defined as A5 undefined, which is not INPUT, INPUT_PULLUP or OUTPUT .

By default, the pins are initialized to all be pinMode(xxx,INPUT)

Your sketch.ino:

//Librearie per il display LCD:
#include <Wire.h>               //libreria per I2C
#include <LiquidCrystal_I2C.h>  //libreria per LCD
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4);

//Pins su Arduino da usare:
#define ntc2_pin A5   // Pin che rileva la V del partitore di tensione del NTC2
#define Vg 8          // Pin che da  in output la V
#define vdd 2         // 5V per il partitore di tensione


//Parametri dell'NTC2:
#define R0_NTC2 37000 //Resistenza nominale a 25⁰C .. cioè 33k
#define temperatura_nominale 25   //Temperatura nominale = 25⁰C
#define beta2 4220    //coefficiente beta del termistore

#define Rref 10000     //Valore del resistore utilizzato per i partitori di tensione
float campioni2 = 0;   //array per memorizzare i campioni di tensione letti (generati da NTC2)

int readPin = A3;
float temperatura2 = 0;  //a 25°C la resistenza è 10k per ntc1 e 33k per nct2


int ritardo = 500;
int i = 0;           //per il ciclo for     
float tensione2 = 0; //per il ciclo for
float Rntc2 = 0;



void setup() {
  
  /*
  SDA --> A4
  SCL --> A5
  GND --> GND
  5V --> 5V
  */
  //pinMode(4, OUTPUT); //SDA
  //pinMode(5, OUTPUT); //SCL
  lcd.init();
  lcd.backlight();
  lcd.clear();

  pinMode(readPin, INPUT);  //readPin = A3 = input                          A CHE MI SERVE A3 ????
  pinMode(Vg, OUTPUT);
  //pinMode(vdd,OUTPUT);      //D2 = output (fornisce i 5V)
  Serial.begin(9600);

}

void loop() {
  

  //Prelevo 10 campioni e ne calcolo la media (per una miglior precisione):
  //inizio lettura (e campionamento):
  int numero_campioni = 20;   //scegli tu quanto mettere
  //digitalWrite(vdd,HIGH);
    for (i = 0; i < numero_campioni ; i++) {
      campioni2 = campioni2 + (float)analogRead(ntc2_pin);
      delay(20); //ogni campione viene letto ogni 20ms
  }
   //digitalWrite(vdd,LOW);
  //fine lettura

  tensione2 = campioni2 / numero_campioni;
  tensione2 = tensione2/1024.0*5;
  campioni2=0;

//tensione = (float)analogRead(ntc1_pin);
//tensione = tensione/1024.0*5;

  //V partitore:
  /*Serial.print("V partitore = "); 
  Serial.println (tensione, 3); 
  Serial.println(" [V]");
  lcd.setCursor(0, 0);           //a sx le colonne .. a dx le righe
  lcd.print("V partitore = ");
  lcd.setCursor(14, 0);
  lcd.print(tensione);
  lcd.print(" V");*/

  delay(50);


  //resistenza dell'NTC2 (termistore)
  Rntc2 = tensione2*Rref/(5*(1-tensione2/5));
  Serial.print("Rntc2 = "); 
  Serial.println (Rntc2, 2); 
  Serial.println(" [ohm]");
  lcd.setCursor(0, 2);           //a sx le colonne .. a dx le righe
  lcd.print("Rntc2 = ");
  lcd.setCursor(8, 2);
  lcd.print(Rntc2);
  lcd.print(" ohm");




  //temperatura media dell'NTC (termistore)
  /*temperatura = media / resistenza_nominale;
  temperatura = log(temperatura) / beta;
  temperatura = 1.0 / (temperatura_nominale + 273.15);
  temperatura = (1.0 / temperatura) - 273.15;
  */

  temperatura2 = (1./296.15+log(Rntc2/R0_NTC2)/beta2);
  temperatura2 = 1/temperatura2;
  Serial.print("T2 = ");
  Serial.print(temperatura2-273.15);
  Serial.println(" °C");
  lcd.setCursor(0, 3);
  lcd.print("T2 = ");
  lcd.setCursor(5, 3);
  lcd.print(temperatura2-273.15);
  lcd.print(" C");


          ////////////////////////////////////////////////////////// CONTROLLO //////////////////////////////////////////////////////////
/*
if (temperatura1-273.15 >= 40)
{
  digitalWrite(Vg, LOW);
}
else if (temperatura1-273.15 < 40)
{
  digitalWrite(Vg, HIGH);
}
else if(temperatura1-273.15 < 40 && temperatura1-273.15 > 37){
  digitalWrite(Vg, HIGH);
}
*/
          ////////////////////////////////////////////////////////// CONTROLLO //////////////////////////////////////////////////////////



  /*
  tensione = ((5.)/1023.)*analogRead(readPin);
  
  Serial.println(tensione); //stampo il valore di V letto
  Serial.print("[V]");  //stampo la stringa "[V]" dopo il numero per chiarezza di lettura
  delay(ritardo);  //eventualmente un ritardo tra una lettura e un'altra
*/


}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.