Arduino low power
From emboxit
the best I found is the JeeLib library. You can just download it and install it by placing the folder in your Arduino/libraries/ folder.
You basically just have to include the JeeLib library with:
#include <JeeLib.h>
Then initialize the watchdog with:
ISR(WDT_vect) { Sleepy::watchdogEvent(); }
Finally, you can put the Arduino to sleep for a given period of time with:
Sleepy::loseSomeTime(5000);
<cpp>
- include <JeeLib.h> // Low power functions library
int led_pin = 13; ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Setup the watchdog void setup() {
pinMode(led_pin, OUTPUT);
} void loop() {
// Turn the LED on and sleep for 5 seconds digitalWrite(led_pin, HIGH); Sleepy::loseSomeTime(5000);
// Turn the LED off and sleep for 5 seconds digitalWrite(led_pin, LOW); Sleepy::loseSomeTime(5000);
}</cpp>
- LED off, without the JeeLib library: 6.7 mA
- LED on, without the JeeLib library: 8.8 mA
- LED off, with the JeeLib library: 43 uA (!)
- LED on, with the JeeLib library: 2.2mA
- Be prepared to new Ultra Low Power Arduino Wireless Sensor Node
- RFM69 library for RFM69W, RFM69HW, RFM69CW, RFM69HCW (semtech SX1231, SX1231H)
- Low power libraries for Arduino – Control sleep with single function calls
- Rocket Scream: Lightweight Low Power Arduino Library
- Best ways to power a Arduino according to your need
Wake up from interrupt <cpp> // Based on: http://arduino.cc/playground/Main/PinChangeIntExample // More info on uA's: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/
- include <Ports.h>
- include <RF12.h>
- include <avr/sleep.h>
- include <PinChangeInt.h>
- include <PinChangeIntConfig.h>
ISR(WDT_vect) { Sleepy::watchdogEvent(); }
- define PIR 5
- define BUTTON 4
void setup() {
Serial.begin(57600); Serial.println("Interrupt example:"); pinMode(PIR, INPUT); pinMode(BUTTON, INPUT); digitalWrite(BUTTON, HIGH); PRR = bit(PRTIM1); // only keep timer 0 going ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power PCintPort::attachInterrupt(PIR, wakeUp, CHANGE); PCintPort::attachInterrupt(BUTTON, wakeUp, CHANGE);
}
void wakeUp(){}
void loop() {
if (digitalRead(PIR) == HIGH) { Serial.println("Motion detected"); } else if (digitalRead(BUTTON) == LOW) { Serial.println("Button pressed"); } Sleepy::powerDown();
} </cpp>