EDIT: Here's a picture:
I'm building a curing chamber for tasty meat products.
I have a 12v relay board controlled by an Arduino Uno.
If Relay 1 gets a signal, it closes as intended.
If Relay 2 gets a signal, it closes as intended.
If Relay 3 gets a signal, it closes as intended.
But, if 1 and 2 get a signal, 3 closes and 1 and 2 stay open.
if 1 and 3 get a signal, 2 closes and 1 and 3 stay open.
It's weird, and I can't see where the coding is interacting.
Simply put, if my DHT22 registers a temp that is too high, then it turns on a relay(1) which powers a fan.
If the Humidity is too low, then it turns on a relay(2) which powers a fan.
If the Humidity is too high, then it turns on a relay(3) which powers a fan.
The Relay board is powered by an external 12v supply.
If any relay is individually triggered they work as intended, but if two are triggered, then the third relay closes while nothing happens to the relays I actually want to activate.
Any ideas?
Code:
//Libraries
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//Definitions
#define DHTPIN 3 // DHT pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define temLowTrigger 50
// Setting the trigger value for the temperture (in Farenheit),
// once the temperture higher than this trigger value, the fan runs
// 40F = 4.44C
// 39F = 3.88C
#define humLowTrigger 10
// Setting the trigger value for the LOW humidity,
// once the humidity lower than this value, start humidification
#define humHighTrigger 90
// Setting the trigger value for the HIGH humidity,
// once the humidity higher than this value, start DEhumidification
//Calls
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const int relay1 = 4; // the number of the relay 1 pin
const int relay2 = 5; // the number of the relay 2 pin
const int relay3 = 6; // the number of the relay 3 pin
//Variables
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
float f = dht.convertCtoF(temp);
void setup()
{
lcd.begin(20, 4);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("initializing...");
lcd.setCursor(0, 1);
delay(1000);
Serial.begin(9600);
dht.begin();
delay(1000);
lcd.clear();
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
}
void loop()
{
delay(2000); //delay 2 seconds
hum = dht.readHumidity();
temp = dht.readTemperature();
f = dht.convertCtoF(temp);
//Serial
Serial.print("Humidity: ");
Serial.print(hum, 1);
Serial.print(" %, Temp: ");
Serial.print(temp, 1);
Serial.print("C / ");
Serial.print(f, 1);
Serial.println("F");
//Display
lcd.setCursor(0, 0);
lcd.print("Humidity: ");
lcd.print(hum, 1);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(f, 1);
lcd.write(223);
lcd.print("F");
lcd.print("/");
lcd.print(temp, 1);
lcd.write(223);
lcd.print("C");
delay(8000); //Delay 8 sec.
//Code
//Temp
{
if (f > temLowTrigger)
{
digitalWrite(relay1, HIGH); //start cooling fan
lcd.setCursor(0, 2);
lcd.print(" !!!COOLING NOW!!!");
Serial.print("COOLING FAN ON | ");
}
else
digitalWrite(relay1, LOW);
}
//Humidify
{
if (hum < humLowTrigger) //if the humidity is lower than the trigger value
{
digitalWrite(relay2, HIGH); //start Humidification
lcd.setCursor(0, 3);
lcd.print("!!HUMIDIFYING NOW!!");
Serial.print("HUMIDIFIER FAN ON | ");
}
else
digitalWrite(relay2, LOW);
}
//DEHumidify
{
if (hum > humHighTrigger) //if the humidity is higher than the trigger value
{
digitalWrite(relay3, HIGH); //start DEHumidification
lcd.setCursor(0, 3);
lcd.print("!DE-HUMIDIFYING NOW!");
Serial.print("DE-HUMIDIFIER FAN ON | ");
}
else
digitalWrite(relay3, LOW);
}
}
