Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. rayan
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by rayan

    • RE: Multi Button Relay Sketch

      @Boots33
      hi my friend.
      i use your sketch and thank you.but there is a problem.
      sketchs in site , when relay is fail , when i send command , so show to me "Error sending switch command, check device/hardware !" but your sketch dont show this error. so i dont understand relay is fail or no , when we are out home. can you fix this ?

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @pepson
      i dont have a ready sketch! wait to boots answer

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @pepson

      @Boots33 can solve this maybe because i dont work with Bounce2 lib.

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      ack is a feedback . is this true ? so when i am out of home and i want turn on light , so ack show me that light is on or no ! also when there is a problem in connection and ack dont receive, so node search and found a new way for connection.
      now i dont have a arduino and radio for test 🙂 but do you think this code will be ok ?without else.

      void loop()
      {
       if (!isTransportOK())
      {
      if (...)            //if change switch to up or down
      ...                 //change state of relay
      if(isTransportOK())
      send(msg.set(state ? true : false), true);  // (last state)
      }
        
        debouncer.update();
        // Get the update value
        int value = debouncer.read();
        if (value != oldValue && value == 0) {
          send(msg.set(state ? false : true), true); // Send new state and request ack back
        }
        oldValue = value;
      }
      

      (i can not work with Bounce2 library 🙂 ) please help to fill lines
      in loop we add a "if (!isTransportOK())" and write when change switch (on/off) state of relay change and this is repeat until connection will be ok ! so send a ack and for continue follow your code...
      is this right ? can you do this change ?

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      ack is important , so we can not found any solution for this ? for exapmle add a code to this sketch , that when radio is disconnect so without ack work and when radio is ok this way stop and with ack work again.
      this idea is for when a radio have problem or fail or other reason... so this light or other divece dont stop working and work handy when radio go to correct or change radio....

      if you can change your code and add this option , so your sketch is best code for light control

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @pepson
      i am beginner and i hope some one help to you

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33 this your code is good, but there is a small issue .button work just when the connection is ok (radio with gateway) ! and when radio is disconnect or controller is off, so button dont work handy . do you have any idea for this ? that when controller is off the button work handy

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @pepson
      go to : file > examples > mysensors > clear eeprom config
      and select arduino pro mini from : tools > board > arduino pro or pro mini

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      thank you very much

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      oh , after added this device , happen a Event ! node id of motion sensor and this device is 1 ! and after sense of motion light on in dashborad ! why both Catch node id 1 .
      i dont add #define node id for motion and for this. but both take id 1 and Interference

      0_1475589467935_mdmddmdmd.jpg

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      great.
      so this is best sketch 🙂
      thank you

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33 said:

      i test your code and this is excellent . but there is another tiny problem 🙂
      when relay is ON then loses power so in app relay is ON (icon) , when power is restored and relay go to OFF in app icon is ON and dont Ack for go to show Off .
      you are best in programming 🙂

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33 said:

      @rayan yes it was meant to be used with push buttons not toggle switches. It will need a few tweaks to make it work. I am at work now so will take a look when I get home.

      ok thank you

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      but this app , every time after the restored power and startup, relay ( related to state of up/down switch) have different state

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      yes, all of lights are on or off (some on some off) so when looses power and power is restored , i want all of lights be off also in web and app light = off , so with key in app or change state of switch turn on again ...

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      i want if power of home be off and after time on again , so all of relay ( with switch up/down with each state) to be off. now in this code after startup relay is unstable for 1s and my light is on and aff quickly 🙂
      also if lights are off , if power off/on , so some of relay go to ON in startup !

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      you are set value for relay in code

        digitalWrite(relayPinA, RELAY_OFF);
        digitalWrite(relayPinB, RELAY_OFF);
      

      but i dont know why after start up . . .

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      this is your code 🙂

      #define MY_DEBUG
      #define MY_RADIO_NRF24
      #define MY_REPEATER_FEATURE
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      
      #define RELAY_ON 1
      #define RELAY_OFF 0
      
      #define SSR_A_ID 1   // Id of the sensor child
      #define SSR_B_ID 2   // Id of the sensor child
      
      const int buttonPinA = 18;
      const int buttonPinB = 19;
      const int relayPinA = 5;
      const int relayPinB = 6;
      int oldValueA = 0;
      int oldValueB = 0;
      bool stateA = false;
      bool stateB = false;
      
      
      
      Bounce debouncerA = Bounce();
      Bounce debouncerB = Bounce();
      
      MyMessage msgA(SSR_A_ID, V_STATUS);
      MyMessage msgB(SSR_B_ID, V_STATUS);
      
      void setup()
      {
      
        pinMode(buttonPinA, INPUT_PULLUP); // Setup the button Activate internal pull-up
        pinMode(buttonPinB, INPUT_PULLUP); // Setup the button Activate internal pull-up
      
      
        // After setting up the buttons, setup debouncer
        debouncerA.attach(buttonPinA);
        debouncerA.interval(5);
        debouncerB.attach(buttonPinB);
        debouncerB.interval(5);
      
        // Make sure relays are off when starting up
        digitalWrite(relayPinA, RELAY_OFF);
        digitalWrite(relayPinB, RELAY_OFF);
        // Then set relay pins in output mode
        pinMode(relayPinA, OUTPUT);
        pinMode(relayPinB, OUTPUT);
        
      }
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Mains Controller", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(SSR_A_ID, S_LIGHT);
        present(SSR_B_ID, S_LIGHT);
      
      }
      
      /*
         Example on how to asynchronously check for new messages from gw
      */
      void loop()
      {
        debouncerA.update();
        // Get the update value
        int valueA = debouncerA.read();
        if (valueA != oldValueA) {
          send(msgA.set(stateA ? false : true), true); // Send new state and request ack back
        oldValueA = valueA;
        }
       
      
        debouncerB.update();
        // Get the update value
        int valueB = debouncerB.read();
        if (valueB != oldValueB) {
          send(msgB.set(stateB ? false : true), true); // Send new state and request ack back
        oldValueB = valueB;
        }
      }
      
      void receive(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type == V_STATUS) {
            
          switch (message.sensor) {
            case 1:
              stateA = message.getBool();
              digitalWrite(message.sensor + 4, stateA ? RELAY_ON : RELAY_OFF);
              
              break;
            case 2:
              stateB = message.getBool();
              digitalWrite(message.sensor + 4, stateB ? RELAY_ON : RELAY_OFF);
              
              break;
            
          }
         
            // Write some debug info
          Serial.print("Incoming change for sensor:");
          Serial.println(message.sensor);
          Serial.print("from node:");
          Serial.println(message.sender);
          Serial.print(", New status: ");
          Serial.println(message.getBool());
        }
      }
      
      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      this is great
      but have a tiny problem
      with power off/on , relay state is unstable every time . i could not fix this . can you fix ? with power off/on relay to be high every time . different state of relay and button have influence on relay state after power off/on . often with power off/on , there are a change state low to high or high to low quickly.
      in other means , in startup if switch be down or up , dont Make sure relays are off when starting up

      also state in web is not correct

      posted in Development
      rayan
      rayan
    • RE: Multi Button Relay Sketch

      @Boots33
      if i want use an up/down switch (no push switch) that with each change (up or down) , relay state change . for example if relay is "on" and switch is "down" , with change switch to "up" relay to be "off" OR if relay is "off" and switch is "down" , with change switch to "up" relay to be "on"
      in sketch , what am i do ?

      posted in Development
      rayan
      rayan