Replace onewire with thermistor, help!

Hi guys…

I hope everyone is well, I hope to get some help on my code for a project I am doing.
I have tried for days and I just don’t get it. it may stand to you guys.

My project needs to read a sensor, I was using a ONEWIRE sensor and now wish to use 10K ntc type

I have made my code work from searching over the internet for similar projects and taking important code and putting them together… in the end I got it working with the onewire but being so bulky I want to change to the smaller thermistor as they are tiny and can fit in smallest places…

Can you guys can read my program and help to see where I am going wrong. I have marked areas of interest with // areas.

Everytime I compile I am getting GetTemp4 was not declared in this scope Line 65
float temperature = constrain(getTemp4(), MIN_TEMP, MAX_TEMP);

thanks,
I have also attached a 2nd code I experimented with making a thermistor to work…
Basically I thought I could make the thermistor send it’s temperature to my code.

EDIT… Problem solved.

// LINE 6-17 = new code trying to make use of TEMP_PIN A0 which is a thermistor.
// LINE 41 added TEMP-PIN as an input
// Lines 57-58 I copied from another code.
// LINES 87-134 I have disabled to try and start using a new Thermistor line 6

#define TEMP_PIN A0
//int adc = 0;
//int blue = 0, red = 0;
double ReadThermistor(int adc) {
  double resistance = ((1024.0/adc) - 1);    //calculate from voltage divider, for 10k resistor
  double Temp4 = log(resistance);
  // calculate the temperature, in K, using 4 thermistor model/material specific parameters A, B, C, D
  // here we use the values for the Sparkfun/Hactronics version of the Vishay 10k NTC thermistor
  Temp4 = 1 / (0.003354016 + 0.0002569850 * Temp4 + 0.000002620131 * Temp4 * Temp4 + 0.00000006383091 * Temp4 * Temp4 * Temp4);
  Temp4 = Temp4 - 273.15;            // Convert Kelvin to Celsius
  return Temp4;
}


//#include "OneWire.h"
//#include "Streaming.h"

//const int DS18S20a_Pin = 2; //DS18S20 Signal pin on digital 2
#define MIN_TEMP 10
#define MAX_TEMP 45
#define RELAY1  4 // Relay on digital pin 4
//OneWire ds(DS18S20a_Pin);

#define SIZE    255
#define DELAY    0
#define HUE_MAX  6.0
#define HUE_DELTA 0.01
int firstPins [] = { 3,5};
long rgb[2];
long rgbval;
float hue=0.0, saturation=1, value=1;
long bright[2] = { 256, 256};
long k, temp_value;

void setup () {
    pinMode(TEMP_PIN, INPUT);

    
  randomSeed(analogRead(4));
  pinMode(RELAY1, OUTPUT);
  Serial.begin(57600);
  for (k=0; k<2; k++) {
    pinMode(firstPins[k], OUTPUT);
    rgb[k]=0;
     analogWrite(firstPins[k], rgb[k] * bright[k]/256);
  }
}


void loop() {
  adc = analogRead(TEMP_PIN);
  int temp4 = ReadThermistor(adc);
  
  pinMode(RELAY1, OUTPUT); //new


//This is to make use of temperature to setup lighting and activate relay switches based of heat etc
 // float temperature = constrain(getTemp(), MIN_TEMP, MAX_TEMP);    // REMOVED LINE TO NOW USE DIFFERENT SENSOR the gettemp is below and cannot work out how to attach new sensor
    float temperature = constrain(getTemp4(), MIN_TEMP, MAX_TEMP);   // I HAVE RENAMED Temp to Temp4 to make it clear as the code above Lines 11-16
    
    float deltaTemp = (MAX_TEMP - MIN_TEMP);
    float deltaHue = 4 - 0;

  hue = map((temperature - MIN_TEMP) * 100, 0, deltaTemp * 100, deltaHue * 100, 0) / 100.0;
  rgbval=HSV_to_RGB(hue, saturation, value);
  rgb[0] = (rgbval & 0x00FF0000) >> 16;
  rgb[1] = (rgbval & 0x0000ff00) >> 8;
            for (k=0; k<2; k++) {
    analogWrite(firstPins[k], rgb[k] * bright[k]/256);}

//SECTION CONTROL RELAY SWITCH
if (temperature < 40) {
digitalWrite(4,HIGH);
} else if (temperature > 36) {
digitalWrite(4,LOW);
}
}



