Relay does not switch off although Arduino sends the signal

Hi all!
I made my first Arduino project so I’m quite new to it and I ran into a problem. I made this humidifier project I found on Instructables so I used the wiring and the code mostly as I found there: https://www.instructables.com/Sky-Control-V1-Temperature-and-Humidity-Controller
I don’t have any temperature control connected, only a humidifier.
When I test the system without humidifer connected it seems to work totally fine.
However when I connect the humidifier (230V) to my relay at first it works fine but after a few times switching on and off the relay suddenly does not switch off anymore. The Arduino still sends the signal to switch off and the LED on the relay module switches off but the power still comes through and the humidifier just keeps going. Anybody an idea what is going on here?
Many thanks!!

#include <LiquidCrystal.h>
#include <DFR_Key.h>
#include <DHT.h>

//Starting values after boot up, you can change them
int temp = 5;
int hum = 80;


//For DHT22 (AM2023)
#define DHTPIN 15
#define DHTTYPE DHT22
const int relay2 =  18;
const int relay1 =  19;
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 
DFR_Key keypad;
int localKey = 0;
String keyString = "";
int lcd_key     = 0;
int adc_key_in  = 0;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons(){               
    adc_key_in = analogRead(0);
    if (adc_key_in > 1000) return btnNONE; 
    if (adc_key_in < 50)   return btnRIGHT;  
    if (adc_key_in < 250)  return btnUP; 
    if (adc_key_in < 450)  return btnDOWN; 
    if (adc_key_in < 650)  return btnLEFT; 
    if (adc_key_in < 850)  return btnSELECT;  
    
}             
void setup() 
{ 
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Sky control v1");
  lcd.setCursor(0, 1);
  lcd.print("Instr on Select");
  delay(2500);
  Serial.begin(9600);
  dht.begin();
  delay(1000);
  lcd.clear();
    
  //Sample rate (default 10 ms)
  keypad.setRate(10);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
}
void loop() 
{ 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(t) || isnan(h)) { //checking sensor operation
    lcd.begin(16, 2);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Sensor broken!!");
    delay(10000);
  } else {
    
    //You can change values (step) after each button press, default is 1'C for step and 5% humidity   
    lcd_key = read_LCD_buttons();
    switch (lcd_key){
       
       case btnLEFT:{
             temp = temp +1;
             delay (200);
             break;
       }
       case btnRIGHT:{
             temp = temp - 1;
              delay (200);
             break;
       }
       case btnUP:{
             hum = hum + 5;
              delay (200);
             break;
       }
       case btnDOWN:{
             hum = hum - 5;
              delay (200);
             break;
       }
       case btnSELECT:{
            lcd.begin(16, 2);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Hum Up/Down +-5%");
            lcd.setCursor(0, 1);
            lcd.print("Temp L/R +-1");
            lcd.print((char)223);
            lcd.print("C");
            delay (5000);
            break;
     }
  }   
    lcd.setCursor(0, 0);
    lcd.print("Hum: ");
    lcd.print(h);
    lcd.print("%");
    lcd.print("(");
    lcd.print(hum);
    lcd.print("%)");
    
    lcd.setCursor(0, 1);
    lcd.print("Tem: ");
    lcd.print(t);
    lcd.print((char)223);
    lcd.print("(");
    lcd.print(temp);
    lcd.print((char)223);
    lcd.print(")");

//adding this so the humidifier will not be powering on and off constantly (humidifier will exceed upper limit by 10% - IF YOU NEED EXACT VALUES COMMENT THIS SECTION AND UNCOMMENT NEXT !!           
      int H = hum + 10;    
      if(h < hum )
      digitalWrite(relay1, LOW);
      else if (h >= H)
      digitalWrite(relay1, HIGH);
      /* <- UNCOMMENT THIS IF YOU NEED EXACT VALUES BUT COMMENT 5 LINES ABOVE
      if(h < hum )
      digitalWrite(relay1, LOW);
      else
      digitalWrite(relay1, HIGH);
      */
      if(t < temp )
      digitalWrite(relay2, LOW);
      else
      digitalWrite(relay2, HIGH);
  }
}

Relay|397x499

Your topic has been moved here as this forum section is more appropriate than where it was originally posted.

Please take care to post in the correct forum section

Please post your code and a schematic of your project

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code

If the relay’s LED goes off, it sounds like it may be the relay contacts sticking, or the driver (less likely).

What current does the humidifier draw? Is it within the AC spec of the relay contacts ?

The humidifier works on 230V AC and the relay should be able to handle up to 250V AC. It is a cheap relay though so maybe that’s the problem?

Hi,
Welcome to the forum.

Can you post a link to where you bought the humidifier, or tell us what is on the info sticker on the humdifier, in particular A (Amps) and or W (Watts).
A picture of the sticker and humidifier would be good. :+1:

Thanks… Tom… :grinning: :+1: :coffee: :australia:

…and the relay rating A @ 230VAC

The relay rating is 10A 250V AC. It is a small humidifier that works with an AC/DC adapter (with output 24V DC and 2A) but the relay actually interrupts the extension cord that feeds the humidifier, before the adapter. I hope the pictures clarify it. The utility voltage is 230V here. Thanks for your input! I really appreciate it!

In my opinion these relays are not suitable for 220VAC. By the way why are you interrupting the 220VAC ?
With theese relays you should be interrupting the 24VDC output from your power supply to the humidifier.
Though that does not explain why the relays stay engaged. Can you confirm the output of the arduino with a digital multi meter ? Also can you confirm the voltage between the relay coil contacts ?

It’s curious that the relay LEDs are going in and off as expected.
That suggests the Arduino is ok, but the relay is kaput.

Those relays should be ok for <2A as indicated, but as pointed out it would be a lot safer in a hobby project if you switch the 24V to the humidifier. Leaving AC mains voltage laying around - especially on Chinese hobby components is a risk.

As mentioned, if the relay LEDs are doing what you expect, there’s something wrong with the relay module.

Proably. Only a check with a DMM can give a safe answer i think.

Hi,

As suggested, use a DMM to test the resistance between the COM and NO contacts that you are using.
Do this with ALL power OFF and the mains plug pull out of the wall socket.

Tom… :grinning: :coffee: :coffee: :australia:

Hi all!
So I followed your advice and I connected the 24V DC to the relay and now it works totally fine! The humidifier switches on and off whenever it should. The idea of connecting the extension cord was to easily modify the setup later on without having to cut wires again.
I measured with a DMM when everything was disconnected and the NO of the relay was still closed. This made me think the contacts were melted but then after waiting a few hours I measured again and then the NO was open again! So I’m guessing the module just can’t handle the main voltage.
Thanks for helping me out! I’m really happy it works now thanks to you all!

You are welcome !