Skip to content
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Announcements
  3. 💬 Relay
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

💬 Relay

Scheduled Pinned Locked Moved Announcements
139 Posts 47 Posters 33.7k Views 45 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • fdojuradoF Offline
    fdojuradoF Offline
    fdojurado
    wrote on last edited by
    #12

    I would like to ask about ack. Does the library have a specific timeout? Does the library resends the message when ack is not received? Thank you.

    1 Reply Last reply
    0
    • Puneit ThukralP Offline
      Puneit ThukralP Offline
      Puneit Thukral
      wrote on last edited by
      #13

      Cam I use an arduino pro mini 3.3V 8 Mhz to trigger the relay - or do I need a 5v arduino?

      sundberg84S 1 Reply Last reply
      0
      • Puneit ThukralP Puneit Thukral

        Cam I use an arduino pro mini 3.3V 8 Mhz to trigger the relay - or do I need a 5v arduino?

        sundberg84S Offline
        sundberg84S Offline
        sundberg84
        Hardware Contributor
        wrote on last edited by
        #14

        @Puneit-Thukral - it depends on the relay.
        If you read the datasheet for intended relay you will see what is needed. Most relays i have seen requiers 5v and a good current (which Arduino sometimes fail to deliver).

        Controller: Proxmox VM - Home Assistant
        MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
        MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
        RFLink GW - Arduino Mega + RFLink Shield, 433mhz

        Puneit ThukralP 1 Reply Last reply
        0
        • sundberg84S sundberg84

          @Puneit-Thukral - it depends on the relay.
          If you read the datasheet for intended relay you will see what is needed. Most relays i have seen requiers 5v and a good current (which Arduino sometimes fail to deliver).

          Puneit ThukralP Offline
          Puneit ThukralP Offline
          Puneit Thukral
          wrote on last edited by
          #15

          @sundberg84 I used a 3904 transistor between the relay and arduino and it works just fine with 3.3 V Arduino pro mini 8 HMz.
          (2N2222 also works, but I have many pieces of 3904 and just a few 2N2222, hence using 3904)

          1 Reply Last reply
          1
          • Javier RubioJ Offline
            Javier RubioJ Offline
            Javier Rubio
            wrote on last edited by
            #16

            I have my gateway and my relay, I believe is working fine, I just want to know what set of caracters do I need to send in the serial monitor to turn on the relay? I will like to use the info in order to use a controller like Vantage or C4, is that possible? Regards

            Puneit ThukralP 1 Reply Last reply
            0
            • Javier RubioJ Javier Rubio

              I have my gateway and my relay, I believe is working fine, I just want to know what set of caracters do I need to send in the serial monitor to turn on the relay? I will like to use the info in order to use a controller like Vantage or C4, is that possible? Regards

              Puneit ThukralP Offline
              Puneit ThukralP Offline
              Puneit Thukral
              wrote on last edited by
              #17

              @Javier-Rubio I m not an expert- a complete novice.
              I would suggest one of the following - trigger the relay through a controller or use one the the arduino relay example sketch in which relay is programmed to turn on and off every 1 second. This would help you validate if your wiring is correct or not.

              1 Reply Last reply
              0
              • GizmohG Offline
                GizmohG Offline
                Gizmoh
                wrote on last edited by
                #18

                I tried the relay sketch on my arduino mini pro (5v), step down converter for the NRF module and a two channel relay. It's conecte to a Raspi GW wirh the 2.0.0 beta and FHEM as controller. The switching works as expexted. but the relay switches continuisly on and off on its own after a certain time. I tried removing the loop-block but with no effort. Is there anything i can do to get a stable state? Thanks

                korttomaK 1 Reply Last reply
                0
                • GizmohG Gizmoh

                  I tried the relay sketch on my arduino mini pro (5v), step down converter for the NRF module and a two channel relay. It's conecte to a Raspi GW wirh the 2.0.0 beta and FHEM as controller. The switching works as expexted. but the relay switches continuisly on and off on its own after a certain time. I tried removing the loop-block but with no effort. Is there anything i can do to get a stable state? Thanks

                  korttomaK Offline
                  korttomaK Offline
                  korttoma
                  Hero Member
                  wrote on last edited by
                  #19

                  @Gizmoh sounds like the relays are not receiving enough power to remain on. How are you powering all this?

                  • Tomas
                  GizmohG 1 Reply Last reply
                  0
                  • korttomaK korttoma

                    @Gizmoh sounds like the relays are not receiving enough power to remain on. How are you powering all this?

                    GizmohG Offline
                    GizmohG Offline
                    Gizmoh
                    wrote on last edited by
                    #20

                    @korttoma
                    I'm powering this with 6 x AA Batteries into the RAW Input from the Arduino and the 5v output from Arduino to the Relay.

                    korttomaK 1 Reply Last reply
                    0
                    • GizmohG Gizmoh

                      @korttoma
                      I'm powering this with 6 x AA Batteries into the RAW Input from the Arduino and the 5v output from Arduino to the Relay.

                      korttomaK Offline
                      korttomaK Offline
                      korttoma
                      Hero Member
                      wrote on last edited by
                      #21

                      @Gizmoh ok so it seems like the voltage regulator on the arduino cannot handle the load the relays produce when activated. You need to power the relay board directly from your batteries either trough another 5V regulator or if your relay board already can handle a higher voltage you can connect it directly.

                      • Tomas
                      GizmohG 1 Reply Last reply
                      0
                      • korttomaK korttoma

                        @Gizmoh ok so it seems like the voltage regulator on the arduino cannot handle the load the relays produce when activated. You need to power the relay board directly from your batteries either trough another 5V regulator or if your relay board already can handle a higher voltage you can connect it directly.

                        GizmohG Offline
                        GizmohG Offline
                        Gizmoh
                        wrote on last edited by
                        #22

                        @korttoma Ah, okay, thank you. I'll give it a try.
                        Maybe connecting a Decoupling-Capacitor could also fix this problem?

                        1 Reply Last reply
                        0
                        • Rodolfo VieiraR Offline
                          Rodolfo VieiraR Offline
                          Rodolfo Vieira
                          wrote on last edited by
                          #23

                          hello one doubt
                          if a use this sketch: /mysensors/MySensorsArduinoExamples/examples/RelayWithButtonActuator/RelayWithButtonActuator.ino

                          when i press the button home assistant knows if switch was turned or off? its change the stat?

                          1 Reply Last reply
                          0
                          • riochickenR Offline
                            riochickenR Offline
                            riochicken
                            wrote on last edited by
                            #24

                            Hi,

                            First of all Merry Xmas to all of you!

                            I want to use this sketch with three LEDs to present the status of the alarm at home, so with a multicolored LED I have a green status, a red and a blue status, but I just want one color at a time, is there a way to alter the code a little to make sure that is a color is activated, the other one is turned off?

                            mfalkviddM 1 Reply Last reply
                            0
                            • riochickenR riochicken

                              Hi,

                              First of all Merry Xmas to all of you!

                              I want to use this sketch with three LEDs to present the status of the alarm at home, so with a multicolored LED I have a green status, a red and a blue status, but I just want one color at a time, is there a way to alter the code a little to make sure that is a color is activated, the other one is turned off?

                              mfalkviddM Offline
                              mfalkviddM Offline
                              mfalkvidd
                              Mod
                              wrote on last edited by
                              #25

                              @riochicken yes, but I wouldn't recommend relays for controlling a led. It can be controlled directly from the Arduino pins.

                              Look at the code for these:
                              https://www.openhardware.io/view/21/RGBW-LED-Controller#tabs-source
                              https://www.openhardware.io/view/74/OH-MySensors-RGBW-Controller#tabs-source

                              1 Reply Last reply
                              0
                              • riochickenR Offline
                                riochickenR Offline
                                riochicken
                                wrote on last edited by
                                #26

                                @mfalkvidd : I have directly soldered the LED's to the board, would be a waste of relays.. :) Thanks I will look into the examples you just gave...

                                1 Reply Last reply
                                1
                                • riochickenR Offline
                                  riochickenR Offline
                                  riochicken
                                  wrote on last edited by
                                  #27

                                  @mfalkvidd I have no clue how to decode the examples you gave, normally in vb or powershell I would check if a pin would be active if another color was requested so I could turn off the other color but I am a bit lost with the code....

                                  1 Reply Last reply
                                  0
                                  • pepsonP Offline
                                    pepsonP Offline
                                    pepson
                                    wrote on last edited by pepson
                                    #28

                                    Hi all
                                    I use this sketch for controlling 2 x relays. Can anybody change me this sketch to controliling only 1 x relay ?

                                    Next problem....
                                    Anybody know how edit sketch for relays to add itrms to send repeate update status to gateway? I want eliminate problem when node start and change status , but gateway is disabled. And after gateway will be enable show in my Domoticz old status/last memory before disable gateway. But after this node has changed status and this status is not show in Domoticz after run. I want to work it as Z-Wave. Z-wave has always actual status. Is any chance to also MySensors Gateway and not has always actual status ?

                                    /**
                                       DESCRIPTION
                                       Sketch for 2x relay with buttons monostable. After back power all relays set OFF and send correct status OFF to controller.  
                                    */
                                    
                                    // Enable debug prints to serial monitor
                                    #define MY_DEBUG
                                    
                                    // Enable and select radio type attached
                                    //#define MY_RADIO_NRF24
                                    #define MY_RADIO_RFM69
                                    #define MY_RFM69_FREQUENCY RF69_868MHZ
                                    #define MY_IS_RFM69HW
                                    
                                    // Enabled repeater feature for this node
                                    #define MY_REPEATER_FEATURE
                                    
                                    // Node id defaults to AUTO (tries to fetch id from controller)
                                    #define MY_NODE_ID AUTO
                                    
                                    #include <SPI.h>
                                    #include <MySensors.h>
                                    #include <Bounce2.h>
                                    
                                    // Define 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
                                    
                                    // Define Sensor ID's
                                    #define SSR_A_ID 1   // Id of the sensor child
                                    #define SSR_B_ID 2   // Id of the sensor child
                                    
                                    // Define buttons and relays
                                    const int buttonPinA = 3;
                                    const int buttonPinB = 4;
                                    const int relayPinA = 5;
                                    const int relayPinB = 6;
                                    
                                    // Define Variables
                                    int oldValueA = 0;
                                    int oldValueB = 0;
                                    bool stateA = false;
                                    bool stateB = false;
                                    int trigger = 0;
                                    
                                    Bounce debouncerA = Bounce();
                                    Bounce debouncerB = Bounce();
                                    
                                    MyMessage msgA(SSR_A_ID, V_STATUS);
                                    MyMessage msgB(SSR_B_ID, V_STATUS);
                                    
                                    void setup()
                                    {
                                    
                                      pinMode(buttonPinA, INPUT_PULLUP); // Setup the button Activate internal pull-up
                                      pinMode(buttonPinB, INPUT_PULLUP); // Setup the button Activate internal pull-up
                                    
                                    
                                      // After setting up the buttons, setup debouncer
                                      debouncerA.attach(buttonPinA);
                                      debouncerA.interval(5);
                                      debouncerB.attach(buttonPinB);
                                      debouncerB.interval(5);
                                    
                                      // Make sure relays are off when starting up
                                      digitalWrite(relayPinA, RELAY_OFF);
                                      digitalWrite(relayPinB, RELAY_OFF);
                                      // Then set relay pins in output mode
                                      pinMode(relayPinA, OUTPUT);
                                      pinMode(relayPinB, OUTPUT);
                                    
                                    }
                                    
                                    void presentation()  {
                                      // Send the sketch version information to the gateway and Controller
                                      sendSketchInfo("2xRelay with monostable", "2.1");
                                    
                                      // Register all sensors to gw (they will be created as child devices)
                                      present(SSR_A_ID, S_LIGHT);
                                      present(SSR_B_ID, S_LIGHT);
                                    
                                    }
                                    
                                    /*
                                       Example on how to asynchronously check for new messages from gw
                                    */
                                    void loop()
                                    {
                                    if (trigger == 0){
                                      send(msgA.set(false)); // Send off state for relayA to ensure controller knows the switch is off
                                      send(msgB.set(false)); // Send off state for relayB to ensure controller knows the switch is off
                                      trigger = 1;
                                    }
                                      
                                      debouncerA.update();
                                      // Get the update value
                                      int valueA = debouncerA.read();
                                      if (valueA != oldValueA && valueA == 0) {
                                        send(msgA.set(stateA ? false : true), true); // Send new state and request ack back
                                    
                                      }
                                      oldValueA = valueA;
                                     
                                    
                                      debouncerB.update();
                                      // Get the update value
                                      int valueB = debouncerB.read();
                                      if (valueB != oldValueB && valueB == 0) {
                                        send(msgB.set(stateB ? false : true), true); // Send new state and request ack back
                                    
                                      }
                                      oldValueB = valueB;
                                    }
                                    
                                    void receive(const MyMessage &message) {
                                      // We only expect one type of message from controller. But we better check anyway.
                                      if (message.type == V_STATUS) {
                                          
                                        switch (message.sensor) {
                                          case 1:
                                            stateA = message.getBool();
                                            digitalWrite(message.sensor + 4, stateA ? RELAY_ON : RELAY_OFF);
                                            
                                            break;
                                          case 2:
                                            stateB = message.getBool();
                                            digitalWrite(message.sensor + 4, stateB ? RELAY_ON : RELAY_OFF);
                                            
                                            break;
                                          
                                        }
                                       
                                          // Write some debug info
                                        Serial.print("Incoming change for sensor:");
                                        Serial.println(message.sensor);
                                        Serial.print("from node:");
                                        Serial.println(message.sender);
                                        Serial.print(", New status: ");
                                        Serial.println(message.getBool());
                                      }
                                    }```
                                    1 Reply Last reply
                                    0
                                    • oufmanO Offline
                                      oufmanO Offline
                                      oufman
                                      wrote on last edited by
                                      #29

                                      Hello,
                                      I would like to do an auto off after 2 sec directly in the sketch, however I do not understand how to write the code? I do not want to make a loop, but on pressing the ON button from my box the relay is activated is deactivated after 2 sec.

                                      Thank you for your help.

                                      1 Reply Last reply
                                      0
                                      • EfflonE Offline
                                        EfflonE Offline
                                        Efflon
                                        wrote on last edited by
                                        #30

                                        I'm trying to wrap my head around the button example and don't understand what the loop() really does. To me it only alters the "state" but how does it affect the relay?
                                        Is the button physically connected to the relay or should the controller send the new state back and let the receive() function handle the actual relay switching?
                                        Also, after presentation, shouldn't there be a send() to the controller?

                                        korttomaK Boots33B 2 Replies Last reply
                                        0
                                        • EfflonE Efflon

                                          I'm trying to wrap my head around the button example and don't understand what the loop() really does. To me it only alters the "state" but how does it affect the relay?
                                          Is the button physically connected to the relay or should the controller send the new state back and let the receive() function handle the actual relay switching?
                                          Also, after presentation, shouldn't there be a send() to the controller?

                                          korttomaK Offline
                                          korttomaK Offline
                                          korttoma
                                          Hero Member
                                          wrote on last edited by
                                          #31

                                          @Efflon you are right about the loop() function it seems like the part where it should change the relay state is missing. Did you try to use this example code?

                                          The button should be wired between PIN 3 and GND so that when you push the button PIN 3 is Grounded.

                                          PIN 3 is connected to a "Debouncer" in the "setup()" ( so that when you push the button the code detects only one push and not several ).

                                          loop() monitors the debouncer and when it detects that you have pushed the button it will send the new state to the controller. I think it should also change the state so if it does not do that you could add the following line

                                          digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); //write new state to relay output

                                          Before this line in the loop() function:
                                          send(msg.set(state?false:true), true); // Send new state and request ack back

                                          You could also add the line:
                                          saveState(CHILD_ID, state); // Store state in eeprom

                                          To the same part of the code so that the state change is written to eeprom so that the previous state can be returned after a power failure.

                                          • Tomas
                                          EfflonE 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          9

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular