Relay Actuator On/Off Status Reversed



  • Hello,

    I am currently using the relay actuator sketch to control 6 relays for an irrigation control system using Vera (VeraLite, UI7, Ethernet gateway) but for some reason the on/off status of the devices is showing up in reverse in Vera (off when on and on when off). I could use the normally closed contacts on the relays to correct the problem but then the relays would be constantly on when the irrigation solenoids are off.

    Any suggestions on how to correct the problem are welcome, thanks.


  • Contest Winner

    @Myles-L

    Some relays that you buy on the web are so-called 'Active Low' which means they close when brought down to ground.

    Sounds like you may have that.



  • Thanks, I checked the relay specs and it is active low but so is the relay in the suggested buying guide. Is there a way to mod the sketch to send 5v to the active low modules so that the relay is only triggered when the voltage drops, correcting the reversed on/off indicator?


  • Contest Winner

    which sketch?



  • The relay actuator sketch 'RelayActuator.ino'

    // Example sketch showing how to control physical relays.
    // This example will remember relay state even after power failure.

    #include <MySensor.h>
    #include <SPI.h>

    #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1 // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay

    MySensor gw;

    void setup()
    {
    // Initialize library and add callback for incoming messages
    gw.begin(incomingMessage, AUTO, true);
    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Relay", "1.0");

    // Fetch relay status
    for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    gw.present(sensor, S_LIGHT);
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay to last known state (using eeprom storage)
    digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
    }
    }

    void loop()
    {
    // Alway process incoming messages whenever possible
    gw.process();
    }

    void incomingMessage(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.type==V_LIGHT) {
    // Change relay state
    digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
    gw.saveState(message.sensor, message.getBool());
    // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    }
    }



  • I changed the following to get mine to work. Not sure if it will work for you.

    @Myles-L said:

    define RELAY_ON 1 // GPIO value to write to turn on attached relay
    define RELAY_OFF 0 // GPIO value to write to turn off attached relay

    switch to
    define RELAY_ON 0 // GPIO value to write to turn on attached relay
    define RELAY_OFF 1 // GPIO value to write to turn off attached relay



  • Thanks, I did try that as it seemed like the logical choice but no success. now that I know it works I will be more persistent!



  • Works like a charm. For anyone else having the same problem I had to upload the sketch as normal, add the device to vera then modify the sketch using griffinsaic suggestion for it to work. Thanks again



  • I have been scratching my head wondering how to reverse the relay. Thank you


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.