Skip to content
  • MySensors
  • 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. Hardware
  3. Controlling existing relays

Controlling existing relays

Scheduled Pinned Locked Moved Hardware
54 Posts 9 Posters 30.9k Views 6 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.
  • C Offline
    C Offline
    ceech
    Hardware Contributor
    wrote on last edited by
    #9

    It would be nice if your relays could hold with DC voltage. Do you have a chance to remove one of them, just to try it? Use a 24 DC voltage and try to make a relay click to close. See if it holds. If it does than you can use Mosfets to control them. Be careful, 220AC is lethal.

    1 Reply Last reply
    0
    • T twosh

      Latching relays - I can see a small latch physically move when I switch on / off the lights. I think they might be powering my button lights as well since there are a thin wire connected to each relay in addition to the 230V wire. At least that thin wire must be for the impulse making the relay switch. Does this simplify things @Sparkman ?

      @TimO , could you visualize how you have connected the different parts, or better yet use my uploaded pic to show me how I should connect everything?

      Greatly appreciated!

      SparkmanS Offline
      SparkmanS Offline
      Sparkman
      Hero Member
      wrote on last edited by
      #10

      @twosh said:

      Latching relays - I can see a small latch physically move when I switch on / off the lights. I think they might be powering my button lights as well since there are a thin wire connected to each relay in addition to the 230V wire. At least that thin wire must be for the impulse making the relay switch. Does this simplify things @Sparkman ?

      Yes it does, you would need to wire the new Arduino controlled relay in parallel with the existing wires (the ones to contact A1 and A2). One side of the 24 VAC power supply should be connected to either A1 or A2 and then the other side of the AC supply is connected through the switch to the other terminal. Just hook up the new relay the same way using the same 24VAC power supply if possible.

      Also, if you want to know the status of the light, you could add voltage/current sensors on the output side that would connect to an input pin on the Arduino. If you're not comfortable working on the high-voltage side, you could measure the pulses on the 24VAC side as well.

      Cheers
      Al

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ceech
        Hardware Contributor
        wrote on last edited by ceech
        #11

        If they don't hold, then you can use a semiconductor called triac. Here is how you use one:
        triaccontroller.png
        It is not 240V AC that you are going to regulate, it is going to be your relays 24V AC control signal. And load is your relay.

        jeylitesJ T 2 Replies Last reply
        0
        • T Offline
          T Offline
          twosh
          wrote on last edited by twosh
          #12

          Thanks guys! I will try to get a friend over who knows his stuff when it comes to electricity to help me out with the wiring.

          Breaking it down, I'll need one arduino for controlling the relay board, and if I want a dimmer I would need to rig another Arduino with a dimmer circuit after each 230v relay I want to dim the lamps for.

          @ceech - nice! I'll keep that diagram as an option as well - it would basically eliminate the need for the Arduino relay board I guess.

          Thanks again!

          1 Reply Last reply
          0
          • C ceech

            If they don't hold, then you can use a semiconductor called triac. Here is how you use one:
            triaccontroller.png
            It is not 240V AC that you are going to regulate, it is going to be your relays 24V AC control signal. And load is your relay.

            jeylitesJ Offline
            jeylitesJ Offline
            jeylites
            wrote on last edited by
            #13

            @ceech Just wondering, did you get a chance to test this circuit? I've been wanting to do this for a while., guess will be my next project. Will be great if I could get a kit on Ebay. :)

            C 1 Reply Last reply
            0
            • jeylitesJ Offline
              jeylitesJ Offline
              jeylites
              wrote on last edited by
              #14

              found a kit on Ebay, but it's pricey.

              http://www.ebay.com/itm/AC-60Hz-50Hz-Dimmer-Controller-Board-Arduino-Compatible-/221739082562?pt=LH_DefaultDomain_2&var=&hash=item33a0ade342

              1 Reply Last reply
              0
              • jeylitesJ jeylites

                @ceech Just wondering, did you get a chance to test this circuit? I've been wanting to do this for a while., guess will be my next project. Will be great if I could get a kit on Ebay. :)

                C Offline
                C Offline
                ceech
                Hardware Contributor
                wrote on last edited by ceech
                #15

                @jeylites No, I didn't try. It will work, though. You can try on a breadboard. You don't even need all the elements. Remove the 100ohm resistor and 0,1uF cap for testing. And the resistors can be replaced with similar. Be careful with the mains voltage, please. I'm tempted to make some boards just to try.

                jeylitesJ 1 Reply Last reply
                0
                • C ceech

                  @jeylites No, I didn't try. It will work, though. You can try on a breadboard. You don't even need all the elements. Remove the 100ohm resistor and 0,1uF cap for testing. And the resistors can be replaced with similar. Be careful with the mains voltage, please. I'm tempted to make some boards just to try.

                  jeylitesJ Offline
                  jeylitesJ Offline
                  jeylites
                  wrote on last edited by
                  #16

                  @ceech Perhaps I should test one on a bread board. ..

                  1 Reply Last reply
                  0
                  • C ceech

                    If they don't hold, then you can use a semiconductor called triac. Here is how you use one:
                    triaccontroller.png
                    It is not 240V AC that you are going to regulate, it is going to be your relays 24V AC control signal. And load is your relay.

                    T Offline
                    T Offline
                    twosh
                    wrote on last edited by twosh
                    #17

                    @ceech said:

                    If they don't hold, then you can use a semiconductor called triac. Here is how you use one:
                    triaccontroller.png
                    It is not 240V AC that you are going to regulate, it is going to be your relays 24V AC control signal. And load is your relay.

                    Based on @jeylites comments I'm starting to think that this triac circuit completely replaces the current relay (not just the Arduino relay board), as well as adding dimmer functionality - is this correct? Confused

                    But would I loose the current physical buttons' functionality or could those also be wired into the triac?

                    jeylitesJ C 2 Replies Last reply
                    0
                    • T twosh

                      @ceech said:

                      If they don't hold, then you can use a semiconductor called triac. Here is how you use one:
                      triaccontroller.png
                      It is not 240V AC that you are going to regulate, it is going to be your relays 24V AC control signal. And load is your relay.

                      Based on @jeylites comments I'm starting to think that this triac circuit completely replaces the current relay (not just the Arduino relay board), as well as adding dimmer functionality - is this correct? Confused

                      But would I loose the current physical buttons' functionality or could those also be wired into the triac?

                      jeylitesJ Offline
                      jeylitesJ Offline
                      jeylites
                      wrote on last edited by
                      #18

                      @twosh

                      Yes indeed, this is a dimmer not a Relay. If you need a relay functionality you could employ a solid state relay or mechanical one. Why I say this is the waveform gets altered when going through Traic and its not good for certain electronic items.Excluding a light bulb. See picture below for better understating. I wish i could explain more but in the process of doing something...LOL

                      I didn't quite understand what you meant by "current physical buttons" ....

                      dimmertheory_1236784371.jpg

                      1 Reply Last reply
                      0
                      • T twosh

                        @ceech said:

                        If they don't hold, then you can use a semiconductor called triac. Here is how you use one:
                        triaccontroller.png
                        It is not 240V AC that you are going to regulate, it is going to be your relays 24V AC control signal. And load is your relay.

                        Based on @jeylites comments I'm starting to think that this triac circuit completely replaces the current relay (not just the Arduino relay board), as well as adding dimmer functionality - is this correct? Confused

                        But would I loose the current physical buttons' functionality or could those also be wired into the triac?

                        C Offline
                        C Offline
                        ceech
                        Hardware Contributor
                        wrote on last edited by ceech
                        #19

                        @twosh Yes, it is adding the dimmer functionality, but you would need an additional optocoupler and bridge rectifier for it to work. The MOC3061 IC knows about zero crossing of the AC signal and cuts some signal as @jeylites explained. That shouldn't bother you for now. As long as you apply 5V or 0V on the input side, the circuit behaves as a switch.
                        Let's not completely replace everything at the moment. Let us say that we are just going to add this circuit to your 24V AC relay coil. You can still use the physical switch. But remember - the voltage fed into the BTA41 triac should be 24V AC in this case.

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          twosh
                          wrote on last edited by twosh
                          #20

                          Want to share my progress since my 8 relay arrived today! :)

                          I've successfully modified the relay example sketch to use two analogue pins for the 7:th and 8:th relays, so everything software wise is fine for now.

                          I connected one of the arduino relay outputs to one of my house relays for testing and succeeded to get the house relay to switch on by having the arduino relay low. But I can't get the house relay to turn off again, no matter if I turn the arduino relay high, nor low again. I had to use the physical light switch to turn the relay off again.

                          What am I missing..?

                          1 Reply Last reply
                          0
                          • jeylitesJ Offline
                            jeylitesJ Offline
                            jeylites
                            wrote on last edited by
                            #21

                            @twosh you should post your sketch.

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              twosh
                              wrote on last edited by
                              #22

                              Here's my sketch @jeylites !

                              I'm using this 8 channel relay board: http://www.ebay.com/itm/181242936438?rmvSB=true

                              Had to switch the GPIO HIGH/LOW values around compared to the original sketch, and added two analogue pins controlling channel 7 and 8 on the board.

                              // 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 RELAY_1A  0  // Arduino Analog I/O pin number for first relay (second on pin+1 etc)
                              #define NUMBER_OF_RELAYS 6 // Total number of attached relays
                              #define NUMBER_OF_ANALOG_RELAYS 2 // Total number of attached relays
                              #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
                              
                              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 AD");
                              
                                // 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);
                                }
                              
                                // Fetch and present the analogue relays  
                                int sensor=NUMBER_OF_RELAYS+1;
                                gw.present(sensor++, S_LIGHT);
                                pinMode(A0, OUTPUT);
                                digitalWrite(A0, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
                                gw.present(sensor++, S_LIGHT);
                                pinMode(A1, OUTPUT);
                                digitalWrite(A1, 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
                                   if (message.sensor <= NUMBER_OF_RELAYS)
                                     digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
                                   else if (message.sensor == NUMBER_OF_RELAYS+1) //First analogue sensor
                                     digitalWrite(A0, message.getBool()?RELAY_ON:RELAY_OFF);
                                   else //Second analogue sensor
                                     digitalWrite(A1, 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());
                                 } 
                              }
                              
                              SparkmanS 1 Reply Last reply
                              0
                              • jeylitesJ Offline
                                jeylitesJ Offline
                                jeylites
                                wrote on last edited by
                                #23

                                @twosh Try this sketch below it works. You can change outputs around by changing const int relayPin [] = {A2, A3, A4, A5, A6, A7}; & const int buttonPin[] = {3, 4, 5, 6, 7, 8};

                                
                                // This is the final sketch
                                // Example sketch showing how to control physical relays. 
                                // This example will remember relay state even after power failure.
                                
                                #include <MySensor.h>
                                #include <SPI.h>
                                #include <Bounce2.h>
                                #define RELAY_ON 0                      // switch around for realy HIGH/LOW state
                                #define RELAY_OFF 1
                                //
                                MySensor gw;
                                
                                //#define RADIO_ID 8                    // Radio Id, whatever channel you assigned to
                                #define noRelays 6
                                const int relayPin[] = {A2, A3, A4, A5, A6, A7};
                                const int buttonPin[] = {3, 4, 5, 6, 7, 8};
                                
                                class Relay				// relay class, store all relevant data (equivalent to struct)
                                {
                                public:                             		 
                                  int buttonPin;			// physical pin number of button
                                  int relayPin;				// physical pin number of relay
                                  byte oldValue;               		// last Values for key (debounce)
                                  boolean relayState;             	// relay status (also stored in EEPROM)
                                };
                                
                                Relay Relays[noRelays];	
                                Bounce debouncer[noRelays];
                                MyMessage msg[noRelays];
                                
                                void setup(){
                                	gw.begin(incomingMessage, AUTO, true);
                                	delay(250);
                                	gw.sendSketchInfo("MultiRelayButton", "0.9b");
                                	delay(250);
                                
                                	// Initialize Relays with corresponding buttons
                                	for (int i = 0; i < noRelays; i++){
                                	Relays[i].buttonPin = buttonPin[i];				             // assign physical pins
                                	Relays[i].relayPin = relayPin[i];
                                	msg[i].sensor = i;						             // initialize messages
                                	msg[i].type = V_LIGHT;
                                	debouncer[i] = Bounce();						     // initialize debouncer
                                	debouncer[i].attach(buttonPin[i]);
                                	debouncer[i].interval(5);
                                	pinMode(Relays[i].buttonPin, INPUT_PULLUP);
                                	pinMode(Relays[i].relayPin, OUTPUT);
                                	Relays[i].relayState = gw.loadState(i);			                      // retrieve last values from EEPROM
                                	digitalWrite(Relays[i].relayPin, Relays[i].relayState? RELAY_ON:RELAY_OFF);   // and set relays accordingly
                                	gw.send(msg[i].set(Relays[i].relayState? true : false));	              // make controller aware of last status
                                	gw.present(i, S_LIGHT);							      // present sensor to gateway
                                	delay(250);
                                
                                	}
                                }
                                
                                void loop()
                                	{
                                	gw.process();
                                	for (byte i = 0; i < noRelays; i++){
                                	debouncer[i].update();
                                	byte value = debouncer[i].read();
                                	if (value != Relays[i].oldValue && value == 0){
                                	Relays[i].relayState = !Relays[i].relayState;
                                	digitalWrite(Relays[i].relayPin, Relays[i].relayState?RELAY_ON:RELAY_OFF);
                                	gw.send(msg[i].set(Relays[i].relayState? true : false));
                                	gw.saveState( i, Relays[i].relayState );}                 // save sensor state in EEPROM (location == sensor number)
                                	
                                        Relays[i].oldValue = value;
                                        
                                	}
                                }
                                
                                // process incoming message 
                                void incomingMessage(const MyMessage &message){
                                         
                                        if (message.type == V_LIGHT){ 
                                        if (message.sensor <noRelays){ 			  // check if message is valid for relays..... previous line if [[[ (message.sensor <=noRelays){ ]]]
                                        Relays[message.sensor].relayState = message.getBool(); 
                                        digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState? RELAY_ON:RELAY_OFF); // and set relays accordingly
                                        gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
                                		}
                                	}
                                }
                                
                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  twosh
                                  wrote on last edited by twosh
                                  #24

                                  Thanks a lot @jeylites !

                                  A couple of question; you are using physical buttons mapped to your pins d3-d8 - 6 in total. The rest of the digital pins are taken up by the radio I guess, since they are for me. Does that mean that this sketch is limited to 6 relays as well since the Relay class seems to match one button pin with one relay pin. Or can I just define 6 buttons and 8 relays, like this?

                                  const int relayPin[] = {A0, A1, A2, A3, A4, A5, A6, A7};
                                  const int buttonPin[] = {3, 4, 5, 6, 7, 8, NULL, NULL};
                                  

                                  I could use the A0-A7 pins for my 8 relays but I'm unsure if the above 6+NULL+NULL buttons to 8 relays mapping will cause problems?

                                  To clarify, the problem I'm facing when using my sketch above is not that the arduino relays would not obey, it is that the relays controlled by the arduino relays stays "on" all the time. The physical buttons i keep mentioning are connected to the HOUSE relays (i.e. lightswitches), not to the Arduino.

                                  1 Reply Last reply
                                  0
                                  • T Offline
                                    T Offline
                                    twosh
                                    wrote on last edited by
                                    #25

                                    Found some specs on my house relays: http://www.switchtec.co.uk/relay_catalog/129_LR-28.pdf

                                    It's the esmi nr-8251 latching relay if this helps!

                                    1 Reply Last reply
                                    0
                                    • T TimO

                                      I suppose the relays are impulse relays, which need a impulse to change the state (on/off). I'm using the Relay-Modules you mentioned above to control my impulse relays. My impulse relays are controlled with 230V. The relays are connected in parallel to the existing switches and use a 100ms impulse to change the state.
                                      Works like a charme.

                                      T Offline
                                      T Offline
                                      twosh
                                      wrote on last edited by
                                      #26

                                      @TimO said:

                                      I suppose the relays are impulse relays, which need a impulse to change the state (on/off). I'm using the Relay-Modules you mentioned above to control my impulse relays. My impulse relays are controlled with 230V. The relays are connected in parallel to the existing switches and use a 100ms impulse to change the state.
                                      Works like a charme.

                                      Could you share your experience in more detail? It feels like you have accomplished what I would like to happen at this point. :)

                                      1 Reply Last reply
                                      0
                                      • T twosh

                                        Here's my sketch @jeylites !

                                        I'm using this 8 channel relay board: http://www.ebay.com/itm/181242936438?rmvSB=true

                                        Had to switch the GPIO HIGH/LOW values around compared to the original sketch, and added two analogue pins controlling channel 7 and 8 on the board.

                                        // 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 RELAY_1A  0  // Arduino Analog I/O pin number for first relay (second on pin+1 etc)
                                        #define NUMBER_OF_RELAYS 6 // Total number of attached relays
                                        #define NUMBER_OF_ANALOG_RELAYS 2 // Total number of attached relays
                                        #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
                                        
                                        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 AD");
                                        
                                          // 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);
                                          }
                                        
                                          // Fetch and present the analogue relays  
                                          int sensor=NUMBER_OF_RELAYS+1;
                                          gw.present(sensor++, S_LIGHT);
                                          pinMode(A0, OUTPUT);
                                          digitalWrite(A0, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
                                          gw.present(sensor++, S_LIGHT);
                                          pinMode(A1, OUTPUT);
                                          digitalWrite(A1, 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
                                             if (message.sensor <= NUMBER_OF_RELAYS)
                                               digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
                                             else if (message.sensor == NUMBER_OF_RELAYS+1) //First analogue sensor
                                               digitalWrite(A0, message.getBool()?RELAY_ON:RELAY_OFF);
                                             else //Second analogue sensor
                                               digitalWrite(A1, 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());
                                           } 
                                        }
                                        
                                        SparkmanS Offline
                                        SparkmanS Offline
                                        Sparkman
                                        Hero Member
                                        wrote on last edited by Sparkman
                                        #27

                                        @twosh Based on the spec sheet, I believe your existing latching relays need a 35ms pulse to turn them on and off.

                                        The standard relay sketch to control your new relays is meant to turn the relays on based on a command from the controller and then another command from the controller to turn them off. It also maintains the relay state by saving them to EEPROM, and sets them to last state on power-up, etc. You don't need most of that. All you need to do is set the relay to on, wait 35 milliseconds and then set the relay to off based on a toggle command from the controller.

                                        Take a crack at simplifying the sketch, post your results and I, or others, can help with the next steps.

                                        The one thing to note is that with this system, you won't know if the light is on or on, all you can do is toggle current status. You would have to add current sensors or something like that to be able to know the state. Are there LEDs on the existing system that are on when the light is on and off when the lights are off?

                                        Cheers
                                        Al

                                        PS Have you measured the voltage to the control side of the existing latching relay when operated by a switch?

                                        1 Reply Last reply
                                        0
                                        • T Offline
                                          T Offline
                                          twosh
                                          wrote on last edited by
                                          #28

                                          Thank you all for the various ideas and input!

                                          I've figured out what I had done wrong (not feeding the relays with the common wire correctly). I've also changed the sketch to give a 35 ms impulse, and connected everything. Working great! Here is my sketch if anyone needs it:

                                          // Example sketch showing how to control physical relays. 
                                          // This example will NOT remember relay state even after power failure.
                                          
                                          #include <MySensor.h>
                                          #include <SPI.h>
                                          
                                          #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
                                          
                                          #define noRelays 8
                                          const int relayPin[] = {A0, A1, A2, A3, A4, A5, 3, 4};
                                          
                                          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 AD");
                                          
                                            // Fetch relay status
                                            for (int sensor=0; sensor < noRelays; sensor++)
                                            {
                                              // Register all sensors to gw (they will be created as child devices)
                                              gw.present(sensor+1, S_LIGHT);
                                              // Then set relay pins in output mode
                                              pinMode(relayPin[sensor], OUTPUT);   
                                              // Set relay to last known state (using eeprom storage) 
                                              //digitalWrite(relayPin[sensor], gw.loadState(sensor+1)?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)
                                            {
                                               if (message.sensor <= noRelays)
                                               {
                                                   digitalWrite(relayPin[message.sensor-1], RELAY_ON);
                                                   delay(35); // 35 ms impulse used by my relays
                                                   digitalWrite(relayPin[message.sensor-1], 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());
                                             } 
                                          }
                                          
                                          

                                          As @Sparkman says, I won't actually know if the light is on or off, since I can't register a change that would happen via the physical light switches in the house. Any suggestions on how to do this is of course welcome! The output side of the house relay is 230 VAC to the lights, and 24 VAC to the leds in the light switches. What kind of hardware would I need for sensing current and reporting it back to the Arduino? Is there any sketch I could use that lays the groundwork?

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


                                          22

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 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
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular