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. Help with sleeping door sensor

Help with sleeping door sensor

Scheduled Pinned Locked Moved Development
5 Posts 3 Posters 1.7k 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.
  • U Offline
    U Offline
    ustredna
    wrote on last edited by ustredna
    #1

    Hi friend i need help with my code of sleeping door sensor.

    i need add sending actual status of digital input and battery level and send this info each 7 seconds to GW.

    #define MY_DEBUG
    #define MY_RADIO_NRF24
    uint8_t NodeID = 88;
    #define MY_NODE_ID NodeID
    #define MY_PARENT_NODE_ID 0
    uint8_t RF24_Channel = 30;
    #define MY_RF24_CHANNEL RF24_Channel
    
    #define LED_PIN 17
    #define PRIMARY_BUTTON_PIN 3   // Arduino Digital I/O pin for button/reed switch
    #define SECONDARY_BUTTON_PIN 2 // Arduino Digital I/O pin for button/reed switch
    
    unsigned long SLEEP_TIME = 7000; // Sleep time between tX
    
    #include <MySensors.h>
    
    #define SKETCH_NAME "Door RF Sensor"
    #define SKETCH_MAJOR_VER "1"
    #define SKETCH_MINOR_VER "1"
    #define PRIMARY_CHILD_ID 1
    #define SECONDARY_CHILD_ID 2
    
    
    MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
    MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
    
    
    void before () {
      // Setup the buttons
      pinMode(PRIMARY_BUTTON_PIN, INPUT);
      pinMode(SECONDARY_BUTTON_PIN, INPUT);
    
      // Activate internal pull-ups
      digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
      digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
      pinMode(LED_PIN, OUTPUT);
      
      
     }
    
    void setup()
    {
    }
    
    void presentation()
    {
    	sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
    	present(PRIMARY_CHILD_ID, S_DOOR);
    	present(SECONDARY_CHILD_ID, S_DOOR);
    }
    
    void loop()
    {
    	uint8_t value;
    	static uint8_t sentValue=2;
    	static uint8_t sentValue2=2;
      
    	// Short delay to allow buttons to properly settle
    	sleep(5);
    
    	value = digitalRead(PRIMARY_BUTTON_PIN);
    
    	if (value != sentValue) {
    		// Value has changed from last transmission, send the updated value
    		digitalWrite(LED_PIN, HIGH);
        delay (5);
    		send(msg.set(value==HIGH));
        digitalWrite(LED_PIN, LOW);
    		sentValue = value;
    	}
    
    	value = digitalRead(SECONDARY_BUTTON_PIN);
    
    	if (value != sentValue2) {
    		// Value has changed from last transmission, send the updated value
    		digitalWrite(LED_PIN, HIGH);
        delay (5);
    		send(msg2.set(value==HIGH));
         digitalWrite(LED_PIN, LOW);
    		sentValue2 = value;
    	}
    
     
    
    
    	// Sleep until something happens with the sensor
    	sleep(PRIMARY_BUTTON_PIN-2, CHANGE,SECONDARY_BUTTON_PIN-2, CHANGE, 7000);
    

    how make it...???

    also interrupt must working correctly.

    please help me with my code.

    tnx
    Peter

    1 Reply Last reply
    0
    • gohanG Offline
      gohanG Offline
      gohan
      Mod
      wrote on last edited by
      #2

      Are you having problems with the code?
      Is there a reason why you don't use

      #define MY_NODE_ID 88
      

      ?

      1 Reply Last reply
      0
      • U Offline
        U Offline
        ustredna
        wrote on last edited by
        #3

        In my specific application i use one GW as receiver and one node with Static NODE ID as transmitter.

        1 Reply Last reply
        0
        • gohanG Offline
          gohanG Offline
          gohan
          Mod
          wrote on last edited by
          #4

          that didn't answer much my questions, as that is the common setup for Mysensors network. :)

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rvendrame
            Hero Member
            wrote on last edited by
            #5

            @ustredna , try changing this line:

            send(msg.set(value==HIGH));

            by

            send(msg.set(value));

            The same for msg2 line:

            send(msg2.set(value==HIGH));

            to

            send(msg2.set(value));

            And if you only need to update the GW on every 7 seconds (and not immediately), change the sleep:

            sleep( 7000 ) ;

            Hope it helps!

            Home Assistant / Vera Plus UI7
            ESP8266 GW + mySensors 2.3.2
            Alexa / Google Home

            1 Reply Last reply
            1

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            5

            Online

            11.9k

            Users

            11.2k

            Topics

            113.4k

            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