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. General Discussion
  3. Need help making pin D1 available for 8 relay module

Need help making pin D1 available for 8 relay module

Scheduled Pinned Locked Moved General Discussion
6 Posts 2 Posters 400 Views 2 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.
  • M Offline
    M Offline
    mrhutchinsonmn
    wrote on last edited by
    #1

    Is there a way to utilize pin D1 for my 8 relay module with this or a modified sketch? I understand from research that the serial commands are getting in the way but I am not sure how to work around this and need pins 8-13 for my radio. (Powering via vin)

    // Override Setting for Manual Node ID to 2
    #define MY_NODE_ID 51
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #include <SPI.h>
    #include <MySensors.h>
    
    #define RELAY_1  1          // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 8 // Total number of attached relays: 4
    
    // Opto Relay Module I was using Active Low - Low (0):ON, High (1): OFF
    #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
    
    bool initialValueSent = false;
    
    //Init MyMessage for Each Child ID
    MyMessage msg1(1, V_LIGHT);
    MyMessage msg2(2, V_LIGHT);
    MyMessage msg3(3, V_LIGHT);
    MyMessage msg4(4, V_LIGHT);
    MyMessage msg5(5, V_LIGHT);
    MyMessage msg6(6, V_LIGHT);
    MyMessage msg7(7, V_LIGHT);
    MyMessage msg8(8, V_LIGHT);
    
    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("Multiple Relay", "1c.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() 
    {
      if (!initialValueSent) {
        Serial.println("Sending initial value");
        send(msg1.set(loadState(1)?RELAY_OFF:RELAY_ON),true);
        wait(1000);
        send(msg2.set(loadState(2)?RELAY_OFF:RELAY_ON),true);
        wait(1000);
        send(msg3.set(loadState(3)?RELAY_OFF:RELAY_ON),true);
        wait(1000);
        send(msg4.set(loadState(4)?RELAY_OFF:RELAY_ON),true);
        wait(1000);
         send(msg5.set(loadState(5)?RELAY_OFF:RELAY_ON),true);
        wait(1000);
        send(msg6.set(loadState(6)?RELAY_OFF:RELAY_ON),true);
        wait(1000);
        send(msg7.set(loadState(7)?RELAY_OFF:RELAY_ON),true);
        wait(1000);
        send(msg8.set(loadState(8)?RELAY_OFF:RELAY_ON),true);
        wait(1000);
        Serial.println("Sending initial value: Completed");
        wait(5000);
      }
    }
    
    void receive(const MyMessage &message) {
      Serial.println("=============== Receive Start =======================");
      if (message.isAck()) {
         Serial.println(">>>>> ACK <<<<<");
         Serial.println("This is an ack from gateway");
         Serial.println("<<<<<< ACK >>>>>>");
      }
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
        Serial.println(">>>>> V_LIGHT <<<<<");
        if (!initialValueSent) {
          Serial.println("Receiving initial value from controller");
          initialValueSent = true;
        }
         // Update relay state to HA
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         switch (message.sensor) {
            case 1:
              Serial.print("Incoming change for sensor 1");
              send(msg1.set(message.getBool()?RELAY_OFF:RELAY_ON));
              break;
            case 2:
              Serial.print("Incoming change for sensor 2");
              send(msg2.set(message.getBool()?RELAY_OFF:RELAY_ON));
              break;
            case 3:
              Serial.print("Incoming change for sensor 3");
              send(msg3.set(message.getBool()?RELAY_OFF:RELAY_ON));
              break;
            case 4:
              Serial.print("Incoming change for sensor 4");
              send(msg4.set(message.getBool()?RELAY_OFF:RELAY_ON));
              break;
            case 5:
              Serial.print("Incoming change for sensor 5");
              send(msg5.set(message.getBool()?RELAY_OFF:RELAY_ON));
              break;
            case 6:
              Serial.print("Incoming change for sensor 6");
              send(msg6.set(message.getBool()?RELAY_OFF:RELAY_ON));
              break;
            case 7:
              Serial.print("Incoming change for sensor 7");
              send(msg7.set(message.getBool()?RELAY_OFF:RELAY_ON));
              break;
            case 8:
              Serial.print("Incoming change for sensor 8");
              send(msg8.set(message.getBool()?RELAY_OFF:RELAY_ON));
              break;                               
            default: 
              Serial.println("Default Case: Receiving Other Sensor Child ID");
            break;
         }
         // Store state in Arduino eeprom
         saveState(message.sensor, message.getBool());
         Serial.print("Saved State for sensor: ");
         Serial.print( message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
         Serial.println("<<<<<< V_LIGHT >>>>>>");
       } 
       Serial.println("=============== Receive END =======================");
    }
    
    mfalkviddM 1 Reply Last reply
    0
    • M mrhutchinsonmn

      Is there a way to utilize pin D1 for my 8 relay module with this or a modified sketch? I understand from research that the serial commands are getting in the way but I am not sure how to work around this and need pins 8-13 for my radio. (Powering via vin)

      // Override Setting for Manual Node ID to 2
      #define MY_NODE_ID 51
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      
      // Enable repeater functionality for this node
      #define MY_REPEATER_FEATURE
      
      #include <SPI.h>
      #include <MySensors.h>
      
      #define RELAY_1  1          // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 8 // Total number of attached relays: 4
      
      // Opto Relay Module I was using Active Low - Low (0):ON, High (1): OFF
      #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
      
      bool initialValueSent = false;
      
      //Init MyMessage for Each Child ID
      MyMessage msg1(1, V_LIGHT);
      MyMessage msg2(2, V_LIGHT);
      MyMessage msg3(3, V_LIGHT);
      MyMessage msg4(4, V_LIGHT);
      MyMessage msg5(5, V_LIGHT);
      MyMessage msg6(6, V_LIGHT);
      MyMessage msg7(7, V_LIGHT);
      MyMessage msg8(8, V_LIGHT);
      
      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("Multiple Relay", "1c.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() 
      {
        if (!initialValueSent) {
          Serial.println("Sending initial value");
          send(msg1.set(loadState(1)?RELAY_OFF:RELAY_ON),true);
          wait(1000);
          send(msg2.set(loadState(2)?RELAY_OFF:RELAY_ON),true);
          wait(1000);
          send(msg3.set(loadState(3)?RELAY_OFF:RELAY_ON),true);
          wait(1000);
          send(msg4.set(loadState(4)?RELAY_OFF:RELAY_ON),true);
          wait(1000);
           send(msg5.set(loadState(5)?RELAY_OFF:RELAY_ON),true);
          wait(1000);
          send(msg6.set(loadState(6)?RELAY_OFF:RELAY_ON),true);
          wait(1000);
          send(msg7.set(loadState(7)?RELAY_OFF:RELAY_ON),true);
          wait(1000);
          send(msg8.set(loadState(8)?RELAY_OFF:RELAY_ON),true);
          wait(1000);
          Serial.println("Sending initial value: Completed");
          wait(5000);
        }
      }
      
      void receive(const MyMessage &message) {
        Serial.println("=============== Receive Start =======================");
        if (message.isAck()) {
           Serial.println(">>>>> ACK <<<<<");
           Serial.println("This is an ack from gateway");
           Serial.println("<<<<<< ACK >>>>>>");
        }
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_LIGHT) {
          Serial.println(">>>>> V_LIGHT <<<<<");
          if (!initialValueSent) {
            Serial.println("Receiving initial value from controller");
            initialValueSent = true;
          }
           // Update relay state to HA
           digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
           switch (message.sensor) {
              case 1:
                Serial.print("Incoming change for sensor 1");
                send(msg1.set(message.getBool()?RELAY_OFF:RELAY_ON));
                break;
              case 2:
                Serial.print("Incoming change for sensor 2");
                send(msg2.set(message.getBool()?RELAY_OFF:RELAY_ON));
                break;
              case 3:
                Serial.print("Incoming change for sensor 3");
                send(msg3.set(message.getBool()?RELAY_OFF:RELAY_ON));
                break;
              case 4:
                Serial.print("Incoming change for sensor 4");
                send(msg4.set(message.getBool()?RELAY_OFF:RELAY_ON));
                break;
              case 5:
                Serial.print("Incoming change for sensor 5");
                send(msg5.set(message.getBool()?RELAY_OFF:RELAY_ON));
                break;
              case 6:
                Serial.print("Incoming change for sensor 6");
                send(msg6.set(message.getBool()?RELAY_OFF:RELAY_ON));
                break;
              case 7:
                Serial.print("Incoming change for sensor 7");
                send(msg7.set(message.getBool()?RELAY_OFF:RELAY_ON));
                break;
              case 8:
                Serial.print("Incoming change for sensor 8");
                send(msg8.set(message.getBool()?RELAY_OFF:RELAY_ON));
                break;                               
              default: 
                Serial.println("Default Case: Receiving Other Sensor Child ID");
              break;
           }
           // Store state in Arduino eeprom
           saveState(message.sensor, message.getBool());
           Serial.print("Saved State for sensor: ");
           Serial.print( message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
           Serial.println("<<<<<< V_LIGHT >>>>>>");
         } 
         Serial.println("=============== Receive END =======================");
      }
      
      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @mrhutchinsonmn which Arduino are you using?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrhutchinsonmn
        wrote on last edited by
        #3

        Ardunio Nano

        mfalkviddM 1 Reply Last reply
        0
        • M mrhutchinsonmn

          Ardunio Nano

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

          @mrhutchinsonmn I think you use this

          #define MY_DISABLED_SERIAL
          

          Documentation: https://www.mysensors.org/apidocs/group__SerialDebugGrpPub.html#ga77b235511106d59e4ee2a1d9a919b49e

          M 1 Reply Last reply
          1
          • M Offline
            M Offline
            mrhutchinsonmn
            wrote on last edited by
            #5

            Will this mess with data sent to my home assistant controller, or only disable serial monitor and usb?

            1 Reply Last reply
            0
            • mfalkviddM mfalkvidd

              @mrhutchinsonmn I think you use this

              #define MY_DISABLED_SERIAL
              

              Documentation: https://www.mysensors.org/apidocs/group__SerialDebugGrpPub.html#ga77b235511106d59e4ee2a1d9a919b49e

              M Offline
              M Offline
              mrhutchinsonmn
              wrote on last edited by
              #6

              @mfalkvidd Got it! Had to put on top of sketch to get it to work.. Thank you!

              1 Reply Last reply
              0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              11

              Online

              12.1k

              Users

              11.2k

              Topics

              113.4k

              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