I was wondering if there was any difference between controlling a normal rotating servo and a linear servo with the raspberry pi. Would the code look essentially the same? I'm trying to build a device that can push a button, and I can't seem to find many good tutorials online with small linear servos controlled by a pi.

I have a motor controller HAT from adafruit: https://www.adafruit.com/product/2348 I was planning on buying this: https://www.actuonix.com/Actuonix-PQ12-R-micro-linear-servos-for-RC-p/pq12-r.htm

Would I be able to effectively control the linear servo with a raspberry pi and that HAT? I apologize, I'm new to this and I'm not familiar with a lot of the electrical engineering side of things yet.

  • Well, it depends on the user requirements such: force, distance, speed, price, Micky Mouse, industrial, robotic, or NASA projects? – tlfong01 May 15 '20 at 5:45
  • Linear servos/motors are usually precise but slow. If you just wish to push a button, or press a key, you can consider using a solenoid: raspberrypi.stackexchange.com/questions/98232/…. – tlfong01 May 15 '20 at 5:50
  • 1
    For the force, I need it to be able to push a button to make a toilet flush, and small enough that it can fit inside the tank. Speed isn't a massive deal since the button kind of hits a point of no return so I can set it up just above that point and then have it push. Distance isn't a huge deal either for the reason mentioned above, but an inch or two should be good. – Josip May 16 '20 at 1:52
  • Hi @Josip, Ah I see. So it is a smart flush project. I pasted the enggr functional spec pic in my answer below. Then I am thinking aloud what I am going to develop (Ah, me hobbyist IoT toilet developer!). You are welcome to interrupt, comments, and make counter suggestions. Cheers. – tlfong01 May 16 '20 at 4:11
  • As I suggested earlier, a solenoid might do the job. On second thought, a electromagnet might work better . See Reference 5 in my answer. – tlfong01 May 16 '20 at 4:26

That is a servo and is controlled as other hobby servos. I.e. 50 Hz pulses in the range 1000 to 2000 microseconds long.

The code will look the same.

  • Sweet thanks! Would the hat be enough to power that servo, seeing as it's connected to a wall plug? – Josip May 16 '20 at 1:54
  • The HAT should be fine. The servo needs a maximum of half an amp at 6V. In practice it will use much less. – joan May 16 '20 at 9:37


How to DIY a smart toilet flush button?



(1) The flush button needs about 700g to push, that is a about 7N (Newton), travelling a distance of 25mm. So we need a big solenoid.

(2) A 8N solenoid takes 1.5A. So we also need a big current.


(3) The flush button I am playing actually has a spring to keep pushing the button up. So we can adjust the spring's force so that a smaller solenoid can also push down the button.

(4) Another idea is to use an electromagnet to push/pull down the button. A magnet takes little space and can be easier to make it water proof and hide inside the water tank.



(1) Amazon Flush Toilets Top Selected Products and Reviews

(2) 通用型免浮球馬桶進水器安裝DIY不求人 - 2016sep27 714,059 views

(3) 廁所水箱漏水之換零件DIY 粵語 - 2016sep13m 141,017 views

(4) DIY 維修更換ROCA 馬桶座、水箱零件維修更換 - 2016may04 227,156 views

(5) Connecting solenoid and electromagnet to Rpi - tlfong01, rpi.org.forums, 2019mar05

(6) How to use 12VDC Solenoid Lock

(7) Small and Big Solenoids


Appendix A - Smart Flush Functional Spec

EXQ Flush Spec

End of answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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