Datalogging and Relay Output in Uno

sarouje:
Try to do Serial print of 'temp' variable and see the what your function returns. Then you can identify your issue.

#include <math.h>
#include <SPI.h>
#include <SD.h>

File file;

int count = 1;

#define CSpin 4
#define RelayPin 9

void setup()
{
  pinMode(RelayPin, OUTPUT);
  digitalWrite(RelayPin, LOW);
  Serial.begin(9600);
  if (!SD.begin(CSpin)) {
    Serial.println("No SD card or connection.");
    return;
  }
  Serial.println("SD Card connected");
}

double Termistor(int analogRead)
{
  double temp;
  temp = log(((10240000 / analogRead) - 10000));
  temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp )) * temp );
  temp = temp - 273.15;
  return temp;
}


void loop()
{

  int value ;
  double temp ;
  value = analogRead(A0);
  temp = Termistor(value);
  if (temp > 60)
    digitalWrite(RelayPin, HIGH);
  else
    digitalWrite(RelayPin, LOW);
  save();
}


void save()
{
  int value ;
  double temp ;

  value = analogRead(A0);
  temp = Termistor(value);
  Serial.println(temp);
  file = SD.open("Log.txt", FILE_WRITE);
  if (SD.exists("Log.txt")) {
    file.print(count);
    file.print(".minute ");
    file.print("NTC temperature value:");
    file.println(temp);
    file.print(count);
    file.print(".minute ");
    Serial.println("Temperature value saved.");
  } else {
    Serial.println("Failed");
  }
  count++;
  delay(60000);
}

this is output in serial port

SD Card connected
17.18
Temperature value saved.