The project has been running smoothly for several months and now it's crashing

Hi, for a few months the project of switching the fan based on indoor and outdoor humidity measurements worked well. All of a sudden, after restarting ARDUINO UNO, the fan starts only once, and reports a sensor reading error when the loop is finished. I replaced the sensors, I replaced the relay. And nothing. Does anyone have any ideas? Thank you

Kit: Arduino Uno, 2x DHT22 sensors, 5V relay module - 1 channel with level switch. The relay is connected to a 220V tubular fan.

Source code:

#include <DHT.h>

#define DHTPIN_OUT 2
#define DHTPIN_IN 3
#define DHTTYPE DHT22

DHT dht_outdoor(DHTPIN_OUT, DHTTYPE);
DHT dht_indoor(DHTPIN_IN, DHTTYPE);

const int RELAY_PIN = 7;

void setup() {
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
  
  Serial.begin(9600);
  dht_outdoor.begin();
  dht_indoor.begin();
}

void loop() {
  delay(60000); // 1 minute delay

  float outdoor_humidity = dht_outdoor.readHumidity();
  float indoor_humidity = dht_indoor.readHumidity();
  float indoor_temp = dht_indoor.readTemperature();

  if (isnan(outdoor_humidity) || isnan(indoor_humidity) || isnan(indoor_temp)) {
    Serial.println("Error reading data from sensors!");
    return;
  }

  Serial.print("Outdoor sensor - Humidity: ");
  Serial.print(outdoor_humidity);
  Serial.print("%  Temperature: ");
  Serial.print(dht_outdoor.readTemperature());
  Serial.print("°C\n");

  Serial.print("Indoor sensor - Humidity: ");
  Serial.print(indoor_humidity);
  Serial.print("%  Temperature: ");
  Serial.print(indoor_temp);
  Serial.print("°C\n");

  if (outdoor_humidity < 60.0 && indoor_humidity > 60.0) {
    digitalWrite(RELAY_PIN, HIGH);
    Serial.println("Relay switched ON");
    delay(1800000); // 30 minute delay
    digitalWrite(RELAY_PIN, LOW);
    Serial.println("Relay switched OFF");
  } else {
    digitalWrite(RELAY_PIN, LOW);
    Serial.println("Relay switched OFF");
  }
}

Serial monitor result after start:

Outdoor sensor - Humidity: 43.50% Temperature: 19.90°C
Indoor sensor - Humidity: 65.90% Temperature: 19.70°C
Relay switched ON
Relay switched OFF
Error reading data from sensors!
Error reading data from sensors!
Error reading data from sensors!
Error reading data from sensors!
Error reading data from sensors!

moderator edit: fixed tags

You will have to print the actual values of each of the sensor so you can tell is one or more is causing the error.

1 Like

Looks like switching noise from the relay is corrupting the DHT signals, what kind of snubber do you have across the fan motor terminals?

Hey, I have absolutely no idea. It's a VENTS TT 100. It is connected via a cable with a switch directly to the relay. VENTS TT 100 Centrifugal Inline Fan User Manual
When I turn the switch off, the relay switches normally and the DHT sensors work in loop. When I turn the switch on, it only runs 1xloop and then it goes into error. I don't understand that for a month it ran without problems and now it's having problems.
I replaced the relay and that didn't help either.

Why did you restart the arduino, had it stopped working, or did you intentionally turn it off while it was still working properly?
Have you moved any of the cables or components, or changed anything?

Have you replaced the UNO?

I disconnected the Arduinon because I needed to replace the power cable (splitter).
I didn't change anything, or rather since then I tried to move everything to other PINs, but also without success.

No, I replaced everything except UNO.

It worked for a long time, then stopped. You replaced everything but the UNO and it still does not work. I would suspect the UNO.
However, connect your fan directly to 220 and make sure it is working OK

Is there anything different about the new power cable?

Odds are, a schematic will reveal much.

nope


picture is ok?

Not really. Nothing obvious, from what I can observe, but. Is this how everything is arranged normally, or did you pull it together for the picture? The relay switching 220V within inches of your Uno is ill-advised, but not necessarily the source of your problem.

The UNO!

1 Like

I had a relay further away from UNO and the problems were the same.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.