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
  1. Home
  2. Development
  3. Is this completely wrong?

Is this completely wrong?

Scheduled Pinned Locked Moved Development
3 Posts 2 Posters 1.1k Views 2 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.
  • xydixX Offline
    xydixX Offline
    xydix
    wrote on last edited by
    #1

    Hi.
    I am about to set up a battery-switch-node with Home Assistant as controller.
    It's a mini pro 3V3 with led and regulator removed.
    I am trying two different sketches and will try to get low power consumption .

    Here i use pin 3 and ground.

    #include <MySensor.h>
    #include <SPI.h>
    
    #define SN "TestSleepSensor"
    #define SV "1.0"
    
    #define CHILD_ID 3
    
    #define BUTTON_PIN 3   // Arduino Digital I/O pin for button/reed switch
    
     
    MySensor sensor_node;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      sensor_node.begin();
    
      // Setup the buttons
      pinMode(BUTTON_PIN, INPUT_PULLUP);
      
      // Send the sketch version information to the gateway and Controller
      sensor_node.sendSketchInfo(SN, SV);
    
      // Register binary input sensor to sensor_node (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.
      sensor_node.present(CHILD_ID, S_DOOR);  
    }
    
    // Loop will iterate on changes on the BUTTON_PINs
    void loop() 
    {
      uint8_t value;
      static uint8_t sentValue=2;
    
      // Short delay to allow buttons to properly settle
      sensor_node.sleep(5);
      
      value = digitalRead(BUTTON_PIN);
      
      if (value != sentValue) {
         // Value has changed from last transmission, send the updated value
         sensor_node.send(msg.set(value==LOW ? 1 : 0));
         sentValue = value;
      }
    
      // Sleep until something happens with the sensor
      sensor_node.sleep(BUTTON_PIN-2, CHANGE, 0);
    }
    

    This seems to work. I can't tell if it's good or not. Its my first, a example i chaged.
    It consumes about 0.09mA when the connector is closed witch it will be most of the time.
    When switch is open it consumes less.

    Here i use pin 3 and VCC

    #include <MySensor.h>
    #include <SPI.h>
    
    #define SN "TestSleepSensor"
    #define SV "1.0"
    
    #define CHILD_ID 3
    
    #define BUTTON_PIN 3   // Arduino Digital I/O pin for button/reed switch
    
     
    MySensor sensor_node;
    
    // Change to V_LIGHT if you use S_LIGHT in presentation below
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    void setup()  
    {  
      sensor_node.begin();
    
      // Setup the buttons
      pinMode(BUTTON_PIN, INPUT);
      
      // Send the sketch version information to the gateway and Controller
      sensor_node.sendSketchInfo(SN, SV);
    
      // Register binary input sensor to sensor_node (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.
      sensor_node.present(CHILD_ID, S_DOOR);  
    }
    
    // Loop will iterate on changes on the BUTTON_PINs
    void loop() 
    {
      uint8_t value;
      static uint8_t sentValue=2;
    
      // Short delay to allow buttons to properly settle
      sensor_node.sleep(5);
      
      value = digitalRead(BUTTON_PIN);
      
      if (value != sentValue) {
         // Value has changed from last transmission, send the updated value
         sensor_node.send(msg.set(value==HIGH ? 1 : 0));
         sentValue = value;
      }
    
      // Sleep until something happens with the sensor
      sensor_node.sleep(BUTTON_PIN-2, CHANGE, 0);
    }
    

    This consumes less when the switch is closed, approx 1.2uA according to my multimeter. it seems very low but anyway, it's much lower than the other sketch.
    One thing with this. When door is open it shows closed in the controller and the other way around. Can i fix it?
    Another thing. When i open my switch, it takes about 2-3 seconds before it send the changed state. Not a problem but i guess it is since i feed the pin directly from VCC?

    Is this stupid? I am New to this.

    1 Reply Last reply
    0
    • korttomaK Offline
      korttomaK Offline
      korttoma
      Hero Member
      wrote on last edited by
      #2

      @xydix

      Try changeing this line:

      sensor_node.send(msg.set(value==HIGH ? 1 : 0)); 
      

      To this:

      sensor_node.send(msg.set(value==HIGH ? 0 : 1)); 
      
      • Tomas
      1 Reply Last reply
      0
      • xydixX Offline
        xydixX Offline
        xydix
        wrote on last edited by
        #3

        Thank you. That will get it right.
        But now I get the delay when the door open.
        I guess I need a pull down resistor for this to work. 4.7k? 10k?
        I guess it's the internal pull up that consumes power?
        Another thing.
        I changed digitalWrite = HIGH (original example)
        to
        Pinmode INPUT_PULLUP
        in my first sketch

        Wich option is best if I want low power consumption?

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


        19

        Online

        11.7k

        Users

        11.2k

        Topics

        113.0k

        Posts


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