4 Relay Firm with Cloud Function needed

Hello, can someone share a 4 ( standard) relay board firm for photon with cloud function?
thanks!

Hello, maybe this library could give you what you want?

Example 3 says: Internet Relays - Setting up functions so you can call relays over the internet!
Cheers,
Gustavo.
PS: you may need to plug your normal relays where the lib expects them (I think it’s D0, D1, D2, D3)

EDIT: as corrrectly pointed out below by @ScruffR (thank you!), it’s D3, D4, D5 and D6:
image

2 Likes

It’s actually D3, D4, D5 & D6 (also marked on the Relay Shield PCB)
Here are the Particle Relay Shield schematics
https://github.com/particle-iot/shields/blob/master/photon-shields/PDFs/Schematics/relay-shield-v310.pdf

1 Like

Done the library part
Can you help me with the publish / cloud functions IFTTT ?

thanks

The library examples show this already, so I’m not quite sure what the question is at this point.
What exactly do you want to do?
What have you tried already?
What isn’t working?

cloud function " turnrelay XX on"
turnrelay XX off

with the IFTTT Do buttons

Alright, that’s the “what do you want it to do?” part.

What have you tried so far to get that to work, and what are you having difficulties with?

The function does not appear published at IFTTT so I cannot create “Call a Function”

Solved, using internetrelays sample
Thanks !

hello, testing my 4 relay with relayshield library, all works fine, but
when the photon starts/reboot the relay starts High, what line I need to add so the relay starts Low ( off)

thanks

In your setup function, set that pin as LOW.
So you have pinMode(D3, OUTPUT) then DigitalWrite(D3, LOW). The exact syntax may be wrong since I’m doing this from my phone.

1 Like

can you tell me how to?

#include "RelayShield.h"

#define relay1 D3
#define relay2 D4
#define relay3 D5
#define relay4 D6

bool relays[5] = {false,false,false,false,false};

RelayShield::RelayShield(){
    
}

void RelayShield::begin(){
    pinMode(relay1, OUTPUT);
    pinMode(relay2, OUTPUT);
    pinMode(relay3, OUTPUT);
    pinMode(relay4, OUTPUT);
}

void RelayShield::on(uint8_t i){
    switch(i){
        case 1:
            digitalWrite(relay1, LOW);
            relays[1] = true;
            break;
        case 2:
            digitalWrite(relay2, LOW);
            relays[2] = true;
            break;
        case 3:
            digitalWrite(relay3, LOW);
            relays[3] = true;
            break;
        case 4:
            digitalWrite(relay4, LOW);
            relays[4] = true;
            break;
    }
    
}


void RelayShield::off(uint8_t i){
    switch(i){
        case 1:
            digitalWrite(relay1, HIGH);
            relays[1] = false;
            break;
        case 2:
            digitalWrite(relay2, HIGH);
            relays[2] = false;
            break;
        case 3:
            digitalWrite(relay3, HIGH);
            relays[3] = false;
            break;
        case 4:
            digitalWrite(relay4, HIGH);
            relays[4] = false;
            break;
    }
}

void RelayShield::allOn(){
    digitalWrite(relay1, LOW);
    relays[1] = true;
    digitalWrite(relay2, LOW);
    relays[2] = true;
    digitalWrite(relay3, LOW);
    relays[3] = true;
    digitalWrite(relay4, LOW);
    relays[4] = true;
}

void RelayShield::allOff(){
    digitalWrite(relay1, HIGH);
    relays[1] = false;
    digitalWrite(relay2, HIGH);
    relays[2] = false;
    digitalWrite(relay3, HIGH);
    relays[3] = false;
    digitalWrite(relay4, HIGH);
    relays[4] = false;
}

bool RelayShield::isOn(uint8_t i){
    return relays[i];
}

Try it like this:

If that doesn’t work, show up the share link from the exact new code you’ve tried and let us know what isn’t working.

1 Like

One thing to note here is that you are using default SYSTEM_MODE(AUTOMATIC) and hence the relays will always take the default state of the pin after power-up till you have actually established cloud connection, which will take some time before setup() will be executed.

To reduce that time, you can put your pin-setup into a STARTUP() macro which will be run as early as possible.
However, due to the pins used for the Particle Relay Shield there will always be a very brief moment for some of the pins being pulled HIGH due to their double-usage as JTAG pins on bootup.
Unfortunately there is no software way around that that doesn’t involve some major Device OS tweaks which would potentially break other things.

Consequently I’d advise to first test whether using STARTUP() (or any of the alternative SYSTEM_MODE() and SYSTEM_THREAD() settings) would give you an acceptable result.
If not, you could consider adding strong-pull resistors to the pins or as last resort reroute the relays to use different pins (e.g. any of the A# pins).

2 Likes

Perfecto, Thanks!