[SOLVED] 4 channel Relay shield starts always ON

Hello everyone,
Having a problem with relays and cannot get the point.
I have 2 Arduino MKR1010 WiFi, latest Blynk library version, code with Arduino IDE on Mac OS.
On the first, I have a single relay connected just with Signal and GND pins, no VCC and works perfectly on Button Widget (Push/Switch) set to Digital Pin with no code, just declared the pin to be OUTPUT in the void setup.
On the second I have a 4 channel relay shield fully connected (VCC to VCC, GND to GND and Signal1-4 to D1-D4, won’t work without VCC pin). 4 widgets directly connected to D1-D4

void setup() {
  pinMode(1, OUTPUT);   
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

This code returns the relays to start HIGH and work inverted (button ON = relay LOW). I tried to

  • add digitalWrite(1, LOW) in the setup, but nothing change.

  • tried the opposite with digitalWrite(1, HIGH) in the setup, but again nothing change.

  • add digitalWrite(1, LOW) in the loop: relays starts HIGH and button in not responding (obviously).

  • switch 0-1 to 1-0 in the Widget and relays starts HIGH. Change to LOW after pushing the button twice (button ON->OFF).

  • declare the pins as INPUT or INPUT_PULLUP, but nothing worked.

  • do not declare any pinMode, but nothing changed.
    I tried to change the code linking the widget to a virtual pin like this

BLYNK_CONNECTED() {
  Blynk.syncVirtual(V5);
}
BLYNK_WRITE(V5) {
  digitalWrite(1, param.asInt());
}
void setup() {
  pinMode(1, OUTPUT); 

and I had exactly the same behavior, but if I switch 0-1 with 1-0 in the Widget the relay starts always HIGH but goes to LOW in a few seconds and then works correctly.

this happen after any reboot of the Arduino and it is of course not acceptable because those relays will switch on and off other Arduinos on demand. The only solution I could think is to switch NC to NO on the other side of relays, but this would mean keeping HIGH the relays for most of the time and I am on battery power… I don’t know what is the exact power consumption, but I think it’s not a good idea anyway.

I tried 3 different 4 channel relays modules and they all work the same.

Can you help me solve this? I’m at your disposal for further tests.

That’s a very bad idea, you will (sooner or later) like the digital pin on your Arduino, and (as you’ve discovered) the relay won’t work as it’s designed to.

Most relay boards are designed to be Active LOW, so you power them up and then the relays are activated by connecting the signal pins to GND.
This means that it’s a good idea to add a pinMode(OUTPUT) followed by a digitalWrite(HIGH) to ensure that the relays are off (the coils are not energised) initially.

When powering your relays, it’s a good idea to ensure that the VCC connection does not go via the circuitry on the Arduino, as the relays may draw more current than the onboard voltage regulator can provide. If your relays require 5v and you are powering your Arduino via USB then you will probably get away with tapping in to that USB power for a 4 relay board, provided you have a decent (2 amp) USB power supply.
If you go to larger relay boards (or start having reboot issues) then I’d suggest using a separate power supply for the relays.

Pete.

1 Like

Thanks for trying to helping me again Pete,

Actually this is the only one working correctly. It stays LOW all the time unless I push the in-app button or the loop launches a digitalWrite, which is exactly the behavior I want.
I know it’s not good to power it by the signal pin, in fact I arranged a terminal for power inlet. I didn’t connect it yet because I’m still completing it. Anyway the pin has to power the relay for 1 second twice a day, if the sky is clear, so I may consider leaving it this way.

Both Arduino and the 4-relays board are powered via a LM2596 3A step-down buck converter 12V → 3,3V. I tried also to power via the Arduino on first try: it work exactly the same, but on the sofa I was more comfortable :laughing:

Already tried to setup with the digitalWrite(HIGH), but nothing changed in the behavior: It start HIGH.
When I say “relay HIGH” I mean coil energised (the LED is ON, the Normally Open inlet has power, the Normally Closed has not)

Actually, I don’t think it is working as designed, for the reasons I outlined earlier, it’s just giving the results you are looking for because you are only powering the relay when you want it to be activated.

This is poor use of terminology. I think you mean that the relay remains de-energised unless the button is pressed.
You need to determine if your relay boards are expecting a LOW or a HIGH signal on their input pins to energise the relay coil. Do this by disconnecting them from the MCU and powering then via the VCC and GND pins, then connecting one of the signal pins to GND and VCC in turn. If connecting to the GND pin makes the LED light and the relay click on then the relay is active LOW. If this happens when the signal pin is connected to VCC then the relays are active HIGH.

Do this test and report back on your findings. I’d recommend doing it for both your single and double relay boards.

Pete.

1 Like

I did it:
The single one is Active HIGH, the 4x is Active LOW.

Okay, so you need to write your code for the 4-way relay in a way which sets the pins HIGH in void setup and LOW in your code that activates the relays.
If you’re doing this by direct (digital) pin manipulation in the app then you’ll need to change the button widgets to 1/0 instead of the default 0/1.
If you’re using virtual pins and BLYNK_WRITE(vPin) callbacks then you could also change the widget buttons in this way, but my preference is to keep them as standard and write the code in the BLYNK_WRITE accordingly.

I would also recommend changing the way your single relay is wired, as you do risk killing the board eventually.

Pete.

1 Like

Ok now it’s working.
I was very sure I already did the digitalWrite(HIGH); try, but it is evident I didn’t.
Now there is another problem: if I energise relays (one or more) via switch button, after few seconds (can be 3s, or 30s random) they automatically de-energise and become unresponsive for a while. The switch button remains ON and I have to Switch OFF manually.
Is it due to insufficient powering?
They are 5VDC relays and I tried powering them at both 3,3V and 5V without differences.
There is no code after setup because I’m now trying them directly on Digital Pin

Possibly.

I’d recommend you use virtual pins instead.

Pete.

Ok, I changed the code to virtual pins use.
The problem remains, but I had no problem when I was using them with LOW starting. They stayed on for an hour and more during mind was blowing, so I would not blame power (the buck is 3A maximum and I just have the arduino and the relays under it)

What does your code look like?

What do you see in your serial monitor?

Do you have any other widgets in your app?

Are both of your devices use different auth codes?

Pete.

#include <WDTZero.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>

char auth[] = "xxxx";
char ssid[] = "xxxx";
char pass[] = "xxxx";

BlynkTimer timer;
WDTZero MyWatchDoggy;

byte releMeteo_IN = 1;
byte releMeteo_OUT = 2;
byte releTetto = 3;
byte releMontatura = 4;

BLYNK_CONNECTED() {
  Blynk.syncVirtual(V5);
  Blynk.syncVirtual(V6);
  Blynk.syncVirtual(V7);
  Blynk.syncVirtual(V8);
}
BLYNK_WRITE(V5) {
  digitalWrite(1, param.asInt());
}
BLYNK_WRITE(V6) {
  digitalWrite(2, param.asInt());
}
BLYNK_WRITE(V7) {
  digitalWrite(3, param.asInt());
}
BLYNK_WRITE(V8) {
  digitalWrite(4, param.asInt());
}
BLYNK_WRITE(V127) {
  Meteo_INHb = param.asInt();
}
BLYNK_WRITE(V126) {
  Meteo_OUTHb = param.asInt();
}
BLYNK_WRITE(V125) {
  TettoHb = param.asInt();
}

void setup() {
  pinMode(A1, INPUT);   //input voltmetro
  pinMode(releMeteo_IN, OUTPUT);   //output rele
  pinMode(releMeteo_OUT, OUTPUT);
  pinMode(releTetto, OUTPUT);
  pinMode(releMontatura, OUTPUT);
  digitalWrite(releMeteo_IN, HIGH);
  digitalWrite(releMeteo_OUT, HIGH);
  digitalWrite(releTetto, HIGH);
  digitalWrite(releMontatura, HIGH);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  MyWatchDoggy.setup(WDT_HARDCYCLE16S);
  timer.setInterval(1000L, sendHeartbeat);
}
//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
void sendHeartbeat() {
  MyWatchDoggy.clear();
}
void loop() {
  Blynk.run();
  timer.run();
}

I was deleting from this answer the commented-out sections of the when I found out what was the problem: I also commented out the watchdog timer reset function
timer.setInterval(1000L, sendHeartbeat);
so it was actually working correctly for 16s then rebooting. Everything is working now.
Thanks for your patience,
Alessio

1 Like

You need to identify your relay module first, whether it is “low level triggered” or “high level triggered” relay module.

low level triggered = digitalWrite(relay, LOW) = turning on
= digitalWrite(relay, HIGH) = turning off

high level triggered = digitalWrite(relay, HIGH) = turning on
= digitalWrite(relay, LOW) = turning off


Don’t do this, please… if you “named” the pins, use that in your whole sketch, don’t mix…

:sweat_smile: you’re right!
I usually never name pins and those slipped in.