DIY Actigraphy with Arduino

In an effort to understand how well or badly I’ve been sleeping, some ghetto actigraphy had to be done. So for the past month or so, I’ve been sleeping with an accelerometer under my pillow.

I'm such a freak

Pictured is a MMA7341L based accelerometer, an Arduino Uno, a ScrewShield, a Datalogger Shield and a Protoshield. All either from Mr Wong of Robot R Us or AdaFruit.

Progress has been slow, due to my bad programming skills and the write-upload-sleep/test-analyse nature of the project. I actually enjoy the sleep/test portion very much! And every morning, I yank the SDCard to my PC for some Excel graphing.

Light and Temp are achieved with a photo resistor and temperature sensor. Samples are taken once per second and once per minute respectively. The SDCard logs maximums once per minute, including accelerometer data.

“Jump” is a little harder to explain. I read only the Z-Axis. The accelerometer registers 1G facing upwards and -1G facing downwards, so registers 640-ish or 380-ish on “AnalogRead”. So to register every time a significant movement (or jump) is detected, the program compares the maximums for the last 2 minutes and logs the differences as well as the raw accelerometer data.

The green LED also lights up and is PWM’ed to reflect jumps on a per second basis.

Fun! But I have to say, I’m standing on the shoulders of giants here. The original idea from an article by Loic Royer. The code for the internal millisecond clock by Daniel Andrade, Adafruit’s very comprehensive code (and circuit diagrams) for data logging temperature, light and time.

Next steps, have the device charge my iPhone4, and wake me up to music at my pre-programmed time, or up to 1 hour early if I start tossing around enough in bed. This is gonna be achieved through the iPodSerial library (original by David Findlay, forked by Blalor)

Woohoo! This is gonna be fun!

p.s. If you want the code, let me know. It’s work in progress, but I *do* document.

6 thoughts on “DIY Actigraphy with Arduino

  1. Hitesh Thakur

    Hi there pretty good project u got here, I was also inspired by lolos alarm clock and made something similar but i use accelerometer mma7455 i am kinda confused as to what to read from it.. can i have your code please!!!

  2. Anne

    Hi ! I’m a complete beginner to the accelerometers subject , is there anyway you could help me pleaaase??? I have the same accelerometer you’re using, the MMA7341L and I’m working on a different project in which the basic idea is : if there’s a considerable movement , activate a sound , if you’re not moving or baarely moving, do nothing…. But when I connect the accelerometer to the arduino I get weird numbers from the accelerometers, I don’t move it and there are still changes in the values printed, how do you get correct readings from this specific accelerometer? Again, I’m a complete beginner and can’t seem to find the answer in the datasheet … Hope you can help me , thanks!

    1. eD Post author

      Are you reading the accelerometer too often? My code only takes a reading every 20 milliseconds or so… and the raw readings look pretty stable. Not constant, but not *wildly random*. Hope this helps!

Leave a Reply