data logger using 2 DHT22 and 6 ds18b20

good day everyone

ive been struggling using making an datalogger using ds1307 and sd card module. the problem is that when im using the ds18b20 sensors only, it works perfectly fine, but incorporating it with other sensors such as 2 dht22, the text file cannot be open based on the serial monitor's output. thanks in advance

here is the code for the program that i used.

#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "RTClib.h"
#include <DHT.h>




#define ONE_WIRE_BUS_PIN 5
#define DHTPIN1 3 
#define DHTPIN2 6


#define DHTTYPE1 DHT22 // DHT 22 (AM2302)
#define DHTTYPE2 DHT22 // DHT 22 (AM2302)
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif
OneWire oneWire(ONE_WIRE_BUS_PIN);
DHT dht1(DHTPIN1, DHTTYPE1);
DHT dht2(DHTPIN2, DHTTYPE2);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
File myFile;
int pinCS = 10; // Pin 10 on Arduino Uno
int chk;
float hum1;  //Stores humidity value
float temp1; //Stores temperature value
float hum2;  //Stores humidity value
float temp2; //Stores temperature value

DeviceAddress Probe01 = { 0x28, 0xFF, 0xBC, 0x3F, 0x71, 0x17, 0x03, 0xD0}; 
DeviceAddress Probe02 = { 0x28, 0xFF, 0x49, 0x42, 0x71, 0x17, 0x03, 0x91 };
DeviceAddress Probe03 = { 0x28, 0xFF, 0xE5, 0x8C, 0x83, 0x16, 0x03, 0xA9 };
DeviceAddress Probe04 = { 0x28, 0xFF, 0x79, 0x1D, 0x71, 0x17, 0x03, 0x57 };
DeviceAddress Probe05 = { 0x28, 0xFF, 0xB9, 0x3C, 0x71, 0x17, 0x03, 0x8A };
DeviceAddress Probe06 = { 0x28, 0xFF, 0x24, 0x19, 0xA0, 0x16, 0x05, 0x8B };


void setup() {
    
  Serial.begin(9600);
  pinMode(pinCS, OUTPUT);
   
  // SD Card Initialization
  if (SD.begin())
  {       sensors.begin();
        dht1.begin();
       dht2.begin();
        rtc.begin(); 
    Serial.println("SD card is ready to use.");
 
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 10);
  sensors.setResolution(Probe02, 10);
  sensors.setResolution(Probe03, 10);
  sensors.setResolution(Probe04, 10);
  sensors.setResolution(Probe05, 10);
  sensors.setResolution(Probe06, 10);
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
}
void loop() {
  // Create/Open file 
  myFile = SD.open("test.txt", FILE_WRITE);
   DateTime now = rtc.now();
    sensors.requestTemperatures(); 
    delay(2000);
    //Read data and store it to variables hum and temp
    hum1 = dht1.readHumidity();
    temp1= dht1.readTemperature();
    hum2 = dht2.readHumidity();
    temp2= dht2.readTemperature();
  // if the file opened okay, write to it:
  if (myFile) {
   
    
    myFile.println(now.year(), DEC);
    myFile.print('/');
    myFile.print(now.month(), DEC);
    myFile.print('/');
    myFile.print(now.day(), DEC);
    myFile.print(" (");
    myFile.print(daysOfTheWeek[now.dayOfTheWeek()]);
    myFile.print(") ");
    myFile.print(now.hour(), DEC);
    myFile.print(':');
    myFile.print(now.minute(), DEC);
    myFile.print(':');
    myFile.print(now.second(), DEC);

Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();

  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02);
  Serial.println();
 
  Serial.print("Probe 03 temperature is:   ");
  printTemperature(Probe03);
  Serial.println();
   
  Serial.print("Probe 04 temperature is:   ");
  printTemperature(Probe04);
  Serial.println();
  
  Serial.print("Probe 05 temperature is:   ");
  printTemperature(Probe05);
  Serial.println();

  Serial.print("Probe 06 temperature is:   ");
  printTemperature(Probe06);
  Serial.println();

  
    myFile.print("Humidity1: ");
    myFile.print(hum1);
    myFile.print(" %, Temp1: ");
    myFile.print(temp1);
    myFile.print(" Celsius");
    myFile.print("Humidity2: ");
    myFile.print(hum2);
    myFile.print(" %, Temp2: ");
    myFile.print(temp2);
    myFile.print(" Celsius");
    
    myFile.println();

  }
  // if the file didn't open, print an error:
  else {
    Serial.println("error opening test.txt");
  }
  // Reading the file
  
  delay(5000);
}
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   Serial.print(tempC);
   Serial.print(","); 
   myFile.print(tempC);
   myFile.print(",");
   }


}

DHT11 and DHT12 need 1-2 seconds before they can be sampled again.

You might need to check how much current the whole system is drawing?
Is it battery fed?

I don't know anything about DHT, and I don't know how the text file is based on the serial monior, but I think the file commands are suss. A safer approach is to have a properly contained subroutine.

void WriteSD()
{  
           myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
  myFile.print(hour);
  myFile.print(":");
  myFile.print(minute);
  myFile.print(":");
  myFile.print(second);
  myFile.print(",");

  myFile.print(InTemp);
  myFile.print(",");
  myFile.print(OutTemp);
  myFile.print(",");
  myFile.print(DrainTemp);
  myFile.print(",");
  myFile.println(ShrTemp);
       myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE     
}

You are constantly opening the file but not closing it at all.

I think that I need to communicate my experience:

1. SD Card alone works fine.
2. 2xDS18B20 + 1xDHT22 works fine.
3. SD Card + 2xDS18B20 + 1xDHT22 ; only DHT22 works!

But, I had the system few days ago that had been working with 2xDS18B20 + SD Card? Now, I can't re-produce the working condition!

I have been investigating the situation. I suspect that it could also be the power problem -- an issue that has been thought in Post#1.

It might be time to talk more meaningfully about power. I don't know why the DS18B20s would go out, I understand they run on practically nothing, but the SD consumes quite a bit and maybe is the straw that breaks the camel's back. Please don't tell us you are running this with a 9v PP3 battery.

My UNO board with SD+2xDS + DHT are powered by USB native port.

I am now going to power the board using external power supply and will report the result.

Thanks,

If you are waiting for the wall wart to arrive in the mail, you might try another computer. Your problem may not be that Arduino is too power hungry, more that that particular USB port is not up to the job. I don't think substandard USB ports are commonplace, but it has happened to me. There are cables that enable you to use two ports.