Extending the Relay capabilities - Request



  • Hello, I have been studying a lot of time and I got sensors work with MySensors, it is a great work you did! Thanks to all for all this hard work and great forum, it is really a wiki resource. I want to request your help to create two new sketches.
    1, I built the RelayActuator using six outputs, according to the instructions I change the number of relays to six and connect them to pins 3, 4, 5, 6, 7, 8, I cannot connect all the 8 relays of the board I buy. Can you create a sketch to connect 8 relays? Example using A0 to A7 as digital outputs.
    2 I built the RelayWithButtonActuator and it works swimmingly and it is very useful to replace my light switches but I would like to install the double and triple versions, as the home light switches everybody can found at home. Can you modifi the sketch to create a sketches with two bottons – two relays, and three buttons – three relays versions? That will be very useful to replace all my home light switches.
    Is it probably you are short of time, if so my apologies, please can you give me any idea what to modify in the sketches? Thanks in advance gracias


  • Contest Winner

    @Jimy-Aguirre said:

    1, I built the RelayActuator using six outputs, according to the instructions I change the number of relays to six and connect them to pins 3, 4, 5, 6, 7, 8, I cannot connect all the 8 relays of the board I buy. Can you create a sketch to connect 8 relays? Example using A0 to A7 as digital outputs.

    There are Array examples here on the forum that yes, you can use those Analog pins as outputs for the balance of the eight relays, sorta like this:

    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    #define NUMBER_OF_PINS 4
    
    MySensor gw;
    int buttonPin[NUMBER_OF_PINS] = {3,4,5,6};
    Bounce debouncer[NUMBER_OF_PINS] = Bounce();
    int oldValue[NUMBER_OF_PINS];
    MyMessage msg(0,V_TRIPPED);
    
    void setup() 
    {
      Serial.begin(115200);
      delay(1000);
      gw.begin(NULL, AUTO, false);
      gw.sendSketchInfo("RemoteControl", "1.05");
      gw.wait(250);
      for (int i = 0; i < NUMBER_OF_PINS; i++)
      {
        gw.present(i, S_LIGHT);
        pinMode(buttonPin[i], INPUT_PULLUP);
        debouncer[buttonPin[i]].attach(buttonPin[i]);
        debouncer[buttonPin[i]].interval(5);
        gw.wait(250);
      }
    }
    
    void loop() 
    {
      for (int i = 0; i < NUMBER_OF_PINS; i++)
      {
        debouncer[i].update();
        int value = debouncer[i].read();
        if (value != oldValue[i])
        {
          msg.setSensor(i);
          gw.send(msg.set(value));
          oldValue[i] = value;
        }
      }
    }
    


  • I have a "manually" sketch for relay, you may add any number of relays, choose the PINs you want on Arduino. Of course you are limited by the type of the board you are using. You just have to copy/paste the same code and change the relay number 1, 2, 3, 4 etc: https://github.com/Mihai258/HomeAssistant-MySensors-MQTT/blob/master/Single sensor/MySensorMQTT_REL/MySensorMQTT_REL.ino
    Of course you have also to take care about already used PINs (some of them are used for the NRF24 module, some for LEDs if case etc).


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts