VERA / Arduino Integration

  • Hello,
    I am new to this site. I was directed to this site from the VERA forums. I am trying to integrate an Arduino with VERA. I am reading about the different Gateways and such. The Ethernet Gateway looks good but I do not need the wireless / radio devices. The project I am trying to accomplish....I have 2 out buildings out of range of ZWave and WIFI but I have Ethernet cable run to each of the buildings. I would like to put an Arduino in each of the buildings. I need about 6 digital inputs and a few digital outputs on each board. Door switches, etc. Nothing fancy here. The buildings are pole buildings so running wire is very easy. I saw the examples relay control and door/window button. I would like to combine the 2 without the radio units. Basically, use the I/O on the Gateway Arduino. Is this possible? Also, is it possible to use 2 Ethernet Gateways on a VERA? BTW I have the MySensors Plugin running / installed and running on Vera. I have a basic understanding of Arduino. Any suggestions / comments / directions would be greatly appreciated.
    Thank you.

  • Hero Member

    Yes it is possible to run I/O on a Ethernet Gateway without radio unit
    Yes it is possible to have multiple Gateways connected to the same Vera, you just add another plugin device and use different IP for it. Remember to also use different MAC address for each GW in the sketch.

    Not sure how up to date this example is because I have not updated my devices for a year or 2 but I think you get the idea.
    Example sketch:

     * 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 <>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list:
     * Documentation:
     * Support Forum:
     * 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.
     * Version 1.0 - Henrik EKblad
     * Contribution by a-lurker and Anticimex,
     * Contribution by Norbert Truchsess <>
     * Contribution by Tomas Hozza <>
     * The EthernetGateway sends data received from sensors to the ethernet link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     * LED purposes:
     * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error
     * See for wiring instructions.
    // Enable debug prints to serial monitor
    //#define MY_DEBUG 
    #define SN "EthGW/RFM69 Rele Button"
    #define SV "1.1"
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    #define MY_RFM69_FREQUENCY RF69_433MHZ
    #define MY_IS_RFM69HW
    #define MY_RF69_SPI_CS 4  //try changeing this to 9
    // Enable gateway ethernet module type 
    #define MY_GATEWAY_W5100
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 10  
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with 
    // radio on the same spi bus.
    // Enable to UDP          
    //#define MY_USE_UDP
    #define MY_IP_ADDRESS 192,168,1,100   // If this is disabled, DHCP is used to retrieve address
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003      
    // Controller ip address. Enables client mode (default is "server" mode). 
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. 
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254   
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xED, 0xED
    // Flash leds on rx/tx/err
    // Set blinking period
    // Enable inclusion mode
    // Enable Inclusion mode button on gateway
    // Set inclusion mode duration (in seconds)
    // Digital pin used for inclusion mode button
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  9  // the PCB, on board LED
    #include <SPI.h>
    #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
    #include <Ethernet.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    #define RELAY_ON 0                      // switch around for ACTIVE LOW / ACTIVE HIGH relay
    #define RELAY_OFF 1
    #define noRelays 4                     //2-4
    const int relayPin[] = {14, 15, 16, 17};       //  switch around pins to your desire
    const int buttonPin[] = {7, 8, 5, 6};   //  switch around pins to your desire
    class Relay             // relay class, store all relevant data (equivalent to struct)
        int buttonPin;                   // physical pin number of button
        int relayPin;             // physical pin number of relay
        boolean relayState;               // relay status (also stored in EEPROM)
    Relay Relays[noRelays];
    Bounce debouncer[noRelays];
    MyMessage msg[noRelays];
    void setup() {
      // 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;
        pinMode(Relays[i].buttonPin, INPUT_PULLUP);
        pinMode(Relays[i].relayPin, OUTPUT);
        Relays[i].relayState = loadState(i);                               // retrieve last values from EEPROM
        digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
        send(msg[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status
        debouncer[i] = Bounce();                        // initialize debouncer
    void presentation()
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(SN, SV);
      for (int i = 0; i < noRelays; i++)
        present(i, S_LIGHT);                               // present sensor to gateway
    void loop()
      for (byte i = 0; i < noRelays; i++) {
        if (debouncer[i].update()) {
          int value = debouncer[i].read();
          if ( value == LOW) {
            Relays[i].relayState = !Relays[i].relayState;
            digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF);
            send(msg[i].set(Relays[i].relayState ? true : false));
            // save sensor state in EEPROM (location == sensor number)
            saveState( i, Relays[i].relayState );
    void receive(const MyMessage &message) {
      if (message.sender == 0) {
        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
            saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)

  • Thank you for your reply. If I am looking at this code right, you have 4 inputs and 4 outputs, is this correct?

  • Hero Member

    @sparky60 yes, 4 inputs and 4 outputs. It should be easy to modify if you need a different amount.