This tutorial details, step-by-step, how to use an ADXL362 to put an Arduino in a low-power state when the circuit is not moving, and then power it back up when motion is detected.
If you haven't already, make sure you are able to successfully complete the ADXL362 Arduino How-To tutorial, which will guide you through hookup, ADXL362 Arduino library installation, and uploading/executing the "ADXL362_SimpleRead" example. Any unresolved issues you have while working through the first tutorial will cause you trouble in this one.
I'm sure there are many good examples/libraries for putting your Arduino to sleep, but I have had good luck with Rocket Scream's Low Power Arduino library - download zip file here.
In my examples, I renamed the "Low-Power" top level library directory to "LowPower". (My environment doesn't like the hyphen... I'm not sure if it's an OS issue, or perhaps the hyphen worked fine on an older version of the Arduino software? Either way... please remove the hyphen to make the library work with my example code.)
Remember lessons learned while installing the ADXL362 Arduino library in previous tutorial. "LowPower" library folder should be placed in your <sketchbook>/libraries folder.
You libraries directory structure should look like the picture below. Go to ADXL362 Arduino How-To for a more detailed description of how to install Arduino libraries.
If you have it installed successfully, The Rocket Scream LowPower library will show up under Sketch -> Import Library -> LowPower (See image below):
This sleep example utilizes the INT1 pin of the ADXL362, and the Interrupt 0 (digital pin 2) on the Arduino. So, adding to the connections that were made on the previous tutorial, add a wire to connect INT1 pin on the ADXL362 to DP2 pin on the Arduino. See image below for an illustration of required connections:
More information about Arduino interrupts can be found at http://arduino.cc/en/Reference/AttachInterrupt
Once you have completed steps above, uploading the ADXL362_MotionActivatedSleep example to your Arduino should be simple and straightforward. The Motion activated sleep example requires the LowPower library to be properly installed.
Open the example by clicking File -> Examples -> ADXL362 -> ADXL362_MotionActivatedSleep, as shown in image below:
Make sure you have the correct board and serial port selected (see previous tutorial) and click the Upload button, as illustrated below:
Open the serial monitor, and watch as your circuit goes to sleep and wakes up, depending on if it's being shaken or moved.
In the example code, the circuit stays "on" for two seconds after it's been motionless, then shuts off. The on/off timing, as well as the motion threshold, can be changed by tweaking the activity/inactivity interrupt settings, which I've set with the setupDCActivityInterrupt and setupDCInactivityInterrupt functions.
To measure overall current, I disconnected the Pro Mini Arduino from my PC and FTDI Basic, and connected a multimeter in series with a 4.5V battery supply - I connected the battery supply to the RAW pin of my Pro Mini Arduino. My quick observation was that the overall circuit consumes a little over 4mA while awake, and roughly 270uA while asleep.
This tutorial does not include a thorough investigation of what portions of the circuit are consuming what portion of the overall power dissipation. But in this example, the ADXL362 consumes less than 3uA while on, and 300nA while the circuit is "sleeping." (The ADXL362 current consumption varies slightly with output data rate, input voltage, and mode) Therefore, most of the overall current, awake or asleep, is being consumed by the Pro Mini Arduino. I'll leave it to the reader to conduct their own experiments regarding power consumption.
Images below - Current consumption while Pro Mini Arduino + ADXL362 circuit is "awake," and "asleep."
So, as much as I love, love, love the Pro Mini, I wasn't completely satisfied with the sleep current of my overall circuit. And, I probably could have hacked my Pro Mini to make a few improvements (removing the 10K resistor across VCC comes to mind), I instead decided to purchase a Rocket Scream Mini Ultra Arduino-compatible board, especially since I'm using their handy Arduino library for sleep modes.
Using the Mini Ultra, I was able to get my sleep current down to roughly 2uA! That's more like it!
Image below - Current consumption while Mini Ultra + ADXL362 circuit is "asleep."
I have a few ideas... stay tuned!
Oh no! So sorry for the trouble... I can verify I'm having the same issue.
A month or so ago, I merged in a bunch of pull requests, many of which were excellent improvements. It looks like a bug got pulled in as well.
I'll work on making the fix in the library. In the mean time, you should be able to delete the "private:" line in the ADXL362.h file. This file is usually located in Documents/Arduino/libraries/ADXL362/
I've verified that the error goes away, but have not yet verified that all is fixed with hardware. Also, realize that the "MotionActivatedSleep" example utilizes a lowPower library which was written specifically for the Rocket Scream Mini Ultra. You will not get the same behavior on an Uno.
Hi,thanks for your tutorial and for your library.
I've a problem. I installed your Arduino ADXL362 library; everything works fine and the demo "ADXL362_SimpleRead" has no problem. Instead, loading the file "ADXL362_MotionActivatedSleep", Arduino IDE returns the following errors:
- C:\Arduino\libraries\ADXL362/ADXL362.h:67: error: 'void ADXL362::SPIwriteOneRegister(byte, byte)' is private
- ADXL362_sleep:90: error: within this context
I am using Arduino UNO, set to 3.3 V.
Thanks to help by Nitzan, problem solved.
For those of you like me, starting off the Arduino example ADXL362_MotionActivatedSleep.ino, one should comment out the
POWER_CTL_reg = POWER_CTL_reg | (0x04);
line for the activity time value to work.... otherwise it's autosleep state and wakes up on first jolt.
thanks for this tutorial! I have a problem though:
I tried setting the activity timer to a longer period to be immune to random jerks:
I thought this would set it at 250mg for 2 seconds (at ODR=100Hz). However it still wakes up on short jolts, while lying on my table. The total movement time is certainly less than .25 seconds and the final orientation in space is the same. Should it not ignore anything that takes less than 2s?
Matjaz of http://www.physics-engineering.eu/en