Mechanical relay module not working properly

I have mechanical relays that are connected properly to my arduino mega that turn on respectively a bulb and a misting pump (for a terrarium).

Both relays are working correctly at first. But the misting relay which is triggered by the humidity insidd the terrarium malfucntion after some cycles of high and low.
What's happening is that at some point the relay is triggered to let the current pass but it does not open the circuit anymore.
I can see the led light on the relay module lighting perfectly according to my code but the relay does not click and keeps passing the electricity.
I have a 5V relay and verified with a multimeter and can see that it is getting 4.9V from the arduino.
The pump is connect to the NO (normally open) pin of the relay module.
I tried to change the module and it works fine for some time and then it stops let tge current in enven when the led is off.
The probrem is that the pimp is over heat because it is triggering while I'm away from home.
Anyone has a suggestion to help solve the issue ?

Will a solid state relay be mechanically and electronically suitable?

Hello hajjoujti5

Welcome to the world's best Arduino forum ever.

Post your sketch, well formated, with comments and in so called code tags "< code >" and circuit diagram to see how we can help.

From your story it seems that the relay contacts for the pump are welded closed. This happens when switching an inductive load (pump), and you have forgotten to add a snubber circuit across the relay contacts.
Leo..

I'm new to arduino. I will try a solid state state relay and see if this works.

Basically the signal of the lamp relay is connected to PIN number 7 and the pump one to PIN number 8.

The lamp relay is functioning correctly so I won't post the code here.

below is the code for the pump control:

#include <DHT.h>

#define MISTING_RELAY_PIN 8

unsigned long mistingPreviousMillis = 0;
unsigned long mistingRelayStartMillis = 0;

DHT dht22Up(DHT22_PIN_UP, DHT22);
DHT dht22Down(DHT22_PIN_DOWN, DHT22);

void setup() {
  pinMode(MISTING_RELAY_PIN, OUTPUT);
  digitalWrite(MISTING_RELAY_PIN, LOW);
}

void loop() {
  checkHumidityAndMist(60.0, 80.0);
}

void checkHumidityAndMist(float humidityLowThreshold, float humidityHighThreshold) {
  unsigned long currentMillis = millis();

  if ((currentMillis - mistingPreviousMillis) >= HUMIDITY_CHECK_INTERVAL_AFTER_MISTING) {
    // Check humidity levels and if the relay is not already on
    if (currentHumidityUp < humidityLowThreshold && currentHumidityDown < humidityHighThreshold && !isMistingRelayOn) {
      mistingRelayStartMillis = currentMillis;  // Save the start time
      digitalWrite(MISTING_RELAY_PIN, HIGH);    // Turn on the relay
      isMistingRelayOn = true;
    }
  }

  // Check if the relay should be turned off
  if (isMistingRelayOn && ((currentMillis - mistingRelayStartMillis) >= MISTIN_RELAY_TURNED_ON_DURATION)) {
    digitalWrite(MISTING_RELAY_PIN, LOW);  // Turn off the relay
    isMistingRelayOn = false;
    mistingPreviousMillis = currentMillis;
  }
}

The pump needs 12V input and it is connected to a power supply that provides these 12V while being connected to 220VAC and the relay on NO pins.

I don't think they are welded close because at first it was working correctly and then it started only passing the current.
I did though tried to test it with the following code :slight_smile:

#define RELAY_PIN 8

void setup() {
  pinMode(RELAY_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  Serial.println("Turning relay ON");
  digitalWrite(RELAY_PIN, HIGH); // Turn relay on
  delay(5000); // Wait 5 seconds

  Serial.println("Turning relay OFF");
  digitalWrite(RELAY_PIN, LOW); // Turn relay off
  delay(5000); // Wait 5 seconds
}

The behaviour was weird. The first 2 iteration it was passing the current on high and low without ticking noise while the led was turning on for high and off for low.
After the 2nd iteration I heard a ticking noise and the relay started working properly.
I then re uploaded my original sketch for the pump it worked for 2 iterations and then back to always passing the current.

I'm not sure what you mean by snubber circuit and what it is used for. Can you provide a schema that explains how to connect it and what it does please?
I will try at first the proposition of @xfpd by using an SSR.