Skip to content
  • 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. Multiple motion/door sketch
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Multiple motion/door sketch

Scheduled Pinned Locked Moved Development
2 Posts 2 Posters 1.4k 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.
  • B Offline
    B Offline
    bluezr1
    wrote on last edited by bluezr1
    #1

    I like to use store bought PIR motion sensors and have them trigger a Pam-1 relay due to their quality and being much safer. I’ve been using heks Door, Window and Push-button sketch with S_MOTION/S_DOOR. This way I only have to short one of the pins to ground.

    Well today I took the multi button relay sketch and combined it with heks sketch allowing me to have multiple motions on one pro mini.

    Here’s the sketch with two motions

    /**
     * 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 <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * 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.
     *
     *******************************
     *
     * DESCRIPTION
     *
     * Simple binary switch example 
     * Connect button or door/window reed switch between 
     * digitial I/O pin 3 (BUTTON_PIN below) and GND.
     * http://www.mysensors.org/build/binary
     */
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_NODE_ID 12
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define SSR_A_ID 1   // Id of the sensor child
    #define SSR_B_ID 2   // Id of the sensor child
    
    const int buttonPinA = 2;
    const int buttonPinB = 3;
    
    int oldValueA = 0;
    int oldValueB = 0;
    
    bool stateA = false;
    bool stateB = false;
    
    Bounce debouncerA = Bounce();
    Bounce debouncerB = Bounce(); 
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msgA(SSR_A_ID, V_TRIPPED);
    MyMessage msgB(SSR_B_ID, V_TRIPPED);
    
    void setup()  
    {  
      // Setup the button
      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);
    
    }
    
    void presentation() {
      // 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.
      present(SSR_A_ID, S_MOTION);
      present(SSR_B_ID, S_MOTION);   
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop()
    {
      debouncerA.update();
       // Get the update value
      int valueA = debouncerA.read();
    
      if (valueA != oldValueA) {
         // Send in the new value
         send(msgA.set(valueA==HIGH ? 0 : 1));
         oldValueA = valueA;
        
      }
     
      debouncerB.update();
      // Get the update value
       int valueB = debouncerB.read();
    
      if (valueB != oldValueB) {
         // Send in the new value
         send(msgB.set(valueB==HIGH ? 0 : 1));
         oldValueB = valueB;
      }
    }```
    
    

    Here's one with three motions

    /**
     * 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 <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * 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.
     *
     *******************************
     *
     * DESCRIPTION
     *
     * Simple binary switch example 
     * Connect button or door/window reed switch between 
     * digitial I/O pin 3 (BUTTON_PIN below) and GND.
     * http://www.mysensors.org/build/binary
     */
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_NODE_ID 11
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define SSR_A_ID 1   // Id of the sensor child
    #define SSR_B_ID 2   // Id of the sensor child
    #define SSR_C_ID 3   // Id of the sensor child
    
    const int buttonPinA = 2;
    const int buttonPinB = 3;
    const int buttonPinC = 4;
    
    int oldValueA = 0;
    int oldValueB = 0;
    int oldValueC = 0;
    
    bool stateA = false;
    bool stateB = false;
    bool stateC = false;
    
    Bounce debouncerA = Bounce();
    Bounce debouncerB = Bounce(); 
    Bounce debouncerC = Bounce();
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msgA(SSR_A_ID, V_TRIPPED);
    MyMessage msgB(SSR_B_ID, V_TRIPPED);
    MyMessage msgC(SSR_C_ID, V_TRIPPED);
    
    void setup()  
    {  
      // Setup the button
      pinMode(buttonPinA, INPUT_PULLUP); // Setup the button Activate internal pull-up
      pinMode(buttonPinB, INPUT_PULLUP); // Setup the button Activate internal pull-up
      pinMode(buttonPinC, 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);
      debouncerC.attach(buttonPinC);
      debouncerC.interval(5);
    
    }
    
    void presentation() {
      // 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.
      present(SSR_A_ID, S_MOTION);
      present(SSR_B_ID, S_MOTION);
      present(SSR_C_ID, S_MOTION);   
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop()
    {
      debouncerA.update();
       // Get the update value
      int valueA = debouncerA.read();
    
      if (valueA != oldValueA) {
         // Send in the new value
         send(msgA.set(valueA==HIGH ? 0 : 1));
         oldValueA = valueA;
        
      }
     
      debouncerB.update();
      // Get the update value
       int valueB = debouncerB.read();
    
      if (valueB != oldValueB) {
         // Send in the new value
         send(msgB.set(valueB==HIGH ? 0 : 1));
         oldValueB = valueB;
    
      }
    
      debouncerC.update();
      // Get the update value
       int valueC = debouncerC.read();
    
      if (valueC != oldValueC) {
         // Send in the new value
         send(msgC.set(valueC==HIGH ? 0 : 1));
         oldValueC = valueC;
      }
    }```
    rejoe2R 1 Reply Last reply
    2
    • B bluezr1

      I like to use store bought PIR motion sensors and have them trigger a Pam-1 relay due to their quality and being much safer. I’ve been using heks Door, Window and Push-button sketch with S_MOTION/S_DOOR. This way I only have to short one of the pins to ground.

      Well today I took the multi button relay sketch and combined it with heks sketch allowing me to have multiple motions on one pro mini.

      Here’s the sketch with two motions

      /**
       * 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 <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * 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.
       *
       *******************************
       *
       * DESCRIPTION
       *
       * Simple binary switch example 
       * Connect button or door/window reed switch between 
       * digitial I/O pin 3 (BUTTON_PIN below) and GND.
       * http://www.mysensors.org/build/binary
       */
      
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_NODE_ID 12
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      
      #define SSR_A_ID 1   // Id of the sensor child
      #define SSR_B_ID 2   // Id of the sensor child
      
      const int buttonPinA = 2;
      const int buttonPinB = 3;
      
      int oldValueA = 0;
      int oldValueB = 0;
      
      bool stateA = false;
      bool stateB = false;
      
      Bounce debouncerA = Bounce();
      Bounce debouncerB = Bounce(); 
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msgA(SSR_A_ID, V_TRIPPED);
      MyMessage msgB(SSR_B_ID, V_TRIPPED);
      
      void setup()  
      {  
        // Setup the button
        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);
      
      }
      
      void presentation() {
        // 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.
        present(SSR_A_ID, S_MOTION);
        present(SSR_B_ID, S_MOTION);   
      }
      
      
      //  Check if digital input has changed and send in new value
      void loop()
      {
        debouncerA.update();
         // Get the update value
        int valueA = debouncerA.read();
      
        if (valueA != oldValueA) {
           // Send in the new value
           send(msgA.set(valueA==HIGH ? 0 : 1));
           oldValueA = valueA;
          
        }
       
        debouncerB.update();
        // Get the update value
         int valueB = debouncerB.read();
      
        if (valueB != oldValueB) {
           // Send in the new value
           send(msgB.set(valueB==HIGH ? 0 : 1));
           oldValueB = valueB;
        }
      }```
      
      

      Here's one with three motions

      /**
       * 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 <henrik.ekblad@mysensors.org>
       * Copyright (C) 2013-2015 Sensnology AB
       * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
       *
       * Documentation: http://www.mysensors.org
       * Support Forum: http://forum.mysensors.org
       *
       * 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.
       *
       *******************************
       *
       * DESCRIPTION
       *
       * Simple binary switch example 
       * Connect button or door/window reed switch between 
       * digitial I/O pin 3 (BUTTON_PIN below) and GND.
       * http://www.mysensors.org/build/binary
       */
      
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_NODE_ID 11
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      
      #define SSR_A_ID 1   // Id of the sensor child
      #define SSR_B_ID 2   // Id of the sensor child
      #define SSR_C_ID 3   // Id of the sensor child
      
      const int buttonPinA = 2;
      const int buttonPinB = 3;
      const int buttonPinC = 4;
      
      int oldValueA = 0;
      int oldValueB = 0;
      int oldValueC = 0;
      
      bool stateA = false;
      bool stateB = false;
      bool stateC = false;
      
      Bounce debouncerA = Bounce();
      Bounce debouncerB = Bounce(); 
      Bounce debouncerC = Bounce();
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msgA(SSR_A_ID, V_TRIPPED);
      MyMessage msgB(SSR_B_ID, V_TRIPPED);
      MyMessage msgC(SSR_C_ID, V_TRIPPED);
      
      void setup()  
      {  
        // Setup the button
        pinMode(buttonPinA, INPUT_PULLUP); // Setup the button Activate internal pull-up
        pinMode(buttonPinB, INPUT_PULLUP); // Setup the button Activate internal pull-up
        pinMode(buttonPinC, 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);
        debouncerC.attach(buttonPinC);
        debouncerC.interval(5);
      
      }
      
      void presentation() {
        // 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.
        present(SSR_A_ID, S_MOTION);
        present(SSR_B_ID, S_MOTION);
        present(SSR_C_ID, S_MOTION);   
      }
      
      
      //  Check if digital input has changed and send in new value
      void loop()
      {
        debouncerA.update();
         // Get the update value
        int valueA = debouncerA.read();
      
        if (valueA != oldValueA) {
           // Send in the new value
           send(msgA.set(valueA==HIGH ? 0 : 1));
           oldValueA = valueA;
          
        }
       
        debouncerB.update();
        // Get the update value
         int valueB = debouncerB.read();
      
        if (valueB != oldValueB) {
           // Send in the new value
           send(msgB.set(valueB==HIGH ? 0 : 1));
           oldValueB = valueB;
      
        }
      
        debouncerC.update();
        // Get the update value
         int valueC = debouncerC.read();
      
        if (valueC != oldValueC) {
           // Send in the new value
           send(msgC.set(valueC==HIGH ? 0 : 1));
           oldValueC = valueC;
        }
      }```
      rejoe2R Offline
      rejoe2R Offline
      rejoe2
      wrote on last edited by
      #2

      @bluezr1 Good progress!
      In case you are interested in how to shorten this kind of code and be more flexible in assigning PINs, you may have a look at this post here: https://forum.mysensors.org/topic/4847/multi-button-relay-sketch/33# by @korttoma
      Just delete the relay part...

      Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

      1 Reply Last reply
      1
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      9

      Online

      11.7k

      Users

      11.2k

      Topics

      113.0k

      Posts


      Copyright 2019 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
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular