Binarysensor with sleep



  • 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


  • Contest Winner

    @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



  • 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


  • Mod

    @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.



  • 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?


  • Mod

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


  • Code Contributor

    @Yveaux jumpupanddown me me me! 🙂


  • Mod

    @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...



  • 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?


Log in to reply
 

Suggested Topics

  • 1
  • 1
  • 6
  • 10
  • 1
  • 3

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts