Help: Relays behaving weird when receiving multiple signals

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

}

There is nothing really wrong with your code, except a few extra curly braces. How do you have this all wired up? A schematic would be useful. Do you have all your grounds connected? How much current does it take to turn on your relay? An arduino pin can only supply a small amount.

There is nothing really wrong with your code, except a few extra curly braces.

I added those hoping to separate the three code sections (temp/humid/dehumid) from interacting with each other - unfortunately that didn't work!

How do you have this all wired up? A schematic would be useful.

Oof, that would be a lot of work - would a photo suffice? EDIT: HERE IT IS

Do you have all your grounds connected?

Yes for all 12v devices (the 3 fans and the 12v relay board).
The arduino only powers the DHT22 and the LCD screen.

How much current does it take to turn on your relay?

Hmmm... I'm not sure? This is the relay board, which this forum wont let me link to for some reason: https://www.amazon.ca/gp/product/B07S7DH6RN. I don't see any details to what the trigger level is. It definitely works though as I can trigger each relay individually, it's just sending more that one input that causes this, even if I add in delays to send inputs over time.

How many wires go from Arduino to the relay board? If using 3 relays there should be 4. That's why we need a wiring diagram, a pencil drawing would work.

How many wires go from Arduino to the relay board? If using 3 relays there should be 4.

o_0 Four wires? Huh, I only have 3 (one for each relay to be triggered. Power comes from a 12v wall wart).

How are the HIGH/LOW jumpers set on the relay board?

Little yellow jumpers:

LOW
COM
HEIGHT

I assume they meant HIGH not HEIGHT, but you can connect LOW to COM, or COM to HEIGHT

That's right, but which way do you have them set, COM to HIGH or COM to LOW? Your picture is too fuzzy to see where the two 12V wires are connected

I have them as they came as default: COM is connected to HIGH on each of the four jumpers

OK, you need a wire from the Arduino GND to the relay board DC- terminal along with the 12V - wire.

1 Like

OK, you need a wire from the Arduino GND to the relay board DC- terminal along with the 12V - wire.

SUCCESS!!! Wow, thanks so much! I would never have figured that out.

Why does the GND have to be connected to the Arduino? What was the issue? Is there any danger with having a 12v GND being connected to an arduino (it only handles up to 5v normally?)

Thanks again - this was a real headscratcher!

Well, electricity flows in a loop called a circuit, from the power source +, through the load and back to the source -. Now, your Arduino is sending the + to the relay board but there is no return path back to Arduino - (GND). Before you probably had a high resistance "sneak" path through one of the 12V loads.

As long as only the 12V GND and NOT the 12V + is connected, you're OK.

Now, your Arduino is sending the + to the relay board but there is no return path back to Arduino - (GND)

Of course! That makes total sense. Thanks again for your help!

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