//SENSORS SECTION

//     I DISABLED THIS PART OF CODE TO ALLOW USE OF MY NEW SENSOR NOT THE ONEWIRE TYPE.

//float getTemp(){
 //returns the temperature from one DS18S20 in DEG Celsius

 //byte data[12];
// byte addr[8];

// if ( !ds.search(addr)) {
//   //no more sensors on chain, reset search
//   ds.reset_search();
//   return -10;
// }
// if ( OneWire::crc8( addr, 7) != addr[7]) {
//   Serial.println("CRC is not valid!");
//   return -10;
// }
// if ( addr[0] != 0x10 && addr[0] != 0x28) {
//   Serial.print("Device is not recognized");
//   return -10;
// }

// ds.reset();
// ds.select(addr);
// ds.write(0x44,1); // start conversion, with parasite power on at the end

// byte present = ds.reset();
// ds.select(addr);  
// ds.write(0xBE); // Read Scratchpad

 
// for (int i = 0; i < 9; i++) { // we need 9 bytes
//  data[i] = ds.read();
// }
 
// ds.reset_search();
 
// byte MSB = data[1];
// byte LSB = data[0];

// float tempRead = ((MSB << 8) | LSB); //using two's compliment
// float TemperatureSum = tempRead / 16;
 
// return TemperatureSum;
//}
// End Sensors





//THIS SECTION IS CREATING COLOURS TO DISPLAY ON LED STRIP

long HSV_to_RGB( float h, float s, float v ) {
  /* modified from Alvy Ray Smith's site: http://www.alvyray.com/Papers/hsv2rgb.htm */
  // H is given on [0, 6]. S and V are given on [0, 1].
  // RGB is returned as a 24-bit long #rrggbb
  int i;
  float m, n, f;

  // not very elegant way of dealing with out of range: return black
  if ((s<0.0) || (s>1.0) || (v<1.0) || (v>1.0)) {
    return 0L;
  }

  if ((h < 0.0) || (h > 6.0)) {
    return long( v * 255 ) + long( v * 255 ) * 256 + long( v * 255 ) * 65536;
  }
  i = floor(h);
  f = h - i;
  if ( !(i&1) ) {
    f = 1 - f; // if i is even
  }
  m = v * (1 - s);
  n = v * (1 - s * f);
  switch (i) {
  case 6:
  case 0: 
    return long(v * 255 ) * 65536 + long( n * 255 ) * 256 + long( m * 255);
  case 1: 
    return long(n * 255 ) * 65536 + long( v * 255 ) * 256 + long( m * 255);
  case 2: 
    return long(m * 255 ) * 65536 + long( v * 255 ) * 256 + long( n * 255);
  case 3: 
    return long(m * 255 ) * 65536 + long( n * 255 ) * 256 + long( v * 255);
  case 4: 
    return long(n * 255 ) * 65536 + long( m * 255 ) * 256 + long( v * 255);
  case 5: 
    return long(v * 255 ) * 65536 + long( m * 255 ) * 256 + long( n * 255);
  }
}

}

Solved this by restarting entire project code

Start by writing a simple sketch that reads your thermistor and prints the output to the Serial console.

Basically what you to do is take an analog reading of the pin it's connected to, then calculate the temperature using the beta-coefficient formula. (so NTC between GND and analog pin, and a 10k pull-up between the pin and Vcc).

reading = analogRead(pin);
temperature = 1.0 / (log (NTCSERIESRESISTOR / ((1024 / reading- 1) * THERMISTORNOMINAL)) / BCOEFFICIENT + 1.0 / (TEMPERATURENOMINAL + 273.15)) - 273.15;

Fill in the values for your thermistor (nominal value 10k, series resistor 10k (measure this for better accuracy or use a 1% or better resistor), bcoefficient see data sheet, nominal temperature normally 25°C).