Time Corruption Using DHT Sensor Read

I have an official Uno and Ethernet Shield with a prototype board shield to read humidity and Temperature from a DHT22.

When I was testing the software without the Shields on another UNO, the time stamps were working fine. Once I loaded the sketch on the combo above, I am getting sporadic garbage on both my Serial Monitor and my web page.


Web page:
/+"

Humidity: 26.6%, Temp: 119.8° F, Set Point: 120 ° F, Status: Heater On


Monitor:

Ethernet WebServer Starting Up
Server is at 192.168.1.177
Humidity: 26.7 %, Temp: 119.3 Farenheit, Set Point: 90 Runtime: 00:00:02

Humidity: 26.7 %, Temp: 119.8 Farenheit, Set Point: 90 Runtime: 00:00:04

Humidity: 26.7 %, Temp: 119.8 Farenheit, Set Point: 90 Runtime: 00:00:06

Humidity: 26.7 %, Temp: 119.8 Farenheit, Set Point: 90 Runtime: 00:00:08

Humidity: 26.7 %, Temp: 119.8 Farenheit, Set Point: 90 ⸮⸮u⸮⸮⸮⸮

new client
Web page data sent, client disconnected
Humidity: 26.7 %, Temp: 119.8 Farenheit, Set Point: 120 Runtime: 00:00:12

When I comment out the lines:
humidity = dht.readHumidity(); //Read sensor data
tempC = dht.readTemperature();

the errors disappear. But the errors do not appear every time. I had a similar problem when I tried to use NTP time.

Obviously this newbie is doing something not quite right and any help will be much appreciated.

Code attached.

Kiln_Controler_Ethernet_TimeStamp.ino (12.4 KB)

I can reproduce the sporadic display errors on a just a UNO board with no shields.

I did not analyse your code in detail.
You are using globally defined variables of type String
globally defined variables of type String can cause memory-issues because they eat up all RAM-memory over time.

you are already using a char-array

char timeStamp[21];

define a structure that contains an array of char and then create an array of variables of this structure-type

//String timeStampString[arraySize];

typedef struct MyTimeStamp_type {
  char  MyTimeStamp[21];
} MyTimeStamp_type; 

MyTimeStamp_type TimeStamp_AoC[arraySize]  //suffix "AoC as short for "Array-Of-Char"

then writing yout time-stamp looks like this

    //char timeStamp[21];
    sprintf(TimeStamp_AoC[arrayPointer].MyTimeStamp, "Runtime: %02d:%02d:%02d", runHours, runMinutes, runSeconds);

and printing looks like this

  Serial.println(TimeStamp_AoC[arrayPointer].MyTimeStamp);

I installed the bounce2-library and your code compiled but there is a compiler-warning

Sketch uses 22602 bytes (70%) of program storage space. Maximum is 32256 bytes.
Global variables use 1651 bytes (80%) of dynamic memory, leaving 397 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

so maybe it is better to find a way to create your timestamp “on the fly” to save RAM
My idea about this is to create arrays for your variables runHours, runMinutes, runSeconds

3x int x 10 array elements = 3 x 2 x 10 = 60 bytes
compared to 10 x 23 = 230 bytes from the

Or just changing over to a ESP32-board which has much more RAM and Wifi on board

best regards Stefan
any newbee can apply the most professional habit from the first line of code they write on their own:
add only ONE thing at a time. Test/debug that ONE thing until that ONE thing works reliable - repeat.
The sad thing is: only the REAL professionals write code this way.

Thank you! I used arrays of the variables and created the sprintf on the fly. I need to keep the memory size in mind.

Is the problem solved?