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
R

rodaman

@rodaman
About
Posts
9
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • 💬 Door, Window and Push-button Sensor
    R rodaman

    @hek said in 💬 Door, Window and Push-button Sensor:

    pinMode(i + FIRST_PIN, INPUT_PULLUP);

    Big Thanks!
    I have changed all array parts in setup in the same manner like above and it works :-)

    Announcements

  • 💬 Door, Window and Push-button Sensor
    R rodaman

    @rodaman
    Hi,
    Here is a sketch for multi buttons (no relays, no repeated parts of code for each buttons) just enter number of buttons and first digital pin where buttons are attached.
    Thanks to @hek for help...

    /**
       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 updated  for multi switches
       Connect buttons or door/window reed switches between
       digitial I/O choosen pin  (FIRST_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_GATEWAY_SERIAL
    
    //#include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define FIRST_PIN  2  // Arduino Digital I/O pin for button/reed switch
    #define noButtons 6
    
    
    Bounce debouncer[noButtons] = Bounce();
    
    int oldValue[noButtons];
    int value;
    MyMessage msg[noButtons];
    
    void setup() {
    
      for (int i = 0; i < noButtons; i++) {
    
        oldValue[i] = -1;
        
        msg[i].sensor = i;                                   // initialize messages
        msg[i].type = V_TRIPPED; //
        pinMode(i + FIRST_PIN, INPUT_PULLUP);
        digitalWrite(i + FIRST_PIN, HIGH);
      
        debouncer[i] = Bounce();                        // initialize debouncer
        debouncer[i].attach(i + FIRST_PIN);
        debouncer[i].interval(3);
      }
    }
    
    void presentation() {
      sendSketchInfo("Doors", "1.0");
      for (int i = 0; i < noButtons; i++)
        present(i, S_DOOR);                               // present sensor to gateway
    }
    
    
    //  Check if digital input has changed and send in new value
    void loop()
    {
      for (int i = 0; i < noButtons; i++) {
        debouncer[i].update();
    
        value = debouncer[i].read();
        if (value != oldValue[i]) {
        // Send in the new value
          send(msg[i].set(value == HIGH ? 1 : 0));
          oldValue[i] = value;
        }
     }
    }
    
    
    Announcements
  • Login

  • Don't have an account? Register

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