| 50 | == Case # 3== |
| 51 | |
| 52 | '''Powering things from battery''' |
| 53 | |
| 54 | '''Task:''' ''Tips to achieve long battery life. This consolidates information from a great post from @a-lurker and others around the web trying to the longest battery life possible.'' |
| 55 | http://forum.micasaverde.com/index.php/topic,20078.0.html |
| 56 | |
| 57 | '''Solution:''' |
| 58 | 1. Disable or remove the on-board regulator. This draws excessive current; |
| 59 | 2. Remove the power LED. On some boards this is done by disabling the Regulator; |
| 60 | 3. Power directly off the battery or use a Switching Regulator such as: |
| 61 | https://www.sparkfun.com/products/10967 |
| 62 | |
| 63 | http://www.pololu.com/product/798 |
| 64 | 4. SLEEP whenever possible. |
| 65 | - Wake up using the WDT |
| 66 | |
| 67 | {{{ |
| 68 | sleep.sleepDelay(SLEEP_TIME * 1000); //sleep for: sleepTime |
| 69 | }}} |
| 70 | - Or use an interrupt if using a button or sensor. |
| 71 | See http://code.mios.com/trac/mios_arduino-sensor/browser/VeraArduino/Arduino/libraries/Vera/examples/RelayWithButtonActuator/RelayWithButtonActuator.ino |
| 72 | 5. Disable the BOD (Brow out detection). Sleep library does this or can be done in software: |
| 73 | <Enter Sleep Mode> |
| 74 | |
| 75 | {{{ |
| 76 | // turn off brown-out enable in software |
| 77 | MCUCR = bit (BODS) | bit (BODSE); |
| 78 | MCUCR = bit (BODS); |
| 79 | }}} |
| 80 | <Sleep the CPU within 3 clock cycles of above code> |
| 81 | 6. Turn of A/D Convertors : (Again Hek already does this in Sleep Library) |
| 82 | |
| 83 | {{{ |
| 84 | // disable ADC |
| 85 | ADCSRA = 0; |
| 86 | }}} |
| 87 | 7. Set unused input or output pins to LOW; |
| 88 | 8. Lower your clock frequency. This has to be done by burning your fuses. Be careful and check the clock frequency of the radio you're using; |
| 89 | 9. To send the Battery level to the Gateway: |
| 90 | To measure the battery internally (when connected directly to a battery): |
| 91 | {{{ |
| 92 | // Read the Battery |
| 93 | long readVcc() { |
| 94 | long result; |
| 95 | // Read 1.1V reference against AVcc |
| 96 | ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); |
| 97 | delay(2); // Wait for Vref to settle |
| 98 | ADCSRA |= _BV(ADSC); // Convert |
| 99 | while (bit_is_set(ADCSRA,ADSC)); |
| 100 | result = ADCL; |
| 101 | result |= ADCH<<8; |
| 102 | result = 1126400L / result; // Back-calculate AVcc in mV |
| 103 | return result; |
| 104 | } |
| 105 | }}} |
| 106 | {{{ |
| 107 | // Send the Battery Percentage to the Gateway |
| 108 | #define VBatMax 3.1 // The voltage of New Batteries |
| 109 | #define VBatDropout 1.8 // The battery dropout voltage |
| 110 | gw.sendBatteryLevel((readVcc()-(Dropout*1000)) /(((VBatMax-Dropout) *10))); |
| 111 | }}} |
| 112 | |
| 113 | To measure the battery voltage when using a Switching Regulator: |
| 114 | See a-lurker's post: http://forum.micasaverde.com/index.php/topic,20078.0.html |
| 115 | |
| 116 | '''Comments:''' |
| 117 | |
| 118 | For reference here are some good sights: |
| 119 | |
| 120 | http://maniacbug.wordpress.com/2011/10/19/sensor-node/ |
| 121 | |
| 122 | http://www.gammon.com.au/forum/?id=11497 |
| 123 | |
| 124 | http://hwstartup.wordpress.com/2013/03/11/how-to-run-an-arduino-on-a-9v-battery-for-weeks-or-months/ |
| 125 | |
| 126 | http://hwstartup.wordpress.com/2013/04/15/how-to-run-an-arduino-clone-on-aa-batteries-for-over-a-year-part-2/ |
| 127 | |
| 128 | http://www.thalin.se/2013/04/arduino-pro-mini-low-power-modification.html |
| 129 | |
| 130 | http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/ |
| 131 | |
| 132 | ---- |
| 133 | |