I've had a standing desk at work for a long time, but I've always felt that I wasn't using it enough, that I still spent most of my timing sitting.
This week I finally decided to do something about it.
I bought a small sonar sensor (LV-MaxSonar-EZ1), hooked it up to an Arduino and added a little Python script to sample the sensor once a minute.
The sonar is mounted to my table and measures the distance to the floor, and with ~3 cm accuracy it's very easy to distinguish whether I'm sitting or standing.
Since the Sonar happily runs of 5V, I just connected its power input pins directly to the VCC and GND pins of my Arduino. Conveniently it also provides the measured distance as analog voltage on a pin, I just connected that to A0 on the Arduino.
The Arduino code to regularly sample the sonar is then very simple, even with basic smoothing included:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
The Arduino includes a USB serial interface, so I can just connect it directly to my computer and it's straightforward to read its output with Python:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
At this point I can do whatever I want with the data - create daily or weekly graphs, send automated email reminders if I haven't been standing in the last 2 hours, etc.
To ignore periods where I'm not actually at my computer, I use xprintidle
, which prints the time in milliseconds since the last user activity, i.e. mouse or keyboard input.
Tags: misc