thermistor value to servo motor, not getting value

I checked the below code to rotate the servo motor to the resultant degree celsius value. But I'm getting a different result while compiling(Serial.println), got correct value when i did it in a calculator. Did i miss something?

#include <Servo.h>
int servoPin = 7;
Servo Servo1;

int thermistorPin = A0; // Thermistor analog input pin id

float thermistorValue = 0; // Store Thermistor value

float vin = 4.86; // Voltage in

float vout = 0.0; // Voltage out

int roomTemp = 28+273.15; // Room Temperature (Kelvins)

float r1 = 0.0; // Resistance R1

int r2 = 10000; // Resistance R1

float r0 = 7.2; // Resistance @ Room Temperature

float coefficientThermistor = 3950;

void setup() {

Servo1.attach(servoPin);
Serial.begin(9600);

}

void loop() {

thermistorValue = analogRead(thermistorPin); // converts voltage to no. between 0 and 1024
vout = (thermistorValue * vin) / 1024.0 ; // convert value to voltage

r1 = r2 * ((vin/vout) - 1);

float resistanceRatio = r1/r0;

float logR = log(resistanceRatio); // ln(r1/r0)

float productTerm = (1/coefficientThermistor)*logR; // 1/B * ln(r1/r0)

float sum = (1/roomTemp) + productTerm; // 1/T0 + 1/Bln(r1/r0)

float steinhart = (1/sum); // inverse 1/T

float steinhartCelsius = steinhart - 273.15; // Convert from Kelvins to Celsius

Servo1.write(steinhartCelsius);

Serial.println(steinhartCelsius); }

Your 'roomTemp' variable is declared 'int' but you are trying to assign a floating point number to it so it will be truncated.

I don't know if that is causing your errors since you did not say what your calculator result was vs. what your code result was.

float r0 = 7.2; // Resistance @ Room Temperature

Should that be 7200.0?

Perhaps it would be better to start with a working example:

// 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 to C
  
  Serial.print("Temperature "); 
  Serial.print(steinhart);
  Serial.println(" *C");
  
  delay(1000);
}