APM 8Mhz, 2 AA batteries and within 2 tot 3 days dead



  • I've got this sensor with two magnetic sensors.
    1 for the mailbox and 1 for the front door.

    Both working on a interrupt base with sleeping mode on a Arduino Pro Mini 3.3v 8 Mhz.
    Powered by 2 AA batteries on the Vraw pin and GND.

    The unit works for aprox. 2 to 3 days and then the batteries are empty.
    The LED is cut and I believe the code is good. What else can I do to last this device longer then 2 to 3 days? I've read the whole battery powered modules but I have no idea's so far.

    Maybe there is something wrong in my code?

    #include <SPI.h>
    #include <MySensor.h>
    #include <avr/sleep.h>
    #include <Bounce2.h>
    
    #define BUTTON_PIN_1 2 // Voordeur
    #define BUTTON_PIN_2 3 // Brievenbus
    #define INTERRUPT 0
    #define INTERRUPT 1
    
    MySensor gw;
    MyMessage msgVD(BUTTON_PIN_1,V_TRIPPED);
    MyMessage msgBB(BUTTON_PIN_2,V_TRIPPED);
    
    Bounce debouncerVD = Bounce();
    Bounce debouncerBB = Bounce(); 
    int oldValueVD=-1;
    int oldValueBB=-1;
    
    void setup()
    {
      gw.begin(NULL,6,false);
      gw.sendSketchInfo("Voordeur_Brievenbus", "1.1");
      
      pinMode(BUTTON_PIN_1,INPUT_PULLUP);
      pinMode(BUTTON_PIN_2,INPUT_PULLUP);
      gw.present(BUTTON_PIN_1,S_DOOR);
      gw.present(BUTTON_PIN_2,S_DOOR);
      debouncerVD.attach(BUTTON_PIN_1);
      debouncerVD.interval(5);
      debouncerBB.attach(BUTTON_PIN_2);
      debouncerBB.interval(5);
      Serial.println("Setup gerund");
    }
    
    void loop()
    {
      debouncerVD.update();
      // Get the update value
      int valueVD = debouncerVD.read();
     
      if (valueVD != oldValueVD) {
         // Send in the new value
         gw.send(msgVD.set(valueVD==HIGH ? 1 : 0));
         oldValueVD = valueVD;
         enterSleep();
      }
    
      debouncerBB.update();
      // Get the update value
      int valueBB = debouncerBB.read();
     
      if (valueBB != oldValueBB) {
         // Send in the new value
         gw.send(msgBB.set(valueBB==HIGH ? 1 : 0));
         oldValueBB = valueBB;
         enterSleep();
      }
    }
    
    void Voordeur()
    {
        Serial.println("VD Loop gerund");
    }
    
    void Brievenbus()
    {
        Serial.println("BB Loop gerund");
    }
    
    void enterSleep(void)
    {
      attachInterrupt (0,Voordeur,CHANGE);
      attachInterrupt (1,Brievenbus,CHANGE);
      delay(100);
      Serial.println("Entering sleepmode...");
      delay(100);
      set_sleep_mode(SLEEP_MODE_PWR_DOWN);
      sleep_enable();
      sleep_mode();
      /* The program will continue from here. */
      /* First thing to do is disable sleep. */
      sleep_disable(); 
      Serial.println("Recovering from sleepmode...");
    }```

  • Hardware Contributor

    Hi!
    Are you running a 5 or 3.3v arduino? Best for battery based sensors are 3.3v and run the 2xAA bat to VCC and remove voltage regulator to save power. Radio can be powered directly from the battery (Down to 0.9v i think). Then you can use a booster to maintain 3.3v to arduino and/or sensors.

    Removing the volt. regulator did a big difference for me.



  • I'm running a 3.3v APM. I'll check if I've cutted the voltage regulator or not... I'm not sure anymore.


  • Hardware Contributor

    From learning, ill suggest remove (desolder). Atleast I think thats much easier... i cut two volt. regulators and destroyed stuff nearby...

    Also if you have removed the volt. regulator, you would not be able to run it from RAW so you are using it.



  • I've read that somewhere. I will check soon and post my findings.


  • Mod

    The internal pullups will consume 3.3/20000=0.165mA each. That's not a lot but I would switch to external pullups of 1Mohm or more.

    Is there a reason why you're not using the MySensors sleep?

    Will the avr sleep turn off the radio?


  • Admin

    I don't think Bounce2 works when you're sleeping.

    Why not use a simple interrupt to trigger wake up? Like in this example:
    https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/examples/BinarySwitchSleepSensor/BinarySwitchSleepSensor.ino


Log in to reply
 

Suggested Topics

31
Online

11.2k
Users

11.1k
Topics

112.5k
Posts