My oled screen on arduino stucks on black screen after a few days working good

Guys my oled screen on arduino uno is stucked (black screen), after working properly for 4 days…I have DHT11 sensor One light and two fan coolers on it everything is using energy from relay so the arduino uno is not loaded. Its working properly but after some time it showing black screen and doesnt read any info from the sensor or turning on/off the relays. When i restart it its working properly again for some time.

YOUR HELP WILL BE VERY HELPFULL HERES THE CODE

#include <Adafruit_Sensor.h>   //include all libraries
#include <DHT.h>
#include <DHT_U.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define DHTPIN 7     // DHT DATA pin connected to Arduino pin no.2
#define DHTTYPE    DHT11  //DHT sensor type, DHT11 in our case

#define TEMPCOOL 4
#define HUMRL 3   //Arduino pin 3 connected to Humidity Relay
#define TEMPRL 2  //Arduino pin 2 connected to temperature Relay
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     4

DHT_Unified dht(DHTPIN, DHTTYPE);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

uint32_t delayMS;

void setup() {
 pinMode(HUMRL,OUTPUT);
 pinMode(TEMPRL,OUTPUT);
 pinMode(TEMPCOOL,OUTPUT);
 digitalWrite(HUMRL,HIGH);
 digitalWrite(TEMPRL,HIGH);
 digitalWrite(TEMPCOOL,HIGH);
 dht.begin();
 sensor_t sensor;
 dht.temperature().getSensor(&sensor);
 dht.humidity().getSensor(&sensor);
 delayMS = sensor.min_delay / 1000;
 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
   Serial.println(F("SSD1306 allocation failed"));
   for(;;); // Don't proceed, loop forever
   display.clearDisplay();
   display.display();
 }
}
void loop() {
 // Delay between measurements.
 delay(delayMS);
 display.clearDisplay();
 display.display();
 // Get temperature event and print its value.
 sensors_event_t event;
 dht.temperature().getEvent(&event);
 if (isnan(event.temperature)) {
   display.setTextSize(2);             // Normal 1:1 pixel scale
   display.setTextColor(WHITE);        // Draw white text
   display.setCursor(0,0);             // Start at top-left corner
   display.println(F("Error Reading Temperature"));
 }
 else {
   display.setTextSize(1);             // Normal 1:1 pixel scale
   display.setTextColor(WHITE);        // Draw white text
   display.setCursor(0,0);             // Start at top-left corner
   display.println(F("Temperature: "));
   display.print(event.temperature);
   display.println(F(" degC"));
   if(event.temperature <= 23){  //temperature greater than 30degC
     digitalWrite(TEMPRL,LOW); 
     display.setCursor(70,0);
     display.print(F("TEM RELAY"));
     display.setCursor(70,10);
     display.print(F("  ON"));
   }
   else{
     digitalWrite(TEMPRL,HIGH);
     display.setCursor(70,0);
     display.print(F("TEM RELAY"));
     display.setCursor(70,10);
     display.print(F("  OFF"));
   }
  if(event.temperature <= 25){ 
     digitalWrite(TEMPCOOL,HIGH); 
 }
 else {
   digitalWrite(TEMPCOOL,LOW);
 }
 }
 // Get humidity event and print its value.
 dht.humidity().getEvent(&event);
 if (isnan(event.relative_humidity)) {
   display.setCursor(0,30);
   display.println(F("Error reading humidity!"));
 }
 else {
   display.setCursor(0,30);
   display.println(F("Humidity: "));
   display.print(event.relative_humidity);
   display.println(F(" %"));
   if(event.relative_humidity >= 30){  
     digitalWrite(HUMRL,LOW);
     display.setCursor(70,30);
     display.print(F("HUM RELAY"));
     display.setCursor(70,40);
     display.print(F("  ON"));
   }
   else{
     digitalWrite(HUMRL,HIGH);
     display.setCursor(70,30);
     display.print(F("HUM RELAY"));
     display.setCursor(70,40);
     display.print(F("  OFF"));
   }
    if(event.temperature >= 26){
     digitalWrite(HUMRL,HIGH);
   }
 }
 display.display();
 delay(10000);

}[code]

[/code]

You really need to go and read the instructions for posting code (item No. 7) so that you can edit your first post there so it makes sense.

You also need to edit the subject of that first post to remove the foolish "I need help" and fix the stuck Caps Lock. Many of use will not even begin to help when you post in all caps.

TEMPCOOL and OLED_RESET are both 4. That seems odd (at best).

Thank you for making the corrections.

I am somewhat bewildered by the plethora of libraries you are using! If as you say, it was working for several days and then stopped, I have to say that the first step would be to go back to the sketch you originally used to test that the OLED was working correctly - and see if it still works. If it does not, you must necessarily back-track to see what has gone wrong with your connections or whether it is in some way damaged.

If it does in fact work,then you move forward through your previous additions to the project (you did keep them, didn't you?) to find the "sticking point".

I have a feeling it may be the relays, which means we will need to see both a diagram and photos of your setup (photos taken perfectly focused in outside daylight, not a dark room!) to understand how you have assemble this and where problems may be. :grinning: