Hi, welcome to the forum.
Can you give a schematic of how everything is connected ?
Or a list of the used pins ?
Can you tell which SD module you have ? Some modules are only for 3.3V.
Can you tell what pressing the button is for ? Is that to safely remove the SD card ? Then you could show a message on the display to remove the SD card.
Intro
I can see the problem. To make everything run smooth and each part happily run on its own, you have to remove all the delay(). The main structure of the code is okay, but it needs some adjusting here and there. I prefer that the button does not use a long delay but uses a millis-timer.
LCD
The lcd.begin() should only be in setup(), not in the loop().
Updating text on a display is often done by adding extra spaces that clears the previous text. That means you don't need to clear the whole display, but work only on that part of the display.
DHT
You don't need three millis-timers for three DHT sensors. Just one millis-timer that collects data from all three will do. If you want to use them one after another, then you can do this:
int dhtCount;
void loop()
{
if( currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
switch( dhtCount)
{
case 0:
// do the first DHT sensor
break;
case 1:
// do the second DHT sensor
break;
case 2:
// do the third DHT sensor
break;
}
dhtCount++;
if( dhtCount > 2)
dhtCount = 0;
}
}
It is possible to make your own characters for the display.
I think that °C
is nicer than Celsius
.
Perhaps "29.3" is better than "29.30".
The humidity as "48.60" ? Would just "48" be enough ? The DHT sensor are not accurate.
Fan
The fan is just one fan, so it needs one millis-timer.
Remove the delay from the fan functions and use one millis-timer.
You can change the interval of a millis-timer or turn a millis-timer on and off. You can do whatever you want with a running or not-running millis-timer. I don't understand what the fan should do.
Scale
The scale has a delay of 250ms. Can you re-organize the code to avoid that delay ?
What about this:
millis-timer
{
power_up
do the scale thing
power_down
}
On the LCD display the text is "L_C val:". Would "Weight" be better ?
Button
Ten seconds delay after pressing a button ? That is so long ! That delay has to go completely, to let the sketch do all the other things.
You should start by debouncing the button, there are libraries for that.
Perhaps you also need the State Change Detection, but some debouncing libraries have that already.
Serial Monitor
There is no Serial.begin() and no Serial.println() in your sketch. I think you really need that and show a lot of messages to the Serial Monitor to know what is going on.
SD
If you write something every second to the SD card, then I would open and close that file every time.
This code is not okay:
if (Current_time >= timeLimit) {
dataFile.close(); //close the file
}
Can you explain what you wanted to do with that code ?