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);
}
}