Wireless Mailbox Sensor - Battery Consumption

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
m@ttia
 
Posts: 12
Joined: Tue Aug 31, 2010 10:07 am

Wireless Mailbox Sensor - Battery Consumption

Post by m@ttia »

Hi,
I'm almost done with a small project I've been working on for some time: a wireless sensor to put inside my mailbox, who tells me when there is some new mail (since the mailbox is a bit far from my house's door...).

Basically, the project consists on a bare ATMEGA168 (who plays the role of a "cheap" Arduino), an XBee to transmit the data and a LM7805 regulator to convert the input to the desired 5V. Here below you can find a couple of photos of the result. (for the schematics see the updated version below...).

Image Image
(I'm using the adafruit Adapter for the xBee on the one attached to the PC with the FTDI friend, while here there is another one I had around, but it basically does the same job of shifting everything to 3.3V)

Everything works fine (which is quite strange, since it is my first project that includes creating schematics, etching the PCB and soldering everything! :D) but, as a newbie, I forgot to think about the power consumption... I originally planned (and still would like) to run it from a classic 9V Battery (with an average 400-500 mAh). Unfortunately, using a multimeter, I see that the board consumes ca. 130mA, and by removing everything but the microcontroller (i.e. only letting the ATMEGA and the voltage regulator) I get ca. 20 mA of consumption.

Beside the xBee sleep mode, etc. I'm still worried about the 20 mA: if my math is correct, the battery would last at most 500/20 = 25 hours.
Since in my house I've got some alarm PIR sensors who last 1-2 years using a 9V battery, I was wondering if there is an "easy" way to lower down the power consumption of the sensor and make it last much much more time...

My first Idea was to let the mailbox-door-switches be the ones who turn ON the whole board (e.g. by a transistor or something like that that connects the battery, and then the ATMEGA keeps the transistor ON by itself; after e.g. 30 seconds the message has been sent and the board can switch the transistor off, disconnecting the battery), but I'm sure there must be a more elegant solution that I simply can't think of...

Thanks for any advice!
(and please don't speak too complicated: I'm not an engineer :P)
Last edited by m@ttia on Sun Oct 28, 2012 7:49 am, edited 3 times in total.

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Wireless Mailbox Sensor - Battery Consumption

Post by adafruit_support_bill »

There is also a sleep-mode for the Atmega processor. One problem with the 9v power source is that you really need 5v and the 7805 is a rather inefficient linear regulator. If you slow down the clock, you can skip the regulator and run the whole thing (including the XBee) off a 3.3v lithium cell.

And the door-switch solution is not such a bad idea either. Sometimes simple is good. :D

thefatmoop
 
Posts: 352
Joined: Tue Aug 19, 2008 4:36 pm

Re: Wireless Mailbox Sensor - Battery Consumption

Post by thefatmoop »

use 3 AA batteries in series then ditch the arduino's voltage regulator and let that little guy sleep. Those xbee's should be easy to put to sleep and if not just cut the xbee power with a transistor.

You may also want to use the internal 8Mhz oscillator and that will let you run it down to lower voltages

User avatar
philba
 
Posts: 387
Joined: Mon Dec 19, 2011 6:59 pm

Re: Wireless Mailbox Sensor - Battery Consumption

Post by philba »

Definitely ditch the 9V battery. AAs have about 4X the mAHr capacity.

I agree about using sleep mode. Power-Save is pretty easy to use since you still get timer 2. To get the lowest possible power consumption, you should use the Power Down Sleep mode. This means you need to have an external interrupt to wake the Arduino or use the WDT. I would consider using an RTC to generate a 1 hz signal. The reason is that with WDT, you wouldn't be able to keep time. (Of course, if you don't need to keep time...) If your check takes 100 mS (probably a lot less than that), then you could get close to 10X battery life. The XBee sucks a fair amount of power when transmitting, as I'm sure you know, so keeping that to an absolute minimum is important. I'd probably broadcast no more frequently than once a minute.

Image

User avatar
m@ttia
 
Posts: 12
Joined: Tue Aug 31, 2010 10:07 am

Re: Wireless Mailbox Sensor - Battery Consumption

Post by m@ttia »

Thank you everybody very much for your suggestions! (and sorry for not answering for a week, but I've been on holyday 8))

I took a bit of every suggestion and came up with the right solution for me:
  • I'm running everything from 6x AAA Batteries (two sets of 3 in parallel, giving me 4.5V): I used them instead of the AA because 6 AAA do fit in the case, while 6 AA don't);
  • I tried to put the xBee to sleep with the sleep pin, but the breakout board has its own LEDs, 3.3V Regulator, etc. that consumes energy all the time, so I totally cut the power to the breakout board with a transistor (actually, by "cutting" the +5V side, the xBee seems to draw energy from the ATMEGA TX pin in some weird way that the breakout board LEDs turn on once in a while - killing the GND connection on the other hand works perfectly, so I just had to hack the PCB a little with some wires...);
  • As suggested by philba, The ATMEGA is set to sleep (Power Down sleep mode, which saves the most energy) and only woken up by the door-switches being activated (which set the Pin 2 resp. 3 - the two ATMEGA sleep interrupt pins - to LOW).
Image

The Code therefore works as follows:
  1. ATMEGA goes to sleep;
  2. If the mailbox door opens (either the "mail" one or the "opened with key" one), check which of the two pins went LOW;
  3. Turn on the xBee board, send this PIN number and kill the power to the xBee board;
  4. Wait 4 seconds (to avoid reading twice the same door opening, if lasting long) and go to sleep.
By doing this, the whole system consumes only 0.3 mA while nothing happens (i.e. 99.9% of the time), while (only!) when the door opens it stays up for about 8 seconds, consuming 120 mA (ATMEGA, xBee, LEDs, ...).
That's the perfect solution I was looking for, since it only consumes energy when something happens and almost nothing for the rest of the time! :mrgreen:

Again, thank you very very much!!! :wink:


P.S.
If someone is interested, here below is the full Arduino source code loaded into the ATMEGA that performs what said above:

Code: Select all

#include <avr/sleep.h>

// PINS
int WakeUpPin0        = 2;   // Mailbox opened with key
int WakeUpPin1        = 3;   // Mailbox opened (letter introduced)
int xBeeTransistorPin = 11;  // xBee Powered when HIGH
int GreenLedPin       = 5;   // Green LED when opened with key (or after Reset)
int RedLedPin         = 6;   // Red LED when a letter is inserted


// VARIABLES
int WhoWokeMeUp = -1;  // Store the button who went LOW (0 or 1), or -1 to unset


// Functions handled after wakeup
// Execute code here after wake-up before returning to the loop() function;
// timers and code using timers (serial.print, etc.) will not work here!
void WakeUpNow0()
{
  WhoWokeMeUp = 0;
}

void WakeUpNow1() 
{
  WhoWokeMeUp = 1;
}


// Function to put the Arduino to sleep
void SleepNow()         
{
  // Sleep code taken from http://arduino.cc/playground/Learning/ArduinoSleepCode

  /* Now is the time to set the sleep mode. In the Atmega8 datasheet
   * http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
   * there is a list of sleep modes which explains which clocks and 
   * wake up sources are available in which sleep mode.
   * In the avr/sleep.h file, the call names of these sleep modes are to be found:
   *
   * The 5 different modes are:
   *     SLEEP_MODE_IDLE         <-- the least power savings 
   *     SLEEP_MODE_ADC
   *     SLEEP_MODE_PWR_SAVE
   *     SLEEP_MODE_STANDBY
   *     SLEEP_MODE_PWR_DOWN     <-- the most power savings
   */  

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  sleep_enable();          // enables the sleep bit in the mcucr register
                           // so sleep is possible.

  /* Now it is time to enable an interrupt. We do it here so an 
   * accidentally pushed interrupt button doesn't interrupt 
   * our running program. if you want to be able to run 
   * interrupt code besides the sleep function, place it in 
   * setup() for example.
   * 
   * In the function call attachInterrupt(A, B, C) we have:
   * A   can be either 0 or 1 for interrupts on pin 2 resp. 3.   
   * 
   * B   Name of the function you want to execute at interrupt for A.
   *
   * C   Trigger mode of the interrupt pin. It can be:
   *             LOW        a low level triggers
   *             CHANGE     a change in level triggers
   *             RISING     a rising edge of a level triggers
   *             FALLING    a falling edge of a level triggers
   *
   * In all but SLEEP_MODE_IDLE sleep mode only LOW can be used.
   */

  attachInterrupt(0, WakeUpNow0, LOW);
  attachInterrupt(1, WakeUpNow1, LOW);

  sleep_mode();        // here the device is actually put to sleep!!
                       // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
  sleep_disable();     // first thing after waking from sleep: disable sleep...
  
  detachInterrupt(0);  // disables both interrupt {0,1} so the wakeUpNow{0,1} code
  detachInterrupt(1);  // will not be executed during normal running time.
}



void setup()
{
  Serial.begin(9600);

  pinMode(WakeUpPin0, INPUT);
  pinMode(WakeUpPin1, INPUT);
  
  pinMode(GreenLedPin, OUTPUT);
  pinMode(RedLedPin,   OUTPUT);
  digitalWrite(GreenLedPin, HIGH); // LED lights when LOW
  digitalWrite(RedLedPin,   HIGH); // LED lights when LOW  
  
  pinMode(xBeeTransistorPin, OUTPUT);
  digitalWrite(xBeeTransistorPin, LOW);

  pinMode(1, OUTPUT);   // TX (sends data to xBee)
  digitalWrite(1, LOW);
  
  pinMode(12, INPUT);   // (only for wrong made PCB, connected to Pin 2)
  pinMode(13, INPUT);   // (only for wrong made PCB, connected to Pin 3)
  
  WhoWokeMeUp = 0;      // After a Reset, we interpret it as opening with key...
}



void loop()
{
  if(digitalRead(WakeUpPin0) == LOW)
  {
    WhoWokeMeUp = 0; // Since opening with the key may trigger the other pin first...
  }
    
  if(WhoWokeMeUp == 0)
  {
    analogWrite(GreenLedPin, 20);
  }
  else
  {
    analogWrite(RedLedPin, 20);
  }
        
  digitalWrite(xBeeTransistorPin, HIGH);

  delay(4000);
  
  Serial.println(WhoWokeMeUp);  
  WhoWokeMeUp = -1;

  delay(3000);
  
  digitalWrite(GreenLedPin,       HIGH);
  digitalWrite(RedLedPin,         HIGH); 
  digitalWrite(xBeeTransistorPin, LOW);
  
  delay(4000); // Do not sense anything for the next 4 seconds

  SleepNow();
}
Last edited by m@ttia on Thu Jul 19, 2012 10:00 am, edited 4 times in total.

User avatar
philba
 
Posts: 387
Joined: Mon Dec 19, 2011 6:59 pm

Re: Wireless Mailbox Sensor - Battery Consumption

Post by philba »

Nice job.

How do you make sure you don't miss the signal If there is some sort of interference?

User avatar
m@ttia
 
Posts: 12
Joined: Tue Aug 31, 2010 10:07 am

Re: Wireless Mailbox Sensor - Battery Consumption

Post by m@ttia »

Uhm, you're right... :oops:

I think I'll also wire up the RX Pin and let the Receiver send a "OK, Received!" message back immediately: if the mailbox-board doesn't receive this confirmation (I'll obviously let the xBee powered up for a little more seconds to listen), then something went wrong and the message will be resent, etc. (if everything fails for, say, 4 times, I'll put the ATMega in the "sleep-mode-with-timer-enabled" (don't remember the exact name :D) and re-try after, say, 15 min.).

In fact, missing a message once wouldn't be so dramatic for my particular application, but thanks for pointing this out, it will just take a few lines of code and a wire to fix it! :wink:

User avatar
adrianrdzv
 
Posts: 2
Joined: Sat Aug 18, 2012 6:29 am

Re: Wireless Mailbox Sensor - Battery Consumption

Post by adrianrdzv »

Hi!

I'm started to play with arduinos and small electronic projects and I decided to make something similar for my first real project.

I have experience with arduinos, but never tried to use an atmega by itself and the implications on that. Do you know any good guide where I could start researching with this? I mean, I could just copy your design and buy everything and solder it myself, but I would like to make some modifications (The mail detection would be a photoresistor) and maybe other changes.

I studied electronic engineering but it was a while back and I'm not really working in the field since my studies. But I do remember lots of stuff, so you could say I'm not that of a beginner... You mentioned you are a newbie, just wondered where did you start to do your research to come up to such a nice solution for the project?

User avatar
m@ttia
 
Posts: 12
Joined: Tue Aug 31, 2010 10:07 am

Re: Wireless Mailbox Sensor - Battery Consumption

Post by m@ttia »

Hi,
(I hope this is not off-topic; in case any admin can split it to a new topic, thanks!).


Well, after using a bit the Arduino, I felt the need of using only the bare chip, since I didn't want to "sacrifice" a new arduino everytime I wanted to start a new project, so I wanted the Arduino to be my "Chip Programming board" and then extract the chip and plug it in my project. I bought a long time ago a set of 10 ATMEGA 328P chips on eBay for like 4$ each (preprogrammed with the Arduino bootloader), and everything always went fine for my needs. :)

Anyway, on the official Arduino webpage I found a couple of links on "Building an Arduino on a Breadboard" (which is basically what I (we) need to do), so I suggest you to read this (the one I first followed) or this.

Basically, after unplugging the chip from the arduino, you need to build:
  • a voltage supply (e.g. a linear regulator to use a 9V battery, a fuse to protect from overcurrent, capacitor to smooth out the signal, a 3.3V regulator if you need this voltage too, etc.). You can ev. skip this if you use e.g. 3 AA batteries.
  • an external crystal oscillator (16 Mhz) + 2 capacitors (in principle you could also use the slower internal clock, but is not much precise if you need very precise timings or faster frequencies) [everything together is only a few cents...]
  • If you want, a pulldown resistor + button for resetting the chip using the reset pin (this is obviously not mandatory, but somehow belongs to the "basic" configuration of a chip taken out from the Arduino)
I hope I didn't say something depply wrong, but following these guidelines (see above links) everything always worked fine for me! :wink:

cp3d2o
 
Posts: 33
Joined: Mon Aug 13, 2012 12:19 pm

Re: Wireless Mailbox Sensor - Battery Consumption

Post by cp3d2o »

It would be a good idea to use solar power. Also what you could do is place a sensor that will sense the movement and the reciever with a led indoors that stays on until you press a switch.
Very cheap and Very easy :)

User avatar
adrianrdzv
 
Posts: 2
Joined: Sat Aug 18, 2012 6:29 am

Re: Wireless Mailbox Sensor - Battery Consumption

Post by adrianrdzv »

Doesn't the XBee breakout board requires 5V to operate. How are you managing from the 4.5V to make it work? I know the XBee itself operates with 3.3V so I guess the regulation anyways takes place with 4.5V. Is this the case?

User avatar
m@ttia
 
Posts: 12
Joined: Tue Aug 31, 2010 10:07 am

Re: Wireless Mailbox Sensor - Battery Consumption

Post by m@ttia »

Well, quoting myself:
I'm using the adafruit Adapter for the xBee on the board attached to the PC with the FTDI friend, while in the Mailbox there is another one I had around, but it basically does the same job of shifting everything to 3.3V)
The xBee adapter I'm using with the AAA batteries is the simplest adapter possible, of which I draw the schematics here below:
Image

As you can see, the 5V are never used directly, but immediately converted to 3.3V, so even a voltage "around" 5V (e.g. 4.5V) is enough for the regulator to go down to 3.3V.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”