I upgraded the mechanical sensor of my DIY IKEA SmartDesk to ultrasonic rangefinder to set it’s height from the floor automatically which greatly improved its usability!
I removed the original magnetic limit-switch and replaced it with ultrasonic PING-sensor that could measure the actual height from the floor.
Read the part 1 of this article
System in action
Video
Hardware
Ultrasonic PING-sensor
In this project, I used a cheap ultrasonic PING-sensor that cost just a couple of euros. This device acts as a range-finder, measuring distances between objects from 3 cm to 300 cm.
When measuring, the sensor emits an inaudible 40kHz chirp and starts listening for the echo. Distance can be calculated from the time it takes for the sound to travel back!
For ease of installation, the sensor was mounted in a small project-box with mounting flanges. Just needed to drill a couple of holes and solder in some 4-pin cable salvaged from old printer cable.
Ping-sensor itself has 4 wires: ground, 5V supply voltage, Trigger, and Echo.
Controller
Controller-unit of the desk connects to the computer, receives instructions like “set the desk to 86 cm”, uses the ping-sensor to measure the height from the floor and then control the motors accordingly.
At this point, I had decided to make something more permanent so I relieved the Arduino Uno from its duties and modified the old Proto Shield that has the relays to take in something more appropriate, Arduino Nano.
Basically same functionality but in a smaller package.
You can read the distance to what’s in front of the sensor by sending it a standard length pulse via trigger-cable, then you get a response pulse from the Echo-wire. The distance between those pulses is proportional to the distance the sound has traveled in the air and you can use that delay to easily calculate the distance with Arduino. My setup is good for about 1 cm precision.
On the bottom edge of the desk is the away-switch which turns off displays and speakers by cutting the mains voltage going in (modified extension cord) and the original IKEA Bekant electrical desk controller which houses the control electronics and membrane-switches to control the mechanics. Arduino just virtually pushes these buttons via relays.
Software
This is a major upgrade to the system and requires quite a bit of new code to work. There had to be changed to the firmware and the controlling software.
I won’t go into much detail here, you can get the source-code as usual from my Dropbox.
Arduino
For the sensor to work, software needs a way of asking it the distance so it can make decisions what to do.
Flowcode comes with its own libraries to deal with most generic PING-sensors but they for some reason did not work for me so had to make them from scratch.
To determine the distance, the system makes 3 measurements with 60 milliseconds in between to allow the unwanted ultrasonic echoes to dissipate. These measurements are then averaged together and calculated to centimeters which the software can then use.
After receiving a command to move, the software goes in a loop:
- Arduino: “Are we there yet?”
- Sensor: “Distance is X
- Arduino: “I keep pushing button”
After the desired height has been reached, loop breaks and the system returns to an empty loop, listening to input from the computer.
UpButt’n
The new version of control software was needed for the new controller so it can handle the more analog height adjustment.
It has height display, slider on the right to make finer adjustments to the desk height and few useful presets.
Microwork is excellent for soldering and what not while Storage raises the table enough for the chair to fit underneath.
I removed the timers, they turned out to be more annoying than useful, easy access to the UP-button was way more effective than “being soft-forced to stand up”.
Keyboard shortcut
Two other exe-files were compiled, called up and down, with lazy hard-coded height values.
I set them behind function key as shortcuts so with a flick of a wrist I can set the table to proper standing or sitting height without looking up any programs and menus.
The keyboard in the picture is Corsair STRAFE RGB, a mechanical gaming keyboard.
Conclusion
I recently moved, so I had to take apart my workstation.
I was without this computer connected control-system for few months and I stood up once.
Just the system being there and being effortless to use makes a huge difference in one’s habits!
Verdict
- Don’t place a garbage can accidentally under the sensor
- Learn to not hard-code all variables
- Do it properly the first time
Difficulty ★★★☆☆ Time ★★★☆☆ Price ★★★★☆
Documentation
UpButt’n & SmartDesk, written and designed by Henri Rantanen, are licensed under Creative Commons Attribution-ShareAlike 4.0 International.