💬 Relay
-
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
-
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
@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. -
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
-
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
-
@Gizmoh sounds like the relays are not receiving enough power to remain on. How are you powering all this?
-
@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.@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.
-
@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.
-
hello one doubt
if a use this sketch: /mysensors/MySensorsArduinoExamples/examples/RelayWithButtonActuator/RelayWithButtonActuator.inowhen i press the button home assistant knows if switch was turned or off? its change the stat?
-
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?
-
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?
@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 -
@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...
-
@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....
-
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()); } }``` -
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.
-
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? -
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?@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 backYou could also add the line:
saveState(CHILD_ID, state); // Store state in eepromTo 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.
-
@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 backYou could also add the line:
saveState(CHILD_ID, state); // Store state in eepromTo 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.
-
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?@Efflon said:
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?The loop in the relay with button actuator sketch does three main things
checks for a new button push
changes the current state
Sends the new state to the controllerIf you look at the message code you can see it also asks for an ACK back from the controller. That is the true at the end of the line.
send(msg.set(state?false:true), true); // Send new state and request ack backIt is this returned ACK that is used to switch the relay to the new state in the void receive function
The one drawback in this code if it is used for say a light switch is that if this node looses contact with the controller then the relay cannot be changed by pressing the button.
-
@Efflon said:
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?The loop in the relay with button actuator sketch does three main things
checks for a new button push
changes the current state
Sends the new state to the controllerIf you look at the message code you can see it also asks for an ACK back from the controller. That is the true at the end of the line.
send(msg.set(state?false:true), true); // Send new state and request ack backIt is this returned ACK that is used to switch the relay to the new state in the void receive function
The one drawback in this code if it is used for say a light switch is that if this node looses contact with the controller then the relay cannot be changed by pressing the button.
@Boots33 Ok, you explanation is what was my only explanation to the "missing" code. When experimenting with this using the mqtt gateway sketch and home-assistant as controller, the ACK is just an ACK and not a "real" message with payload thus just toggling the state bool and getting things out of sync..
-
I did not get the example working properly with my 8 channel SSR. So here is my updated version of the example.
I have changed the way the pins are assigned by using a array. The current example tries to connect relays 7 and 8 to pins 9 and 10 when you select an 8 channel relays. This won't work because those pins are used by the radio module.
I think you can connect a relays to any pin which is not used. If so this will make it possible to connect up to 14 relays to the mini pro when also the pins A5-A7 are available.
// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Enable repeater functionality for this node #define MY_REPEATER_FEATURE #include <MySensors.h> const int PINS[] = {3, 4, 5, 6, 7, 8, 14, 15}; // I/O pins 3, 4, 5, 6, 7, 8, A0, A1 for the relays #define NUMBER_OF_RELAYS 8 // 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 void before() { for (int sensor=1; sensor<=NUMBER_OF_RELAYS; sensor++) { // Then set relay pins in output mode pinMode(PINS[sensor-1], OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(PINS[sensor-1], loadState(sensor)?RELAY_ON:RELAY_OFF); } } void setup() { } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Relay", "1.0"); for (int sensor=1; sensor<=NUMBER_OF_RELAYS; sensor++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); } } void loop() { } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state digitalWrite(PINS[message.sensor-1], message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom 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()); } }