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. Binarysensor with sleep

Binarysensor with sleep

Scheduled Pinned Locked Moved Development
9 Posts 5 Posters 4.7k 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.
  • stofakillerS Offline
    stofakillerS Offline
    stofakiller
    wrote on last edited by stofakiller
    #1

    Hi,
    I want to make a snail mail sensor (battery operated), and tried to add sleep_time to the binary sketch, i want it to wake up every hour and send if has been tripped... But nothing, hope anyone can help...

    Here's the sketch: (5 seconds sleep ;-) )

    #include <Sleep_n0m1.h>
    #include <Sensor.h>
    #include <SPI.h>
    #include <EEPROM.h>
    #include <RF24.h>
    #include <Bounce2.h>

    #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch

    Sensor gw;
    Sleep sleep;
    unsigned long SLEEP_TIME = 5000; // sleep time between reads (seconds * 1000 milliseconds)
    Bounce debouncer = Bounce();
    int oldValue=-1;

    void setup()
    {
    gw.begin();

    // Setup the button
    pinMode(BUTTON_PIN,INPUT);
    // Activate internal pull-up
    digitalWrite(BUTTON_PIN,HIGH);

    // After setting up the button, setup debouncer
    debouncer.attach(BUTTON_PIN);
    debouncer.interval(5);

    // 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 below.
    gw.sendSensorPresentation(BUTTON_PIN, S_DOOR);
    }

    // Check if digital input has changed and send in new value
    void loop()
    {
    debouncer.update();
    // Get the update value
    int value = debouncer.read();

    if (value != oldValue) {
    // Send in the new value
    gw.sendVariable(BUTTON_PIN, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
    oldValue = value;
    }
    // Power down the radio. Note that the radio will get powered back up
    // on the next write() call.
    gw.powerDown();
    sleep.pwrDownMode(); //set sleep mode
    sleep.sleepDelay(SLEEP_TIME); // sleep for SLEEP_TIME
    }

    Regards,
    Jan

    BulldogLowellB 1 Reply Last reply
    0
    • stofakillerS stofakiller

      Hi,
      I want to make a snail mail sensor (battery operated), and tried to add sleep_time to the binary sketch, i want it to wake up every hour and send if has been tripped... But nothing, hope anyone can help...

      Here's the sketch: (5 seconds sleep ;-) )

      #include <Sleep_n0m1.h>
      #include <Sensor.h>
      #include <SPI.h>
      #include <EEPROM.h>
      #include <RF24.h>
      #include <Bounce2.h>

      #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch

      Sensor gw;
      Sleep sleep;
      unsigned long SLEEP_TIME = 5000; // sleep time between reads (seconds * 1000 milliseconds)
      Bounce debouncer = Bounce();
      int oldValue=-1;

      void setup()
      {
      gw.begin();

      // Setup the button
      pinMode(BUTTON_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);

      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);

      // 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 below.
      gw.sendSensorPresentation(BUTTON_PIN, S_DOOR);
      }

      // Check if digital input has changed and send in new value
      void loop()
      {
      debouncer.update();
      // Get the update value
      int value = debouncer.read();

      if (value != oldValue) {
      // Send in the new value
      gw.sendVariable(BUTTON_PIN, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
      oldValue = value;
      }
      // Power down the radio. Note that the radio will get powered back up
      // on the next write() call.
      gw.powerDown();
      sleep.pwrDownMode(); //set sleep mode
      sleep.sleepDelay(SLEEP_TIME); // sleep for SLEEP_TIME
      }

      Regards,
      Jan

      BulldogLowellB Offline
      BulldogLowellB Offline
      BulldogLowell
      Contest Winner
      wrote on last edited by BulldogLowell
      #2

      @stofakiller

      I messed about with this for a while and went with light instead. It is posted here on the forum, but I don't post the sketch, basic light sensor. I wanted to try a contact sensor but didn't have one.

      the forum convinced me I was worried too much about the battery and that all would be good if it was left with the sleep as is. However, if you want to you could try to hold the sketch in a while loop for an hour, exit and test for the door opening.

      Toggle the event with an interrupt instead on pin3.

      I worked your the logic and debugged, but you have to put your radio stuff in there.

      wire your contact sensor as follows:

      Side A to 5V
      Side B to Pin3 and through a 10kOhm resistor to ground
      Debounce logic in the sketch for you

      try it and let me know if it works. I have my contact sensor now and the mailman is finally used to the light sensor, so he needs to be excited again. :)

      added: if you really want to get crazy and save power, you can put your Arduino to sleep and wake it up on an interrupt:-o

      AltMailBoxLogic.ino

      1 Reply Last reply
      0
      • mountainmanM Offline
        mountainmanM Offline
        mountainman
        wrote on last edited by
        #3

        I am trying to build a mailbox sensor myself using a reed switch. I have 3.3v mini pro with the regulator cut per the battery power directions. (http://www.mysensors.org/build/battery).

        Modified the binary sketch to wake on interrupt on pin 3. Currently I have all the de-bounce logic commented out to make the interrupt work. What issues might this cause and should I be looking at adding debounce back in?

        Measuring current when sleeping with magnetic target far (i.e. open circuit) I am reading 7.6 uA and ~100 uA when it is target near. Ideally i would like these reversed as the sensor will spend the majority of it time with target near. Is there anything I can do to reduce the target near current, such wiring a external resistor?

        One option would be to find some normally closed reed switches but I wanted to explore other options first.

        BTW, Peak current when radio is transmitting is 6.13 mA.

        Thanks,
        Brendan

        YveauxY 1 Reply Last reply
        0
        • mountainmanM mountainman

          I am trying to build a mailbox sensor myself using a reed switch. I have 3.3v mini pro with the regulator cut per the battery power directions. (http://www.mysensors.org/build/battery).

          Modified the binary sketch to wake on interrupt on pin 3. Currently I have all the de-bounce logic commented out to make the interrupt work. What issues might this cause and should I be looking at adding debounce back in?

          Measuring current when sleeping with magnetic target far (i.e. open circuit) I am reading 7.6 uA and ~100 uA when it is target near. Ideally i would like these reversed as the sensor will spend the majority of it time with target near. Is there anything I can do to reduce the target near current, such wiring a external resistor?

          One option would be to find some normally closed reed switches but I wanted to explore other options first.

          BTW, Peak current when radio is transmitting is 6.13 mA.

          Thanks,
          Brendan

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #4

          @mountainman said:

          BTW, Peak current when radio is transmitting is 6.13 mA.

          Just wondering, how did you measure this, and especially the sleeping current?
          I use a uCurrent (see http://forum.mysensors.org/topic/206/sleep-wake-txrx-cycle/15) and get approx. 28mA peak when transmitting.

          http://yveaux.blogspot.nl

          1 Reply Last reply
          0
          • mountainmanM Offline
            mountainmanM Offline
            mountainman
            wrote on last edited by
            #5

            I'm just running the current though a fluke 189 so likely not very accurate vs the uCurrent. Should give rough order of magnitude at least.

            Just reran transmit test using the fast min max and peak is now 25mA!

            BTW, Did you build the uCurrent yourself?

            YveauxY 1 Reply Last reply
            0
            • mountainmanM mountainman

              I'm just running the current though a fluke 189 so likely not very accurate vs the uCurrent. Should give rough order of magnitude at least.

              Just reran transmit test using the fast min max and peak is now 25mA!

              BTW, Did you build the uCurrent yourself?

              YveauxY Offline
              YveauxY Offline
              Yveaux
              Mod
              wrote on last edited by
              #6

              @mountainman yes. But compared its performance to a genuine ucurrent. Result was identical.
              I even have some spare, if you're interested...

              http://yveaux.blogspot.nl

              DammeD mountainmanM 2 Replies Last reply
              0
              • YveauxY Yveaux

                @mountainman yes. But compared its performance to a genuine ucurrent. Result was identical.
                I even have some spare, if you're interested...

                DammeD Offline
                DammeD Offline
                Damme
                Code Contributor
                wrote on last edited by
                #7

                @Yveaux jumpupanddown me me me! :)

                YveauxY 1 Reply Last reply
                0
                • DammeD Damme

                  @Yveaux jumpupanddown me me me! :)

                  YveauxY Offline
                  YveauxY Offline
                  Yveaux
                  Mod
                  wrote on last edited by
                  #8

                  @Damme he he ;)
                  But you can't get it for free.... I build some to pay for mine, but I'm too lazy to sell them...

                  http://yveaux.blogspot.nl

                  1 Reply Last reply
                  0
                  • YveauxY Yveaux

                    @mountainman yes. But compared its performance to a genuine ucurrent. Result was identical.
                    I even have some spare, if you're interested...

                    mountainmanM Offline
                    mountainmanM Offline
                    mountainman
                    wrote on last edited by
                    #9

                    Thanks @Yveaux. Its on the list but it be a while before funds recover to get another toy.

                    Would using a pull-down resistor before more efficient than using the internal pull-up?

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


                    11

                    Online

                    11.7k

                    Users

                    11.2k

                    Topics

                    113.1k

                    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