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.
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.