Help with battery saving and sampling intervals

Attached is the current code, which at the moment logs a thermistor and an LM36 temp. sensor. Although, will eventually just be the thermistor and a quartz crystal pressure transducer.

I need some assistance in changing sampling interval…I guess that I would create a bunch of variables for each sampling rate, and then just plug in the one I need? As well, how I can write this code to save battery life. This instrument will be deployed offshore for a few months at a time, so I would need to be able to store lots of data as well as keep the battery life going.

Also…there is one section of the code that seems to print out 2 different answers for the variables, and may have something to do with timing, no big deal…just wondering if that’s what it is. It’s when I print out the temperatures from the Echo_to_serial from double Thermistor(), and the void printTemp().

#include <math.h>
#include <SD.h>
#include "Wire.h"
#include "RTClib.h"

//-------------------------------------------------------

// A simple data logger for the Arduino analog pins
#define LOG_INTERVAL  1000 // mills between entries
#define ECHO_TO_SERIAL   1 // echo data to serial port
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address
const int chipSelect = 10;
RTC_DS1307 RTC;

// the logging file
File datafile;
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
 
//--------------------------------------------------------------------------

void setup(void) {
  Serial.begin(9600);
  Serial.println();
 Wire.begin();  
// initialize the SD card
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
  
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
// don't do anything more:
    return;
  }
  Serial.println("card initialized.");  
 
}
//-------------------------------------------------

//Reference Voltage
long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1125300L / result; // Back-calculate AVcc in mV
  return result;
}
String printDouble( double val, unsigned int precision){
// prints val with number of decimal places determine by precision

    String retval;
    retval += String(int(val));
    retval += ".";
    unsigned int frac;
    if(val >= 0)
	  frac = (val - int(val)) * precision;
    else
	  frac = (int(val)- val ) * precision;
    retval += frac;
    return retval;
}


//-------------------------------------------------------------------------------

float pad = 2267;                       // balance/pad resistor value
float thermr = 2001;                   // thermistor nominal resistance
 
double Thermister(int RawADC) {
  delay(100);
  long Resistance;  
  float Temp;  // Dual-Purpose variable to save space.
 
  Resistance=((1024 * pad / RawADC) - pad); 
  Temp = log(Resistance); // Saving the Log(resistance) so not to calculate  it 4 times later
  Temp = 1 / (-0.002457400 + (0.000955063 * Temp) + (-0.000003299 * Temp * Temp * Temp));
  Temp = Temp - 273.15;  // Convert Kelvin to Celsius                      
  double Vcc=readVcc()/1000.0;
  
  #if ECHO_TO_SERIAL
  Serial.print("ADC: "); 
  Serial.print(RawADC); 
  Serial.println("/1024");                           // Print out RAW ADC Number
  Serial.print("Vcc: ");
  Serial.println(Vcc,2);
  Serial.print("pad: ");
  Serial.print(pad/1000,3);
  Serial.println(" Kohms");
  Serial.print("Volts: "); 
  Serial.println(((RawADC*Vcc)/1024.0),3);   
  Serial.print("Resistance: "); 
  Serial.print(Resistance);
  Serial.println(" ohms ");
 #endif
 
  return Temp;                                      // Return the Temperature
}
//----------------------------------------------------------------------------
double Temperature (int RawADC){
  delay(200);
  float Vcc = readVcc()/1000.0;
  float voltage = (RawADC/1024.0)*Vcc;
  float temp = (voltage - 0.5)*100.0;
  return temp;
}
//-----------------------------------------------------------------------------
void printTherm(void) {
  double therm = Thermister(analogRead(0));  // Read sensor
   
 #if ECHO_TO_SERIAL
  Serial.print("Therm Temperature is: ");
  Serial.print(therm,2);
  Serial.print((char)176);("Date, Time, Temp, ThermT")
  Serial.println("");
  #endif  //end ECHO_TO_SERIAL
}

void printTemp(void)  {
  double tempValue = Temperature (analogRead(3));
  
  #if ECHO_TO_SERIAL
  Serial.print("Temperature is: ");
  Serial.print(tempValue,2);
  Serial.println((char)176); 
  Serial.println(""); 
  #endif  //end ECHO_TO_SERIAL
}
//--------------------------------------------------------------------------
void loop(void) {
  // make a string for assembling the data to log:
  String dataString = getDateDs1307();
  dataString += String(", ");
  String sensor2 = printDouble(Temperature (analogRead(3)),100);
  dataString += sensor2;
  dataString += ", ";
  String sensor1 = printDouble (Thermister(analogRead(0)),100);
  dataString += sensor1;
  dataString += ", ";
  
  #if ECHO_TO_SERIAL
  printTherm();
  printTemp();
  #endif
  
 File dataFile = SD.open("logger.csv", FILE_WRITE);
 
  if (dataFile) 
  {
    datafile.println(", , , ,");///just a blank line
    datafile.println("Date, Time, Temp, ThermT");
    datafile.close();
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    #if ECHO_TO_SERIAL
    Serial.println("Date, Time, Temp, ThermT");
    Serial.println(dataString);
    Serial.println("");
    #endif
  }  
  // if the file isn't open, pop up an error:
  else 
  {
    Serial.println("error opening test.csv");
  } 
  delay(20000);
}
//-------------------------------------------------------------------------------------
void setDateDs1307()                
{
  // Use of (byte) type casting and ascii math to achieve result.  
  second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48)); 
  minute = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  hour  = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  dayOfWeek = (byte) (Serial.read() - 48);
  dayOfMonth = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  month = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  year= (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(byte(0x00));
  Wire.write(decToBcd(second));  // 0 to bit 7 starts the clock
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));    // If you want 12 hour am/pm you need to set
  // bit 6 (also need to change readDateDs1307)
  Wire.write(decToBcd(dayOfWeek));
  Wire.write(decToBcd(dayOfMonth));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
  Wire.endTransmission();
}

String getDateDs1307()
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0x00);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  second     = bcdToDec(Wire.read() & 0x7F);
  minute     = bcdToDec(Wire.read());
  hour       = bcdToDec(Wire.read() & 0x3F);  
  dayOfWeek  = bcdToDec(Wire.read());
  dayOfMonth = bcdToDec(Wire.read());
  month      = bcdToDec(Wire.read());
  year       = bcdToDec(Wire.read());
  
  String dataString = "";
  
  dataString += Print2Digit(dayOfMonth); 
  dataString += String("/");
  dataString += Print2Digit(bcdToDec(month)); 
  dataString += String("/"); // Y2k1 bug!
  dataString += Print2Digit(bcdToDec(year));
  dataString += String(", ");
  dataString += Print2Digit(hour);
  dataString += String(":");
  dataString += Print2Digit(minute);
  dataString += String(":");
  dataString += Print2Digit(second);

  return dataString;
}
//-------------------------------------------------------------------------------------

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

String Print2Digit(byte Val)
{
  String dataString = "";
  if (Val < 10)
  {
    dataString = "0";
  }  
  dataString += String(Val, DEC);
  return dataString;
}