Yes, interesting. The max positive value of an int = 32,767
An easy test might be to just comment out the readings for year, month and day. Then see if the time at which the peak occurs is extended.
//readings.print(t.year); // Years
readings.print(","); // Equivalent to "TAB", moves to the next horizontal cell
//readings.print(t.mon); // Months
readings.print(",");
//readings.print(t.date); // Day of the month
readings.print(",");
Another test. Here, a millis() timer is used instead of delay() for your 15 second reading interval
// Oxygen content reading in real-time with ME2-O2 Sensor, LCD screen, RTC and SD logging data - ACTIVATION (QUICK VERSION)
// Libraries
#include <LiquidCrystal.h> // Includes the libraries for the LCD
#include <DS3231.h>; // Includes the libraries for the clock
#include <SPI.h>; // Includes the libraries for the Serial Peripheral Interface that allows the Master (Arduino) to control a slave device
#include <SD.h>; // Includes the libraries for the SD card
// Interface and Objects definitions
DS3231 rtc(SDA, SCL); // Initialises the DS3231 using the hardware interface
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Creates a LCD LiquidCrystal object
const int chipSelect = 10; // Assigns the pin for the SPI-SD chip selection
unsigned long previousMillis = 0;
const word interval = 15000; // Defines the time step of the readings (milliseconds)
void setup()
{
pinMode(chipSelect, OUTPUT); // Ensures that the SPI-SD selection pin is an output
rtc.begin(); // Initialises the rtc object
// rtc.setTime(10, 51, 05); // Sets the time HH:MM:SS (24hr format)
// rtc.setDate(15, 2, 2017); // Sets the date DDMMYYYY
lcd.begin(16, 2); // Initialises the interface to the LCD screen, and specifies the dimensions
// Initialising sensor and SD card:
// lcd.print("Initialising SD");
// delay (5000); // Waits 5 seconds
lcd.clear(); // // Clears the LCD screen and positions the cursor in the upper-left corner
if (!SD.begin(chipSelect)) // Checks if the SD card is working
{
lcd.println("SD failed!");
delay(6000);
return;
}
//lcd.println("SD OK");
//delay(1000);
//lcd.clear();
//lcd.print("Reading sensor"); // Prints to the LCD "Reading sensor"
//delay (1000);
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
File readings = SD.open("readings.csv", FILE_WRITE); // Opens the file on the SD card
// Defining the sensor variables:
float sensorValue;
float sensorVoltage;
float SensorVoltageADJ;
float OxygenCont;
sensorValue = analogRead(A2);
sensorVoltage = (sensorValue / 1024) * 5.0; // It adapts the output with a fraction of 0-5V input from Arduino Voltage. In V.
SensorVoltageADJ = sensorVoltage / 344 * 1000; // I am getting rid of the OPAmp. We can use this in the characteristic curve provided with the sensor. In mV.
OxygenCont = SensorVoltageADJ * 20.95 / 5.90; // Calibration with reference to standard condition (linear interpolation)
if (isnan(sensorValue)) // Checks if any reads failed and exit early (to try again)
{
lcd.println("Sensor FAIL!");
delay(6000);
return;
}
lcd.clear();
if (readings) // If the file opened OK, write to it on SD card
{
Time t = rtc.getTime(); // Defines a structure for the date and time
readings.print(t.year); // Years
readings.print(","); // Equivalent to "TAB", moves to the next horizontal cell
readings.print(t.mon); // Months
readings.print(",");
readings.print(t.date); // Day of the month
readings.print(",");
readings.print(t.hour); // Hours
readings.print(",");
readings.print(t.min); // Minutes
readings.print(",");
readings.print(t.sec); // Seconds
readings.print(",");
readings.println(OxygenCont); // Using the characteristic curve provided with the sensor to output the Oxygen % HP: linear from zero
readings.close(); // close the file to save the data on the SD card
}
else // if the file didn't open, print an error
{
lcd.println("FILE NOT OPEN");
delay(6000);
}
// Printing the results on the LCD screen with time and date:
lcd.print("Oxygen: "); lcd.print(OxygenCont); lcd.print("%");
} // end interval
} // end loop