How I Hacked My Standing Desk With a Raspberry Pi
I’m a chronic productivity hacker. I love optimizing everything, but especially my work setup.
I think that it makes a lot of sense to be very deliberate about making my working experience the best it can be, given that I spend about 47% of my waking hours at work.
Like many office workers today, I have a motorized sit-stand desk at work. (I built my own mechanical sit-stand desk at home, but that’s another story)
When I first started using it, I was very excited, but I quickly found myself sitting all day, in spite of the fancy desk.
I found it strangely hard to build a habit of standing. I even tried setting reminders on my phone to stand up, but even then, it was too easy to ignore, and too easy to say “I’m tired right now. I’ll stand in a few minutes.”
So I decided to see if there were some way to automate my desk so that it would rise up on a schedule, whether I felt like standing or not.
I frankly didn’t expect this engineering project to work out, but I figured I’d try taking apart my desk’s control box and just see what was inside it.
I took off a few screws and … voila! A row of pins neatly exposed right in front. I imagine that they were added for testing, perhaps? I don’t expect that Poppin had a productivity-hacker like me in mind when designing these boxes, but these pins were exactly what I needed.
The pins in my control box, when connected correctly, simulate the pressing of the buttons on the front of the box.
All I really needed to do was to press one button: the button that would raise the desk up to standing height. I’m not concerned about too much standing (I get tired and sit down naturally after a while), so I didn’t need a complex controller that would toggle back and forth between sitting and standing and various intervals.
All I needed was to send the desk up every hour or so. I’ve found that switching between sitting and standing every 30–60 minutes is a great way to stay active, improve my posture, and decrease back/neck/knee pain.
My desk has a few programmable buttons that send the desk directly to a preset height when pressed, and I had already set Button 1 as my seated height and Button 2 as my standing height.
When I connected the 3rd pin from the left with the 2nd pin from the right, that sent the Button 2 signal to the (I presume) microcontroller that controls the desk. I soldered a wire to each of those pins, so now I had two wires which, when connected, would raise my desk.
The next question was how to connect these wires in an automated way. The obvious answer was a relay.
A relay is a simple chip that allows you to connect two wires when you send a small current over the control pins. There are lots of kinds of relays, but I chose a very simple solid-state relay with 4 pins, the Toshiba TLP222A. It’s tiny (about 6mm across).
Now, I needed some way to send that small current over the control pins at a regular interval.
I actually thought about designing a simple circuit (no processor involved at all).
There is a very common little chip called a 555 timer. It does exactly what I wanted (connect a circuit at a regular interval), but it’s designed for very-short intervals (like less than a second) and becomes less reliable when you try to turn it up to 1000. I would probably have needed a series of 555 timers in a more complicated circuit. Definitely doable, but not so simple, and it would have been complicated to change the interval afterward.
On the other hand, I’d been waiting for an excuse to play around with a Raspberry Pi for years, and this seemed like the perfect opportunity, so I decided to go with a Raspberry Pi.
I ordered a Raspberry Pi Zero, the simplest, most basic version. It doesn’t have all the bells and whistles, but it does everything I needed for this simple project, and it’s just $5(!). I ordered the Pi Zero, a case, and a Micro SD card with the Raspbian OS pre-installed from Ada Fruit. About $20 altogether.
I didn’t need the full graphical interface for this simple project, so I didn’t bother connecting a monitor and a USB-hub with keyboard and mouse. I decided that I would just use my Macbook to program the Pi Zero. The Pi Zero doesn’t have an Ethernet port, so made a couple tweaks to the installation that allowed me to SSH from my Macbook into my Pi over USB (using a USB “data cable”). Cool, huh?
Now I had a terminal running on my Pi!
The Raspbian OS that came on the SD card had the Raspberry Pi Python library already installed, so it was all ready for me to start programming the Pi.
All I had to do was open a Python terminal, type
import gpiozero and I was ready to control my pins (which triggered the relay and moved the desk) with a Python script.
I wrote an extremely simple Python script that fires one of the GPIO pins on my Pi at a random interval between 45 and 60 minutes. I chose a random interval because I didn’t want to be planning and expecting the desk to rise, calculating the amount of time between intervals. I wanted it to be more organic, unconscious.
If you’d like your desk to move on a different cadence, it’s very easy to tweak the script below.
from gpiozero import LED # The LED library allows easy pin control
from time import sleep
import randomrelay = LED(17) # I connected the relay to pin 17 and groundwhile True:
sleep(random.randint(45, 60) * 60)
I saved my script into /home/pi/Documents/moveDesk.py and then added this line to /etc/rc.local:
Adding the command to /etc/rc.local means that it will always run when the Raspberry Pi boots up (and keep running forever). In case the Pi lost power for any reason, I didn’t want to have to SSH back into it to restart the script.
Then I soldered my two wires from the desk’s control board to the two “output” pins of the relay, and I soldered the 2 control pins of the relay directly onto Pi.
Messy, and not very elegant, but I figured that this would going to be hidden under my desk for the rest of its life, so I didn’t bother too much about making it pretty.
Then I just plugged the Pi into a USB power brick, and… it worked! 🙌 That’s all there is to it.
I tucked the Pi out of sight under some other cables on the underside of my desk, taped the wires in place to make sure that I didn’t catch my foot on them, and I was off to the races.
It’s been running flawlessly for a few months now, and I haven’t had any need at all to tweak it. The random 45–60 interval turned out to be great for me, and I’m now spending a lot more of my day standing, which has a great impact on my back pain.
Before this setup, I had to use notifications (distraction — not good for focus) as a reminder, and I also had to consciously choose to stand (ego depletion) in order to keep myself on a healthy cadence of sitting and standing. Now, the healthy cadence happens automatically. There are times when the desk starts moving up, and I unconsciously stand as it rises without even realizing what’s happening.
Note: I did all of this pre-pandemic. Our company has since outgrown that office and moved to a new space managed by Wework… which doesn’t have any standing desks 😢 I am now exploring new ways to hack my new work setup.
Edit to answer some questions from Hacker News:
This desk has a resistance-detection feature. If the desk starts to rise and encounters some object in the way, it’ll stop and reverse. Otherwise, the desk could end up rising by itself when I wasn’t around and possibly break something or injure someone
And yes, I’m aware that using a Linux server to move the desk up and down again is massive overkill. But 1) it was cheap, 2) it was easy, and 3) I learned how to use a Raspberry Pi, which I’m sure will come in handy in a future project.