Relay Actuator not working



  • Hello guys!

    After successfully using a DS18B20 with MySensors I wanted to try controlling a relay using the "RelayActuator" example provided in the latest version. After the Relay node successfully connects to the Gateway I use domoticz to control ON/OFF to the Relay node. The relay controls a power switch which controls a light. The relay I use is a 5V 1 Channel OMRON SSR G3MB-202P Solid State Relay. There is a light showing if the relay is OPEN or CLOSED, and of course is noticable when and if the light goes on or off. The relay is powered by 5V+GND and controlled through the Channel port on the Relay which is connected to Digital Pin 3 on my Arduino.

    When I press "Off" in domoticz on the relay node, I see a message in the serial monitor for the node: "Changed to 1" or "Changed to 0". But nothing is happening. It is like if D3 is constantly set to HIGH and does not change?!

    The code I am using:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * 
     * DESCRIPTION
     * Example sketch showing how to control physical relays. 
     * This example will remember relay state after power failure.
     * http://www.mysensors.org/build/relay
     */ 
    
    // 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 <SPI.h>
    #include <MySensors.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
    
    
    void before() { 
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, 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, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_LIGHT);
      }
    }
    
    
    void loop() 
    {
      
    }
    
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==S_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor-1+RELAY_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());
       } 
    }
    

    As stated in the code, the relay channel controller is set to digital pin 3. I can't see what's wrong with the code. When testing the relay directly with a simple loop, the light flashes - relay works:

    #define RELAY1 3
    
    void setup()
    
    {    
      pinMode(RELAY1, OUTPUT);       
    }
    
     void loop()
    {
       digitalWrite(RELAY1,LOW);           // Turns ON Relays 1
    
       delay(2000);                                      // Wait 2 seconds
    
       digitalWrite(RELAY1,HIGH);          // Turns Relay Off
    
       delay(2000); 
    
     }
    

    Help would be greatly appreciated!


  • Hero Member

    @chippey5 The code looks OK to me and the fact that you are seeing the change via the serial monitor would seem to indicate the code is working.

    Maybe try disconnecting the relay from pin 3 and connect your multi meter there instead to see if the change is happening.



  • @Boots33 Thanks for your reply!

    I did, nothing happened. I also took out a new relay to see if there was a hardware error but no difference. It just seems that the pin doesn't go to LOW or HIGH when it is told to do. I am using an Aruino mini pro 3v3v 8Mhz Atmega328 (with a dc-dc booster to 5v for the relay to work).


  • Contest Winner

    @chippey5 @chippey5 I prefer to use #define's for the child ID. It eliminates possible bugs. Also uses such complicated code (meaning for statements for controlling relays makes the code harder to read.

    could you change this:

        // Change relay state
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
    

    to this:

        // Change relay state
         digitalWrite(1, message.getBool()?RELAY_ON:RELAY_OFF);
    

    doubt if it helps. But you just give it a try.


  • Hero Member

    @chippey5 can you show us the output from the serial monitor That may help to see what is going on. Perhaps try another digital pin as well for the relay. TheoL has a good idea try and simplify the sketch and see if it works, although you are using the standard relay sketch from what i can see so it should work.

    Try this

    // 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 <SPI.h>
    #include <MySensors.h>
    
    #define RELAY_1  3  // Arduino Digital I/O pin number for t relay 
    #define CHILD_ID_RELAY 1 
    #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
    
    
    
    
    void setup() {
    
      pinMode(RELAY_1, OUTPUT);
      
    }
    
    void presentation()  
    {   
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay Test", "1.0");
    
     
        // Register sensor to gw ( will be created as child devices)
        present(CHILD_ID_RELAY, S_LIGHT);
     
    }
    
    
    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_LIGHT) {
         // Change relay state
         digitalWrite(RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
        
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    }
    
    


  • Alright so I tried the solutions suggested but no luck, now the gateway seems to be rejecting it instead with the RelayActuator sketch:

    Starting sensor (RNNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=1)
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-1 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=1)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:CHKUPL:FAIL (hops=255)
    !TSM:UPL:FAIL
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-1 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=1)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:CHKUPL:FAIL (hops=255)
    !TSM:UPL:FAIL
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-1 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=1)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:CHKUPL:FAIL (hops=255)
    !TSM:UPL:FAIL
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-1 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=1)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:CHKUPL:FAIL (hops=255)
    !TSM:UPL:FAIL
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-1 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=1)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:CHKUPL:FAIL (hops=255)
    !TSM:UPL:FAIL
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-1 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=1)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-1 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSM:UPL:OK
    TSM:READY
    !TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=fail:0100
    !TSP:MSG:SEND 1-1-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=1,st=fail:2.0.0
    !TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=2,st=fail:0
    !TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=11,pt=0,l=5,sg=0,ft=3,st=fail:Relay
    !TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=4,st=fail:1.0
    !TSP:MSG:SEND 1-1-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,ft=5,st=fail:
    Request registration...
    !TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=6,st=fail:2
    !TSM:UPL FAIL, SNP
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSP:SEND:TNR
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSP:SEND:TNR
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSP:SEND:TNR
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    Init complete, id=1, parent=255, distance=255, registration=1
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=1)
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    

    The wiring is ok, I tried to flash the DS18B20 sketch which worked:

    Starting sensor (RNNNA-, 2.0.0)
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=1)
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    !TSM:FPAR:FAIL
    !TSM:FAILURE
    TSM:PDT
    TSM:INIT
    TSM:RADIO:OK
    TSP:ASSIGNID:OK (ID=1)
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSM:FPAR
    TSP:MSG:SEND 1-1-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
    TSP:MSG:READ 0-0-1 s=255,c=3,t=8,pt=1,l=1,sg=0:0
    TSP:MSG:FPAR RES (ID=0, dist=0)
    TSP:MSG:PAR OK (ID=0, dist=1)
    TSM:FPAR:OK
    TSM:ID
    TSM:CHKID:OK (ID=1)
    TSM:UPL
    TSP:PING:SEND (dest=0)
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
    TSP:MSG:READ 0-0-1 s=255,c=3,t=25,pt=1,l=1,sg=0:1
    TSP:MSG:PONG RECV (hops=1)
    TSP:CHKUPL:OK
    TSM:UPL:OK
    TSM:READY
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
    TSP:MSG:SEND 1-1-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
    TSP:MSG:READ 0-0-1 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    TSP:MSG:READ 0-0-1 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=ok:Temperature Sensor
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.1
    Request registration...
    TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
    TSP:MSG:READ 0-0-1 s=255,c=3,t=27,pt=1,l=1,sg=0:1
    Node registration=1
    Init complete, id=1, parent=0, distance=1, registration=1
    

    I am out of ideas now


  • Contest Winner

    @chippey5 Can you post your circuit please?



  • This post is deleted!


  • @TheoL

    So basically all the wiring is correct, the only thing that could cause problems is the actual VCC - I have split this one to power both 5V step-up regulator->Relay and the radio. I just tried the sketch today and now it is registered, but relay not responding on commands. I think I will go with a Nano instead on this one 😜



  • Okay so now I tried to power the relay with an external power source (Arduino Uno 5V port) but still nothing(?). I will check and try tomorrow again, because a basic HIGH/LOW loop for D3 didn't make the relay respond - which it did yesterday


  • Contest Winner

    @chippey5 Not sure what you mean with an external power source (Arduino Uno 5V). If you power everything from the 5V or 3.3V that are on the arduino board, then you're not powering it external. In that case you're powering everything directly from the Uno. I've experienced a lot of troubles with this way. The power regulator on the Arduino Uno just isn't powerful enough to provide a lot of current.

    It's best to power the arduino from an external 5v source (like an old phone charger) and power the relay also from that external adapter. The same goes for the radio but you'll need a power regulator.



  • @TheoL Sorry for not being clear, the serialgateway (Arduino uno) is powered and connected to A raspberry Pi 3 (Which is powered by a 2.5A wall adapter). I used this arduinos 5V pin to test the RelayActuator but it still seems like the Mini Pro 3.3v is not changing the state of the D3 (for relay channel). I will check and see current and voltage from arduinos 5V and report back


  • Contest Winner

    @chippey5 Could you do one test for me? I want to know if your proMini is capable for handling your relay.

    1. Disconnect everything from the ProMini.
    2. Now power it from the FDTI or an external adapter.
    3. Connect the ground of the relay to the ground of your arduino.
    4. Connect the VCC of the relay to the VCC of your Arduino.
    5. Connect the data pin of the relay to the gnd of the Arduino as well.
    6. Now instead of connecting the data line of the Relay to the gnd of the Arduino, you have to connect the data line of the relay to the vcc out of the Arduino.

    Depending on your relay, step 5 or 6 should activate the relay. If not then:

    • either your relay is broken
    • or your relay needs more power than your Arduino can provide.

    I think this way is the easiest to see if the Arduino can handle the relay and this is (imo) the fastest way to test this. Problems in arduino projects can get really hard to solve. Because there are so many aspects in what can go wrong.

    Love to hear your test results.



  • My sensors for Temperature, Humidity, Motion, Light level, and Door sensors were all working well, however, my dimmers, relays and switches were intermittent at best.

    I tried all the suggestions here and had no improvement.

    I monitored one of my node that had a relay and did see any on or off commands coming to the relay.

    PROBLEM SOLVED

    I thought the NRF24L01 on the ethernet gateway might not be transmitting reliably, so i changed it out.

    Every switch, dimmer and relay work perfectly !


Log in to reply
 

Suggested Topics

37
Online

11.4k
Users

11.1k
Topics

112.7k
Posts