I have designed a "WIFI postbox notifier" (open source, when it finished ) with a transmitter based on a Digispark.
I use a 555 timer chip and a tilt switch, to give the Digispark and the transmitter module power in 12 sec, so it have time to send the data. Its designed to only use power when someone lifting the lid on the mailbox. See attachment.
All things work now, but I have a problem. It drains the 9 Volt battery in a 2 to 3 days.
Depends on the exact circuit how much power it takes - for IC's the datasheet will show the
quiescent current drain.
Typically an analog circuit will take a few mA, enough to drain a battery. CMOS logic when inactive
takes a few uA, so is much more useful for micropower applications. A microcontroller with a sleep-mode
is usually the way to go - no need to power it down, in sleep mode the oscillator is switched off and the
current drain a few uA. Aim for 10uA or less total current for such an application if you want a battery
life measured in years.
I have gone after the "sleep-mode" idea. (But "hauerdie's" idea with the latch circuit is probably the best, but I have not any mosfets on the shelf right now)
My new setup :
And sketch : (And yes, It's not great , but it works )
#include <avr/sleep.h>//this AVR library contains the methods that controls the sleep modes
#include <VirtualWire.h>
char *controller;
int task1Status=0;
int task2Status=0;
void setup()
{
pinMode(13,OUTPUT); // set pin 13 as an output so we can use LED to monitor
digitalWrite(13,LOW); // turn pin 13 LED off
pinMode(2, INPUT); //Set interrupt pin 2 as input
digitalWrite(2,HIGH); //activate the internal pull-up resistor to pull it high when jumper is not connected to GND
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(2000);// speed of data transfer Kbps
}
void loop(){
doOneThingOfTask1();
doOneThingOfTask2();
}
void doOneThingOfTask1()
{
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
controller="1" ;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
}
void doOneThingOfTask2()
{
if (task1Status==10)
task1Status=0;
switch (task2Status)
{
case 0:
delay(2000); // Stay awake for 5 seconds, then sleep. These are the 5 seconds when we see ~40mA on the multimeter.
sleepSetup(); //now we see ~27 mA until pin 2 is connected to GND
}
}
void sleepSetup()
{
sleep_enable();
attachInterrupt(0, pinInterrupt, LOW);//Set pin 2 as interrupt and attach Interrupt Service Routine (ISR)
set_sleep_mode(SLEEP_MODE_PWR_DOWN);//define power down sleep mode
digitalWrite(13,LOW); // turn LED off to indicate sleep
sleep_cpu();//Set sleep enable (SE) bit, this puts the ATmega to sleep
digitalWrite(13,HIGH); // turn LED on to indicate wake up
}
void pinInterrupt()//ISR
{
sleep_disable();//this is important. It is possible that the interrupt is called between executing "attachInterrupt(...)" and sleep_CPU() in the main loop
//if that happens without the sleep_disable() in the ISR, the ISR would be called, the interrupt detached and the device put to sleep.
//since the interrupt would be disabled at that point, there would be no way to wake the device up anymore.
//by putting sleep_disable() in the ISR, sleep_cpu() would not be effective during that loop, i.e. the main loop would run one more time
//and then properly attach the interrupt before hitting the sleep_cpu() a second time. At that point the device would go to sleep, but
//the interrupt would now be activated, i.e. wake-up can be induced.
detachInterrupt(0);//disable the interrupt. This effectively debounces the interrupt mechanism to prevent multiple interrupt calls.
}
I do not have as fine an ammeter to measure what it power use now, so time will tell.
You don't need a Nano and its USB/Serial chip, which draws current all the time. Use a Promini instead, or one of my 328 mini cards which has even fewer components, just the processor, crystal, and some Rs & Cs. Use a small switching regulator, maybe a step up to make 9V from 2 AAs, run the board at 3V/8 MHz: http://www.crossroadsfencing.com/BobuinoRev17/
kryder:
I have a Promini (16MHz). Do the 8MHz use less power ?
Maybe. But they take twice as long to get the job done. If speed of performing the task is limited by something else, then slower execution may save a little power, but if you can get the job done twice as fast in computing terms and then switch off, that may save more power.