Hello everyone, I'm working on a small project where I can control the height of a height-adjustable desk using a microcontroller, MOSFET transistors, and an ultrasonic sensor. Essentially I want the user to input a height and the desk to automatically adjust to that height.

Technical details

This is the desk I am using. It only has up/down buttons and has no "memory" features.

I was trying to use this tutorial, but because I did not have an easy access to the motor itself, I decided to "replace" the up/down buttons with MOSFET transistors.

This is a MOSFET I am using. It has a Vgs threshold voltage between 2-4 volt, which will work for my 5v microcontroller.

I opened up the button box and here is what it looks like.

There are four wires going in the JST connector.

  • Red : 30V
  • Black : GND
  • Green : Down
  • White : Up

This is an active-high switch where connecting either Green or White to Red will move the desk down and up, respectively. See below diagram for how the switch (Omron SS-5) does in the schematic.

What I did so far

I pulled out the JST connector and connected jumper wires directly to the female pins to create the following circuit for raising the desk.

enter image description here

The voltage source on the left-side is the digital-out pin of a microcontroller. I was successfully able to raise the desk when the pin was high and stop raising the desk when the pin was low.

Edit(August 16th 2020): I measured the current from the source of the transistor to the white wire, and it spiked to ~3A for a brief moment, and while the desk is rising(i.e. when the motor is operating), it outputted ~300mA.

I was also able to do the same for lowering the desk, except that the source of MOSFET was connected to the Green wire instead.

My problem is:

I placed another transistor as such to do both raising and lowering:

enter image description here

Edit(Aug 15th 2020): Sorry about the confusing diagram. This diagram DOES use two digital output pins. The voltage source on the left side is D2 of MCU and the one on the right is D3 of MCU. The pins share a common ground, which is responsible for the following problem.

This obviously created a problem because the source of both transistors are connected to both White and Green wire, meaning that every time one transistor is on, both White/Green wires are HIGH. This is equivalent of pressing both buttons at the same time, which doesn't move the desk at all. I tried putting 10k resistor between the two sources of the transistors, but that did not solve the problem.

My question

  • How should I edit my circuit to fulfill what I am trying to do?
  • Is this something I can even create just by using transistors? or
  • Do I need to open the motor to follow the typical use cases of transistor-as-switch?

I would greatly appreciate if anyone can give advice on my situation :)

I am more than happy to clarify any confusion.

Thank you!

  • \$\begingroup\$ First of all, put a schematic in your question to show the existing configuration of the switches. I could guess from your FET replacements, but it's best to be sure. Do they pull the white an green wires up to 30 V to operate and o/c otherwise? Or do they switch them between 0 and 30? Do you know what the GND connection doing there if the former? If the switches do pull up, then you would need P-channel FETs, with level shifting from your MCU. What current is running in the switches, a low current control signal, or the motor current? \$\endgroup\$
    – Neil_UK
    Commented Aug 16, 2020 at 6:25
  • \$\begingroup\$ Thank you very much for your quick reply! I have edited the post to answer your questions. 1) The button switches them between 0 and 30V. 2) As mentioned in my edit, the current that is running in the switches is 3A for a brief moment when the button is pressed, and ~300mA while the motor is operating. The power brick of the desk states: - Output: 29.0 V DC 1.8 A 52.2 W Does ~300mA fall under "low current control signal"? 3) Could you elaborate a little bit more on your suggestion on using P-channel FETs? \$\endgroup\$
    – Frank Lee
    Commented Aug 16, 2020 at 7:18
  • \$\begingroup\$ It seems like the white and green wires connect directly to the motor. Is that the case? If that is true, you can look up how to control a DC motor with a microcontroller. \$\endgroup\$ Commented Aug 17, 2020 at 12:40

4 Answers 4


The brief 3 A while the motor starts up means that the white and green wires carry motor current. Your FETs have to be adequate for this current, and protected for the voltage spike when the motor switches off.

Your original switch diagram shows an H-bridge configuration. With both switches down, there is no current to the motor. When either switch goes up, both conduct current to the motor, one sourcing from 30 V, the other sinking to 0 V. Your FET suggestions only show a pullup, no pulldown, so your motor will not run.

You need either an H-bridge driver with a disable, or two half-bridge drivers, to replicate this functionality. Given the level shifting etc needed and your knowledge of electronics, it would be most sensible to try to buy logic-level-input modules, with outputs rated for at least 30 V and 3 A.

Instead of FETs, it would also be reasonable to use a pair of c/o relays to do exactly what the switches are doing. Go to your favourite online e-commerce site and search for 'Arduino relay module', and pick a 2 channel one. They can be driven from 5 V, as cheap as chips, don't blow up like FETs (though the contacts will wear out eventually), and have just enough DC handling capacity for your 30 V motor.


problems with assumptions for design

  • failed to recognize purpose of SPDT.
  • did not understand Vgs(th)
  • motor will surge with 10x rated current or much more than actual load current since it is probably not using maximum load weight.

E.g say motor rated for 1A but only uses 0.3A except 10x1=10A on startup.

  • when switching off, there is an arc and back EMF of motor acting as generator and switch as brake and gears as friction brake with coil shorted for additional load.
  • thus you need a POWER Half Bridge that works with Logic levels using 30V output with power diodes to handle 10A spikes or 20A spikes if reversed quickly while moving.

Problems with FET designs

  • you assumed 2~4V was the operating Vgs but it is only the threshold and you need at least 2.5 to 3x 100uA threshold to get close to RdsOn to handle >10A, which is often specified at Vgs=5, 10 or 12V.

  • “Logic Level FETs “ use Vgs(th) near 1V to operate at 3V for best performance, otherwise they get hot.

  • instead of high side driver , you need a SPDT or half Bridge power FET

A power half bridge is needed that uses logic level input and output probably rated for 30A to have small enough Rdson to keep cool during start. Power diodes reversed to to each rail for Flyback clamp are both needed rated for 10A.

  • half bridge must have small deadtime between Fwd and Rev to prevent short circuit or Shoot through effect. This is normal. But you must ensure it.


Define Motor coil resistance and choose Logic Level Half Bridge IC to drive 30V/DCR + margin

Ensure it has deadtime protection with input controls with RC diode delay or MCU delay and verify Power up reset state is Off.
what about end stop protection? In case of failure on driver or MCU glitch? Consider Polyfuse.

Do the thermal resistance calculations for heatsink and electrical insulation insulator with grease.

This is common to Car power window switch design except more mass, less speed but maybe same current (?) salvage from car graveyard! Or DIY or buy? these are daily make/Buy decisions of any designer.

Finally, what about position sensor or? Position sensor for long travel might be expensive unless you are a mechanical genius to use Pot with 8mm CNC or smaller cog gear belt from linear motion to pulley reduction to pot , then read pot voltage as linear position, calibrate and use for servo feedback. Then allow MCU input switches to remember states you enter for positions and toggle up next and down next or 1,2,3 +,-. But debounce the switches. Anything else missing? End stop switches? STD practice for CNC machines.


Another option would be to use two SPDT relays, having contact ratings identical to that of the existing SS - 5 microswitches.

enter image description here

  • \$\begingroup\$ Please see below comment I left for the other person that suggested the same solution. \$\endgroup\$
    – Frank Lee
    Commented Aug 16, 2020 at 6:19
  • 2
    \$\begingroup\$ @Frank, "below" doesn't work on SE sites as answers float up and down by votes and sorting preferences. \$\endgroup\$
    – Transistor
    Commented Aug 16, 2020 at 8:27

If the desk is just switches, a motor and relays, containing no polarity sensitive components, you could simply reverse the polarity of the power supply. You would then have a common 0v rather than a common 30v rail.

You could then use 2 NPN transistors or possibly 2 N type mosfets to switch the 0v to the white and green wires. The up and down will obviously be reversed too.

You will need to add a couple of free-wheeling diodes to protect your transistors from the back emf from the existing relay coils and motor.

  • \$\begingroup\$ It probably isn't that simple. There have to be protections against the motor going too far and other stuff, and relay clicking would be annoying. This company also makes ones that do have memory features, and so are not just motors and relays, so it seems very likely that they use the same motor control part with this board, just without the other buttons. \$\endgroup\$
    – BeB00
    Commented Aug 17, 2020 at 8:00
  • \$\begingroup\$ @BeB00 I agree, it is unlikely, but possible. Limit switches don’t necessarily need active components. We have some similar desks at work that you can faintly hear relays clicking. \$\endgroup\$
    – HandyHowie
    Commented Aug 17, 2020 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.