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. Development
  3. Arduino Pro MICRO Pinout for 8 channel Relay

Arduino Pro MICRO Pinout for 8 channel Relay

Scheduled Pinned Locked Moved Development
pro microanalog pin on ppinoutlibrary
15 Posts 7 Posters 10.3k Views 3 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.
  • P Offline
    P Offline
    Porky6666
    wrote on last edited by
    #5

    Ok, thanks

    ""// 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 SPI_CE 9
    //#define SPI_SS 10 // PB0, pin 8, Digital17
    //#define SPI_MISO 14 // PB3, pin 11, Digital14
    //#define SPI_MOSI 16 // PB2, pin 10, Digital16
    //#define SPI_SCK 15 // PB1, pin 9, Digital15
    //#define MySensor(uint8_t cepin = 9, uint8_t cspin = 10);
    #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define RELAY_2 4
    #define RELAY_3 5
    #define RELAY_4 6
    #define RELAY_5 7
    #define RELAY_6 18
    #define RELAY_7 19
    #define RELAY_8 20
    #define NUMBER_OF_RELAYS 8 // 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

    //MySensor(uint8_t cepin = 9, uint8_t cspin = 10) gw;
    MySensor gw;
    void setup()
    {
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(18, OUTPUT);
    pinMode(19, OUTPUT);
    pinMode(20, OUTPUT);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(18, HIGH);
    digitalWrite(19, HIGH);
    digitalWrite(20, HIGH);

    //MySensor(uint8_t cepin=9, uint8_t cspin=10)
    // 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");

    // 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);
    }
    }

    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
    digitalWrite(message.sensor-1+RELAY_1, 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());
    }
    }
    ""

    H 1 Reply Last reply
    0
    • P Porky6666

      Ok, thanks

      ""// 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 SPI_CE 9
      //#define SPI_SS 10 // PB0, pin 8, Digital17
      //#define SPI_MISO 14 // PB3, pin 11, Digital14
      //#define SPI_MOSI 16 // PB2, pin 10, Digital16
      //#define SPI_SCK 15 // PB1, pin 9, Digital15
      //#define MySensor(uint8_t cepin = 9, uint8_t cspin = 10);
      #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define RELAY_2 4
      #define RELAY_3 5
      #define RELAY_4 6
      #define RELAY_5 7
      #define RELAY_6 18
      #define RELAY_7 19
      #define RELAY_8 20
      #define NUMBER_OF_RELAYS 8 // 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

      //MySensor(uint8_t cepin = 9, uint8_t cspin = 10) gw;
      MySensor gw;
      void setup()
      {
      pinMode(3, OUTPUT);
      pinMode(4, OUTPUT);
      pinMode(5, OUTPUT);
      pinMode(6, OUTPUT);
      pinMode(7, OUTPUT);
      pinMode(18, OUTPUT);
      pinMode(19, OUTPUT);
      pinMode(20, OUTPUT);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, HIGH);
      digitalWrite(7, HIGH);
      digitalWrite(18, HIGH);
      digitalWrite(19, HIGH);
      digitalWrite(20, HIGH);

      //MySensor(uint8_t cepin=9, uint8_t cspin=10)
      // 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");

      // 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);
      }
      }

      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
      digitalWrite(message.sensor-1+RELAY_1, 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());
      }
      }
      ""

      H Offline
      H Offline
      hek
      Admin
      wrote on last edited by
      #6

      @Porky6666

      That will ot work as you don't actually use the GPIO-defines you created at the top of your sketch.

      I would probably have created an array with the pins you intend to use and loop over it when initializing and handling the commands from gateway.

      E.g.

      char[] pins = [3,4,5,6,7,18,19,20]; 
      for (int i=0;i<pins.length;i++) {
           pinMode(pin[i], OUTPUT); 
           digitalWrite(pin[i], HIGH);
      }
      

      And likewise when receiving controller commands.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Porky6666
        wrote on last edited by
        #7

        Hi,

        this ist the orginal example from this site, and so it works vor 5 relays.
        "// 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_2 4
        #define RELAY_3 5
        #define RELAY_4 6
        #define RELAY_5 7
        //#define RELAY_6 18
        //#define RELAY_7 19
        //#define RELAY_8 20
        #define NUMBER_OF_RELAYS 5 // 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

        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");

        // 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);
        }
        }

        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
        digitalWrite(message.sensor-1+RELAY_1, 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());
        }
        }
        "
        but not more.
        On an Arduino Pro Mini
        this sketch works for 6 Relays inkl. D8, i have changed to pro micro
        an i used 2 different new ones same result, 5 Relays working -- externel power supply to the relays, arduino only needs to pull up or pull down.

        bye
        Stefan
        thanks for your help

        1 Reply Last reply
        0
        • S Offline
          S Offline
          soward
          wrote on last edited by
          #8

          That sketch only works when the desired output pins are in numerical sequence. Once you need to use a variety of pin numbers in an arbitrary order, you will need to mange them differently.

          Using an array as Hek suggested is no doubt your best option.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Porky6666
            wrote on last edited by
            #9

            Hi,

            Thats a fact i'd. Never known,
            Thanks for your help.

            Stefan

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              Zeph
              Hero Member
              wrote on last edited by
              #10

              @Porky6666

              You can insert 4 spaces at the beginning of each line to show it as code here:

              // 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_2 4
              #define RELAY_3 5
              #define RELAY_4 6
              #define RELAY_5 7
              //#define RELAY_6 18
              //#define RELAY_7 19
              //#define RELAY_8 20
              
              #define NUMBER_OF_RELAYS 5 // 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
              
              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");
                  
                  // 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);
                  }
              }
              
              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
                      digitalWrite(message.sensor-1+RELAY_1, 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());
                  }
              }
              
              1 Reply Last reply
              0
              • S Offline
                S Offline
                sjoerd14
                wrote on last edited by
                #11

                Hi,

                Here is the example of the code using an 8 delay board.
                I used the Analog devices as much as possible because I intend to include 1-wire temp sensors as well.
                On my (clone) Mini there are 8 analog pins but useable on the bread board because of the location. I will use them in the final perfboard.

                  // Example sketch showing how to control physical relays. 
                  // This example will remember relay state even after power failure.
                  // Using an Array to define the pin's 
                
                #include <MySensor.h>
                #include <SPI.h>
                
                const int RELAY[] = {A0, A1, A2, A3, A4, 6, 7, 8}; // I/O pins for the relays
                #define NUMBER_OF_RELAYS 8 // 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
                
                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");
                
                  // Fetch relay status
                  for (int sensor=1, pin=0; 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(RELAY[pin], OUTPUT);   
                    // Set relay to last known state (using eeprom storage) 
                    digitalWrite(RELAY[pin], 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
                     digitalWrite(RELAY[message.sensor-1], 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());
                   } 
                }
                

                "

                greglG 1 Reply Last reply
                0
                • S sjoerd14

                  Hi,

                  Here is the example of the code using an 8 delay board.
                  I used the Analog devices as much as possible because I intend to include 1-wire temp sensors as well.
                  On my (clone) Mini there are 8 analog pins but useable on the bread board because of the location. I will use them in the final perfboard.

                    // Example sketch showing how to control physical relays. 
                    // This example will remember relay state even after power failure.
                    // Using an Array to define the pin's 
                  
                  #include <MySensor.h>
                  #include <SPI.h>
                  
                  const int RELAY[] = {A0, A1, A2, A3, A4, 6, 7, 8}; // I/O pins for the relays
                  #define NUMBER_OF_RELAYS 8 // 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
                  
                  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");
                  
                    // Fetch relay status
                    for (int sensor=1, pin=0; 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(RELAY[pin], OUTPUT);   
                      // Set relay to last known state (using eeprom storage) 
                      digitalWrite(RELAY[pin], 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
                       digitalWrite(RELAY[message.sensor-1], 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());
                     } 
                  }
                  

                  "

                  greglG Offline
                  greglG Offline
                  gregl
                  Hero Member
                  wrote on last edited by
                  #12

                  @sjoerd14 said:

                  1-wire temp sensors as well.

                  I learned the other day that you can use the "Analog" I/O for one-wire anyway? just treat them as they were digital!

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Porky6666
                    wrote on last edited by
                    #13

                    @sjoerd14

                    Great thx a lot -- is working fine your example.

                    bye
                    Stefan

                    jeylitesJ 1 Reply Last reply
                    0
                    • P Porky6666

                      @sjoerd14

                      Great thx a lot -- is working fine your example.

                      bye
                      Stefan

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

                      Hi, I'm trying to create an array of binary switches based on the 8Ch relay script, but I'm having issues setting it up. I don't have much knowledge in array and I was wondering if anyone here could guide me.

                      // Simple binary switch example 
                      // Connect button or door/window reed switch between 
                      // digitial I/O pin 3 (BUTTON_PIN below) and GND.
                      
                      #include <MySensor.h>
                      #include <SPI.h>
                      #include <Bounce2.h>
                      
                      const int BUTTON[] = {3, 4, 5};
                      #define NUMBER_OF_BUTTONS 3
                      //#define CHILD_ID 3
                      //#define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
                      
                      MySensor gw;
                      Bounce debouncer = Bounce(); 
                      int oldValue=-1;
                      
                      // Change to V_LIGHT if you use S_LIGHT in presentation below
                      MyMessage msg(V_TRIPPED);
                      
                      void setup()  
                      {  
                        gw.begin();
                      // Fetch relay status
                        for (int sensor=1, pin=0; sensor<=NUMBER_OF_BUTTONS;sensor++, pin++) {
                          
                       // Setup the button
                        pinMode(BUTTON[pin],INPUT);
                        // Activate internal pull-up
                        digitalWrite(BUTTON[pin],HIGH);
                        
                        // After setting up the button, setup debouncer
                        debouncer.attach(BUTTON[pin]);
                        debouncer.interval(5);
                        
                        // Register binary input sensor to gw (they will be created as child devices)
                        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
                        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
                        gw.present(sensor, S_DOOR);  
                        
                      
                      }
                      
                      //  Check if digital input has changed and send in new value
                      void loop() 
                      {
                        debouncer.update();
                        // Get the update value
                        int value = debouncer.read();
                       
                        if (value != oldValue) {
                           // Send in the new value
                           gw.send(msg.set(value==HIGH ? 1 : 0));
                           oldValue = value;
                        }
                      } 
                      
                      
                      jeylitesJ 1 Reply Last reply
                      0
                      • jeylitesJ jeylites

                        Hi, I'm trying to create an array of binary switches based on the 8Ch relay script, but I'm having issues setting it up. I don't have much knowledge in array and I was wondering if anyone here could guide me.

                        // Simple binary switch example 
                        // Connect button or door/window reed switch between 
                        // digitial I/O pin 3 (BUTTON_PIN below) and GND.
                        
                        #include <MySensor.h>
                        #include <SPI.h>
                        #include <Bounce2.h>
                        
                        const int BUTTON[] = {3, 4, 5};
                        #define NUMBER_OF_BUTTONS 3
                        //#define CHILD_ID 3
                        //#define BUTTON_PIN  3  // Arduino Digital I/O pin for button/reed switch
                        
                        MySensor gw;
                        Bounce debouncer = Bounce(); 
                        int oldValue=-1;
                        
                        // Change to V_LIGHT if you use S_LIGHT in presentation below
                        MyMessage msg(V_TRIPPED);
                        
                        void setup()  
                        {  
                          gw.begin();
                        // Fetch relay status
                          for (int sensor=1, pin=0; sensor<=NUMBER_OF_BUTTONS;sensor++, pin++) {
                            
                         // Setup the button
                          pinMode(BUTTON[pin],INPUT);
                          // Activate internal pull-up
                          digitalWrite(BUTTON[pin],HIGH);
                          
                          // After setting up the button, setup debouncer
                          debouncer.attach(BUTTON[pin]);
                          debouncer.interval(5);
                          
                          // Register binary input sensor to gw (they will be created as child devices)
                          // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
                          // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
                          gw.present(sensor, S_DOOR);  
                          
                        
                        }
                        
                        //  Check if digital input has changed and send in new value
                        void loop() 
                        {
                          debouncer.update();
                          // Get the update value
                          int value = debouncer.read();
                         
                          if (value != oldValue) {
                             // Send in the new value
                             gw.send(msg.set(value==HIGH ? 1 : 0));
                             oldValue = value;
                          }
                        } 
                        
                        
                        jeylitesJ Offline
                        jeylitesJ Offline
                        jeylites
                        wrote on last edited by
                        #15

                        In addition to my message above, I'm getting a bunch of errors when I try to compile the above binary sketch. Hope to hear from some one.

                        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


                        55

                        Online

                        12.0k

                        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