IKEA Bekant SmartDesk with Arduino – Upgrade

Henri Rantanen 0

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



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!

Range-finder mounted to the bottom of the desk
Range-finder mounted to the bottom of the desk

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

Relay shield with Arduino Nano soldered in
Relay shield with Arduino Nano soldered in

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.

Controls under the desk
Control-switches under the desk

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.


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.


For the sensor to work, software needs a way of asking it the distance so it can make decisions what to do.

Reading PING sensor with Arduino
Reading the PING sensor

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:

  1. Arduino: “Are we there yet?”
  2. Sensor: “Distance is X
  3. 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.


The new version of control software was needed for the new controller so it can handle the more analog height adjustment.

New version of UpButt'n
The new version of UpButt’n has height display

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.

Keyboard shortcut to raise and lower the desk.

The keyboard in the picture is Corsair STRAFE RGB, a mechanical gaming keyboard.


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!

  1. Don’t place a garbage can accidentally under the sensor
  2. Learn to not hard-code all variables
  3. Do it properly the first time
Difficulty ★★★☆☆
Time ★★★☆☆
Price ★★★★☆


Software and Source-files »

Creative Commons -lisenssi
UpButt’n & SmartDesk, written and designed by Henri Rantanen, are licensed under Creative Commons Attribution-ShareAlike 4.0 International.

What do you think of this post?
  • Awesome (100%)
  • Like (0%)
  • Dislike (0%)
  • Surprising (0%)
  • Interesting (0%)
  • Useful (0%)
  • Boring (0%)
  • Sucks (0%)

Leave a Reply

Your email address will not be published.