Hi,
Im working on a project where I need to measure two temperatures over time to see the difference between the two.
I am storing this on an SD card once every five mins.
The idea is to leave the device outside recording for up to 72 hours.
I have an uno board, with a network shield on it, the network shield being only to give me access to the sd card without having to wire up some dodgy arrangement on a pro mini like I have done in the past, I want this to be a bit more rugged.
I have two lm335 sensors for temp,
The problem is that when running it from a 6v battery the voltage drop on the onboard regulator is quite high, I adjusted for this in code, and then the battery ran out in approx 30 hours, its a 6v 6ah sla battery. I would have expected it to easily last longer.
even though the battery technically lasted 30 hours, the voltage reference changed wildy and caused my reading to be incorrect. although the difference logged between the two sensors still seemed to be logical.
learning from the mistake, and with 30 hours of logged data I adjusted the multiplication factor in the code to bring both sensors as close to equal readings and actual room temp as possible, the nicked the battery bank from a mini solar system I have.
the second battery has a regulated 5v output, this is a 12v 7ah battery it only lasted for 30.5 hours, then the arduino can be seen to be power cycling, I know this as a header is saved to the sd card each time its powered up, along with an increment in a "file number" stored in eeprom that is saved in the header.
so given the fact it has a 5v regulated output, all the data is within the predicted temp ranges, but I have no way to tell the time between the data reads during the "low voltage" so it remains useless to me, although still indicative of a general temp curve, albeit without knowing the time over which the curve takes place.
So I would like to ask if there are any power saving tricks I can emply to make the battery last longer, I think a 7ah 12v sla battery should be enough to give me 48 - 72 hours of data logging on such a simple device, so Im sure that ive messed something up.
can any one give me any pointers?
here is my code :
/*
SD card datalogger
This example shows how to log data from three analog sensors
to an SD card using the SD library.
The circuit:
* analog sensors on analog ins 0, 1, and 2
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created 24 Nov 2010
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
#include <EEPROM.h>
//////////calibration
int outputPin3= A2;
int sensor3=0;
///////////eeprom
byte fileNumber;
byte newFileNumber=0;
int fileNumberWrite=0;
///////////sd card
const int chipSelect = 4;
int count=0;
/////////temperature
int outputPin1= 0;
float celsius1=0;
float kelvin1=0;
float sensor1=0;
float millivolts1=0;
int outputPin2= 1;
float celsius2=0;
float kelvin2=0;
float sensor2=0;
float millivolts2=0;
float difference=0;
void setup() {
//////////read eeprom file number
fileNumber = EEPROM.read(0);
newFileNumber= (fileNumber +1);
EEPROM.write(0, newFileNumber);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
Serial.println(newFileNumber);
}
void loop() {
///////////delay to adjust reading times
///////////calibration
// sensor3 = analogRead(outputPin3);
////////////sensor 1
sensor1 = analogRead(outputPin1);
//millivolts1= (sensor1/1024.0) * 3900;
// millivolts= analogRead(outputPin);
millivolts1 = (sensor1*4700.0)/1024.0;
kelvin1=millivolts1/10;
celsius1= kelvin1 - 273.15;
delay(200);
/////////sensor 2
sensor2 = analogRead(outputPin2);
millivolts2= (sensor2/1024.0) * 4685;
kelvin2=millivolts2/10;
celsius2= kelvin2 - 273.15;
difference= celsius1 - celsius2;
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
digitalWrite(13,HIGH);
if(fileNumberWrite==0){
dataFile.print("FIVE MINS : newFileNumber,");
dataFile.print(newFileNumber);
dataFile.println("NEGATIVE SHOWS HOTTER PLATE, POSITIVE SHOWS HOTTER GROUND");
dataFile.print("GROUND TEMP,");
dataFile.print("PLATE TEMP,");
dataFile.println("DIFFERENCE,");
fileNumberWrite=1;
Serial.println("file number updated");
}
//dataFile.println(millivolts);
dataFile.print(count);
dataFile.print(",");
count=count+1;
//dataFile.print(sensor3);
//dataFile.print(",");
dataFile.print(celsius1);
dataFile.print(",");
dataFile.print(celsius2);
dataFile.print(",");
dataFile.print(difference);
dataFile.println(",");
dataFile.close();
delay(100);
digitalWrite(13,LOW);
// print to the serial port too:
//Serial.println(millivolts);
Serial.println(celsius1);
Serial.println(celsius2);
// Serial.println(difference);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
delay(300000);
}