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
T

Terence Faul

@Terence Faul
About
Posts
48
Topics
23
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Multi Button Relay switch
    T Terence Faul

    @BulldogLowell

    This new one had the relays correct, but the buttons did not work. I compared the old with the new and below now works.

    Thanks again a million for all the help

    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    #define RELAY_ON 0
    #define RELAY_OFF 1
    
    //
    MySensor gw;
    const int relayPin[] = {7, 8, A0, A1};
    const int buttonPin[sizeof(relayPin) / sizeof(relayPin[0])] = {3, 4, 5, 6};
    byte oldValue[sizeof(relayPin) / sizeof(relayPin[0])];
    boolean relayState[sizeof(relayPin) / sizeof(relayPin[0])];
    
    Bounce debouncer[sizeof(relayPin) / sizeof(relayPin[0])];
    
    MyMessage msg[sizeof(relayPin) / sizeof(relayPin[0])];//(sensor,type);
    
    void setup()  
    {  
      Serial.begin(115200);
      gw.begin(incomingMessage, AUTO, false);
      //
      // or you can try:
      // gw.begin(incomingMessage, <Your_Node_ID>, false); // where Your_Node_ID is a number from 1 to 254
      //
      delay(250);
      gw.sendSketchInfo("MultiRelayButton", "0.9b");// <<<<<<<<<<<<<<<<<<< I forgot this, here
      //
      delay(250);
      for (int i = 0; i < sizeof(relayPin) / sizeof(relayPin[0]); i++)
      {
        msg[i].sensor = i;
        msg[i].type = V_LIGHT;
        debouncer[i] = Bounce();
        debouncer[i].attach(buttonPin[i]);
        debouncer[i].interval(5);
        pinMode(buttonPin[i], INPUT_PULLUP);
        digitalWrite(relayPin[i], LOW);
        pinMode(relayPin[i], OUTPUT);
        gw.present(i, S_LIGHT); // <<<<<<<<<<<<<<<<<<<<<<< I fixed this too...
        delay(250);
      }
      //retreive from EEPROM last states
      for (int i = 0; i < sizeof(relayPin) / sizeof(relayPin[0]); i++)
      {
        relayState[i] = gw.loadState(i);
        digitalWrite(relayPin[i], relayState[i]? RELAY_ON : RELAY_OFF);
        gw.send(msg[i].set(relayState[i]? true : false), true);
        delay(250);
      }
    }
    //
    void loop() 
    {
      gw.process();
      for (byte i = 0; i < sizeof(relayPin) / sizeof(relayPin[0]); i++)
      {
        debouncer[i].update();
        byte value = debouncer[i].read();
        if (value != oldValue[i] && value == 0)
        {
          relayState[i] = !relayState[i];
          digitalWrite(relayPin[i], relayState[i]);
          gw.send(msg[i].set(relayState[i]? true : false), true);
        }
        oldValue[i] = value;
      }
    }
    //
    void incomingMessage(const MyMessage &message)
    {
      if (message.isAck()) 
      {
        Serial.println(F("This is an ack from gateway"));
      }
      for (byte i = 0; i< sizeof(relayPin) / sizeof(relayPin[0]); i++)
      {
        if (message.sensor == i)
        {
          if (message.type == V_LIGHT)
          {
            relayState[i] = message.getBool();
            digitalWrite(relayPin[i], relayState[i]? RELAY_ON : RELAY_OFF); 
            gw.saveState(relayPin[i], relayState[i]);
          }
        }
      }
    }
    
    Hardware

  • Battery reporting
    T Terence Faul

    Hi

    is it possible to implement battery reporting as in

    https://github.com/mysensors/MySensorsArduinoExamples/blob/master/examples/Si7021TemperatureAndHumiditySensor/Si7021TemperatureAndHumiditySensor.ino

    in other sketches so one does not need the resisters as in the battery reporting section

    General Discussion

  • Multi Button Relay switch
    T Terence Faul

    @Terence-Faul
    Only one other thing.

    I notice that when the sensor starts up, each of the relays turn on and then off.

    This ia all good and well, however i assume in practice this would mean what ever is connected to them will turn on and off as well in the initialisation phase.

    Also I assume that retrieve from EEPROM means that if the sensor loses power while a relay is on, when it powers up this relay will return to the on state?

    Can you point me to to code that controls this, if these are lights and the power goes out a better option may be to have the relays all start in the off position so that the lights do not come on in the middle of the night

    Is this correct?

    Hardware
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular