The DiyServo service is a service that can be used as a normal servo, but it's built from a motor and an analog input. The idea is that you should be able to use any motor and any analog input to byild your own servo. The circuit below can be used to connect the motor and the servo to a single Arduino. But it's also possible to configure in alternate ways. 





#file : /service/ edit raw
# webgui = Runtime.createAndStart("webgui","WebGui")
# Start of script for DiyServo
# Analog input A0 is the same as digital 14 on the Arduino Uno  
A0 = 14
# Start the Arduino
arduino = Runtime.createAndStart("Arduino","Arduino")
# Start Servo
servo = Runtime.createAndStart("Servo","DiyServo")
servo.attach(arduino)      # Attach the motorcontroller
servo.attach(arduino,A0) # Attach the analog pin 0 
# End of script for DiyServo



hairygael's picture

I just love it !!! Thanks

I just love it !!!

Thanks guys for this fantastic MRL service.

I have been dreaming of this, ever since I burned my first servo!!

SylvainJeanneton's picture

Turn left or right

Thanks your code is very usefull, thanks a lot. But it commands only the speed. How can we command the way ? In other words turn left or turn right with a middle point ? (it exists potentiometer with middle point. I 'm shure of this.) In fact we need both speed and way left or right.


Mats's picture


In the example I only have the motor out to show that it works.

Kwatters built the complete DiServo as you can see int his post. So it works in both directions and you can use it just like any other servo. But you have to  mount the pot, so that it turns with the joint.


If you built one and only can control speed, then you need a different motor control board.

If  you for example use that board from the drill, then it will only move in one direction and only control speed.

I use a BTS7960B that I bought from here.

I also use a IBT-4 board from here:

I tested the drillmotor with a LN298N board, but it was not powerful enough.

I also tried this board, but it could only drive the motor in one direction: