logging data from 3 DHT-11 sensors getting intermittent nan readings

I’m using 3 dht-11 sensors to log data and i’m getting intermittent nan readings, is this possibly due to not enough time for the sensors to read? Do you need delays between them?

//Change NOTES
//Added senond schedual





#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,20,4);

// degree fahrenheit
byte newChar[8]= {
  B01100,
  B10010,
  B10010,
  B01100,
  B00000,
  B00000,
  B00000,
  B00000
};

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

#define ECHO_TO_SERIAL 1 // echo data to serial port
#define PHOTOCELLPIN 8           // analog 0
#define chipSelect 53            // for the data logging shield, we use digital pin 10 for the SD cs line
#define cardFailPin 37
#define DHTTYPE DHT11            // DHT 11  
#define DHTPIN_outside 40
#define DHTPIN_attic 36
#define DHTPIN 44  // The DHT output is connected to digital pin 7.
DHT dht(DHTPIN, DHTTYPE); //define the DHT object
DHT dht_attic(DHTPIN_attic, DHTTYPE);
DHT dht_outside(DHTPIN_outside, DHTTYPE);

//------------------------------
const int Relay =  47;      // the number of the LED pin
int swState =0;
// Variables will change:
int relayState = HIGH;             // ledState used to set the LED
//---------------------------------------------Relay without delay
long previousMillis = 0;        // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long intervala = 210000; 
long intervalb = 210000; 
//------------------------------
RTC_DS1307 RTC; // define the Real Time Clock object
File fileData;                          // the logging file on the SD card
unsigned long ulintMillis = 0;              // milliseconds since start
int TempSens = 95;
int intPhotocellreading = 0;
int light_sensitivity = 995;
int humidity_sensitivity = 35;
float atticHumidity = 0;
float atticTemp = 0;
float outsideHumidity = 0;
float outsideTemp = 0;
float fHumidity = 0;
float fTemp = 0;
const unsigned long ulintLoginterval = 10000;       //------------------------------SD LOG interval

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
}

void setup() //--------------------------------------------------------Setup-----------------------------------------
{
  //-------------------------------------------------------------------Pins-----------------------------------------
  pinMode(Relay, OUTPUT);  //Relay 
  pinMode(DHTPIN, INPUT);
  pinMode(PHOTOCELLPIN, INPUT);
  pinMode(chipSelect, OUTPUT);
  pinMode(cardFailPin,OUTPUT);

  Serial.begin(9600);
  Serial.println("Millis, Date , Time , Light , Roof Humidity , Roof Temp, Humidity Attic, Attic Temp,Outside Humidity,Outside Temp");
  //-----------------------------------------------------------------------LCD----------------------------------------  
  lcd.init();
  lcd.backlight();
  lcd.createChar(1, newChar);
  lcd.clear();
  lcd.setCursor(6,0);
  lcd.print("TEMP");
  lcd.setCursor(4,1);
  lcd.print("HUMIDITY");

  if (!SD.begin(chipSelect)) 
  {
    error("Card failed, or not present, or datalog.csv file not present");
  }
  //Serial.println("card initialized.");
  fileData = SD.open("datalog.csv", FILE_WRITE);
  // connect to RTC
  Wire.begin();  
  if (!RTC.begin()) 
  {
    fileData.println("RTC failed");
#if ECHO_TO_SERIAL
    error ("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
  dht.begin();    // Start reading from the  temperature and humidity sensor
  if (fileData)
  {
    fileData.println("Millis , Date , Time, Light, Roof Humidity ,Roof Temp, Attic Humidity,Attic Temp,Outside Humidity,Outside Temp");
  }
  else
  {
    error("Could not write to file.");
    if (error)
      digitalWrite(cardFailPin,HIGH);  
  }
}

void loop(void)//-----------------------------------------------------------------------------LOOP-----------------------------------------
{
  DateTime now; 

  // delay for the amount of time we want between readings
  delay((ulintLoginterval -1) - (millis() % ulintLoginterval));

  // log milliseconds since starting
  ulintMillis = millis();
  fileData.print(ulintMillis);           // milliseconds since start
  fileData.print(", ");
  //  if (error)
  //  digitalWrite(cardFailPin,HIGH);  
#if ECHO_TO_SERIAL
  Serial.print(ulintMillis);         // milliseconds since start
  Serial.print(", ");  
#endif
  // fetch the time
  now = RTC.now();
  // log time
  fileData.print(now.year(), DEC);
  fileData.print("/");
  fileData.print(now.month(), DEC);
  fileData.print("/");
  fileData.print(now.day(), DEC);
  fileData.print(",");
  fileData.print(now.hour(), DEC);
  fileData.print(":");
  fileData.print(now.minute(), DEC);
  fileData.print(":");
  fileData.print(now.second(), DEC);

#if ECHO_TO_SERIAL
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(",");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL

  intPhotocellreading = analogRead(PHOTOCELLPIN);  

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  delay(250);
  fHumidity = dht.readHumidity();
  fTemp = dht.readTemperature(true);
  atticHumidity = dht_attic.readHumidity();
  atticTemp = dht_attic.readTemperature(true);
  outsideHumidity = dht_outside.readHumidity();
  outsideTemp = dht_outside.readTemperature(true);

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(fHumidity) || isnan(fTemp))
  {
    Serial.println("Failed to read from DHT");
  }

  fileData.print(", ");    
  fileData.print(intPhotocellreading);

#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(intPhotocellreading);      //
#endif //ECHO_TO_SERIAL

  fileData.print(", ");    
  fileData.print(fHumidity);

#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(fHumidity);
#endif //ECHO_TO_SERIAL

  fileData.print(", ");    
  fileData.print(fTemp);

#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(fTemp);
#endif //ECHO_TO_SERIAL

  //------------------------------------------temp Attic

  fileData.print(", ");    
  fileData.print(atticHumidity);

#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(atticHumidity);
#endif //ECHO_TO_SERIAL

  fileData.print(", ");    
  fileData.print(atticTemp);

#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(atticTemp);
#endif //ECHO_TO_SERIAL

  //---------------------------------------temp outside

  fileData.print(", ");    
  fileData.print(outsideHumidity);

#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(outsideHumidity);
#endif //ECHO_TO_SERIAL

  fileData.print(", ");    
  fileData.print(outsideTemp);

#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(outsideTemp);
#endif //ECHO_TO_SERIAL
  //-----------------------------------------
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("R ");
  lcd.print(fTemp);
  lcd.write(1);
  lcd.setCursor(9,0);
  lcd.print("R ");
  lcd.print(fHumidity);
  lcd.print("%");
  lcd.setCursor(0,1);
  lcd.print ("O ");
  lcd.print(outsideTemp);
  lcd.write(1);
  lcd.setCursor(9,1);
  lcd.print("O ");
  lcd.print(outsideHumidity);
  lcd.print("%");
  lcd.setCursor(0,2);
  lcd.print("A ");
  lcd.print(atticTemp);
  lcd.write(1);
  lcd.setCursor(9,2);
  lcd.print("A ");
  lcd.print(atticHumidity);  
  lcd.print("%");
  unsigned long currentMillis = millis();
  //inthumidity = fHumidity;=============================>
  
    if ((intPhotocellreading > light_sensitivity)&&(fHumidity < humidity_sensitivity)&&(fTemp>TempSens))
   {
   digitalWrite(Relay, relayState);
   }

   if(currentMillis - previousMillis > intervala)
   {
   previousMillis = currentMillis;   
   intervala = 1080000 - intervala;
   relayState = digitalRead(Relay);
   }
   if (relayState == LOW)
   {
   relayState = HIGH;
   }
   else
   {
   relayState = LOW;
   }
   if(swState == LOW)
   {
   digitalWrite(Relay, LOW);
   }
  
   if (digitalRead(Relay) == HIGH)
   {
   fileData.print(", ");    
   fileData.print("Sprinkler #2 ON"); 
   } 
   
  if ((intPhotocellreading > light_sensitivity)&&(fHumidity < humidity_sensitivity))
  {
    digitalWrite(Relay, relayState);
  }

  if(currentMillis - previousMillis > intervalb) 
  {
    previousMillis = currentMillis;   
    intervalb = 2160000 - intervalb;
    relayState = digitalRead(Relay);
    if (relayState == LOW)
    {
      relayState = HIGH;
    }
    else
      relayState = LOW;
    {
      digitalWrite(Relay, LOW);
    }
  }

  if (digitalRead(Relay)== HIGH)
  {
    fileData.print(", ");    
    fileData.print("Sprinkler #1 ON"); 
    Serial.print(", ");    
    Serial.print("Sprinkler #1 ON");
  }


  fileData.println();

#if ECHO_TO_SERIAL
  Serial.println();
#endif // ECHO_TO_SERIAL
  fileData.flush();
}

The DHT needs minimal 2 seconds between readings. (DHT11 needs 1 second IIRC)

would that be done here

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  fHumidity = dht.readHumidity();
  fTemp = dht.readTemperature(true);
  atticHumidity = dht_attic.readHumidity();
  atticTemp = dht_attic.readTemperature(true);
  outsideHumidity = dht_outside.readHumidity();
  outsideTemp = dht_outside.readTemperature(true);

like this

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  
  fHumidity = dht.readHumidity();
  fTemp = dht.readTemperature(true);
  delay(2000);
  atticHumidity = dht_attic.readHumidity();
  atticTemp = dht_attic.readTemperature(true);
  delay(2000);
  outsideHumidity = dht_outside.readHumidity();
  outsideTemp = dht_outside.readTemperature(true);
  delay(2000);

or

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  fHumidity = dht.readHumidity();
  delay(1000);
  fTemp = dht.readTemperature(true);
  delay(1000); 
  atticHumidity = dht_attic.readHumidity();
  delay(1000);
  atticTemp = dht_attic.readTemperature(true);
  delay(1000);
  outsideHumidity = dht_outside.readHumidity();
  delay(1000);
  outsideTemp = dht_outside.readTemperature(true);
  delay(1000);

It would be best done without any delay()s. Use millis() to determine if it is time to take another reading, as in the blink without delay example.

You should be able to read the three sensors one right after each other, but delay at least 2 seconds before the next group read so that no one sensor is read more often than 2 seconds.

Hi friends

I am trying to read the maximum dht11 (i power it with 3.3V or 5v) sensors with arduino uno and sd card.
As i am a begginer can someone help with the a program, I found 2 or 3 but when I try changing it for reading more, the errors starts one after other..

Best regards
cpalha

but when I try changing it

Changing what? To what?

for reading more

How many is that?

the errors starts one after other..

Nice of them to form a neat line. What errors are you talking about?

Hi PaulS

I receive recently 10 DHT11 sensors (5 + 5) and I would to control a historical build by measuring temp and hum in diferent places and save it to a 4gb sd card.
O have done some experiences and I have success to write data into sd card.

I tryed connect one SHT11 and it gives readings, now I would like to change a code for reading more than one (the sd card uses 4 digital pins, can i use others to connect DHT11 sensors?)

Thanks
cpalha

can i use others to connect DHT11 sensors?

Sure looks that way.

Hi PaulS

Thanks for the video.
If arduino as 14 digital I/O, and Iam using 4 for the sdcard, means that I can use the other 10 for the sensors?

Can you change the code for 10 sensors?

cpalha

means that I can use the other 10 for the sensors?

Yes. Though not using pins 0 and 1 is a good practice. You can use the analog pins as digital pins, too. A0, A1, etc.

Can you change the code for 10 sensors?

Yes, I can. What code?

Hi PaulS

If I can use 8 is good.

This webpage has a good example, but has display (I dont need it), limit the sd card to 2gB, mine is 4gb

This one is for 3 analog sensors but it worked with mine sdcard

/*
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 <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it’s not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.print(“Initializing SD card…”);
// make sure that the default chip select pin is set to
// output, even if you don’t use it:
pinMode(10, OUTPUT);

// 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.”);
}

void loop()
{
// make a string for assembling the data to log:
String dataString = “”;

// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += “,”;
}
}

// 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) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn’t open, pop up an error:
else {
Serial.println(“error opening datalog.txt”);
}
}

Please use [ code ] tags, it is the # above the smileys (tip you can modify existing posts too)

I am all for boycotting these sensors. While I am an arduino beginner, I have used and replaced a few DHT11's due to their complete inaccuracy. If you don't want to fork out for one of the more expensive humidity sensors, look into making a wet/dry bulb thermometer using ds18b20 temperature sensors. Cheaper, more accurate, more reliable, but a bit more cumbersome

Hoppe this resolve the problem about code.
Can some one help me please? To start a new code for DHT11 sensors (many) and save data into sdcard?

/*
  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 <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // 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.");
}

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ","; 
    }
  }

  // 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) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
}

There is a DHT11 library. Why are you not using it? Use it, and getting the data from n sensors is as easy as getting data from one.

Hi PaulS

Speaking is too easy, as I told you I am a begginer in arduino, I have some experience in labview and NI daqs.

This is completly diferent. Library? I thought library is like a driver for each kind of sensor no more…

I finished the program to read 1 sensor and store data in sd card, it works good, can you please help me to change it for more sensors? Please.

This sensor has decimal numbers? Why it gives 2 decimal places .00 ? If the sensor dont has decimal why the code writes 2 “00”?

Best
cpalha

//sensor liga dig pin 2 e alimentado a 3.3v

#include <DHT11.h>
#include <SD.h>
int pin=4;
const int chipSelect = 4;
DHT11 dht11(2); 

File dataFile;

void setup()
{
  Serial.begin(9600);

if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1) ;
  }
  Serial.println("card initialized.");
  
  // Open up the file we're going to log to!
  dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (! dataFile) {
    Serial.println("error opening datalog.txt");
    // Wait forever since we cant write data
    while (1) ;
  }
}

void loop()
{
  int err;
  float temp = 0, humi;
  if((err=dht11.read(humi, temp))==0)
  {
    Serial.print("temperature:");
    Serial.print(temp);
    Serial.print(" humidity:");
    Serial.print(humi);
    Serial.println();
    dataFile.print(temp);
    dataFile.print("  ");
    dataFile.print( humi);
    dataFile.println();
    dataFile.flush();
  }
  else
  {
    Serial.println();
    Serial.print("Error No :");
    Serial.print(err);
    Serial.println();    
  }
  delay(5000); //delay for reread
}
DHT11 dht11(2);

Do you know what the value in the parentheses means? If it’s a pin number, make copied of this line, changing the instance name and the pin number.

You can probably see that calling the instance dht11 doesn’t give it a meaningful name.

  if((err=dht11.read(humi, temp))==0)
  {
    Serial.print("temperature:");
    Serial.print(temp);
    Serial.print(" humidity:");
    Serial.print(humi);
    Serial.println();
    dataFile.print(temp);
    dataFile.print("  ");
    dataFile.print( humi);
    dataFile.println();
    dataFile.flush();
  }

Here, you read from that one instance, and write to the file. Simply repeat this block for each of the other sensors.

You can make the code not much longer by making this a function, and passing the instance to the function.

You could make the code no longer by making an array of instances, and looping through the array, calling the function. Since the array of instances is global, all you’d need to pass to the function is the index into the array, rather than the instance at the nth position in the array.

Hi PaulS

In a few messages back you said

Quote
Can you change the code for 10 sensors?
Yes, I can. What code?

Best
CPalha

Hi friends

Here is my code for 5 DHT11 sensors. It takes readings each 10 minutes and writes in SDcard.

/*
  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 10
 
 created  24 Nov 2010
 modified 9 Apr 2012
 by Tom Igoe
 modified fev2014 by cpalha
 v3 - writes a unique line for 5 sensores
 v4 - data sparated for excel
 v5 - time in min, readings each 10 min
*/
//sensor liga dig pin 2 e alimentado a 3.3v

#include <DHT11.h>
#include <SD.h>
int pin=10;
const int chipSelect = 10;
const int interval = 10*1000; // the interval between reads, in ms
long lastReadTime = 0;        // the last time you read the sensor, in ms
DHT11 dht11(2); 
DHT11 dht12(3); 
DHT11 dht13(4);
DHT11 dht14(5);
DHT11 dht15(6);

File dataFile;

void setup()
{
   Serial.begin(9600);

if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1) ;
  }
  Serial.println("card initialized.");
  
  // Open up the file we're going to log to!
  dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (! dataFile) {
    Serial.println("error opening datalog.txt");
    // Wait forever since we cant write data
    while (1) ;
  }
}

void loop()
{
   // Get the current time in ms:
  long currentTime = millis();
  if (currentTime > lastReadTime + interval){
  int err;
  float temp, humi;
  if((err=dht11.read(humi, temp))==0)
  {
    Serial.print(currentTime/60000);
    Serial.print(" min.");
    Serial.print("\t");
    Serial.print("temp.:");
    Serial.print(temp);
    Serial.print(" humid.:");
    Serial.print(humi);
    dataFile.print(currentTime/60000);
    dataFile.print(" min.");
    dataFile.print(" ");
    dataFile.print(temp);
    dataFile.print(" ");
    dataFile.print( humi);
    dataFile.flush();
    lastReadTime = millis();
    delay(5000);
  }
   {
   int err;
  float temp, humi;
  if((err=dht12.read(humi, temp))==0)
  {
    
    Serial.print("\t");
    Serial.print("temp.:");
    Serial.print(temp);
    Serial.print(" humid.:");
    Serial.print(humi);
    dataFile.print(" ");
    dataFile.print(temp);
    dataFile.print(" ");
    dataFile.print( humi);
    dataFile.flush();
    lastReadTime = millis();
    delay(5000);
  }
  
  {
   int err;
  float temp, humi;
  if((err=dht13.read(humi, temp))==0)
  {
    
    Serial.print("\t");
    Serial.print("temp.:");
    Serial.print(temp);
    Serial.print(" humid.:");
    Serial.print(humi);
    dataFile.print(" ");
    dataFile.print(temp);
    dataFile.print(" ");
    dataFile.print( humi);
    dataFile.flush();
    lastReadTime = millis();
    delay(5000);
  }
  
  {
   int err;
  float temp, humi;
  if((err=dht14.read(humi, temp))==0)
  {
    
    Serial.print("\t");
    Serial.print("temp.:");
    Serial.print(temp);
    Serial.print(" humid.:");
    Serial.print(humi);
    dataFile.print(" ");
    dataFile.print(temp);
    dataFile.print(" ");
    dataFile.print( humi);
    dataFile.flush();
    lastReadTime = millis();
    delay(5000);
  }
  
  {
   int err;
  float temp, humi;
  if((err=dht15.read(humi, temp))==0)
  {
    
    Serial.print("\t");
    Serial.print("temp.:");
    Serial.print(temp);
    Serial.print(" humid.:");
    Serial.print(humi);
    Serial.println();
    dataFile.print(" ");
    dataFile.print(temp);
    dataFile.print("  ");
    dataFile.print(" ");
    dataFile.print( humi);
    dataFile.println();
    dataFile.flush();
    lastReadTime = millis();
    delay(5000);
  }
  
  
    else
  {
    Serial.println();
    Serial.print("Error No :");
    Serial.print(err);
    Serial.println();    
  }
  delay(600000); //delay for reread
}
}
}
}
}
}

I let it take readings since yesterday and with a 9V battery, it works only 10 houres :slight_smile:
I expected weeks for battery duration…

Best regards
CPalha