Control of Servo Motor Postion with an Accompanying Servo Drive

Hello Everyone,

I am currently an undergraduate student working on a summer research project, and I have a question about controlling the angular position of a servo motor using a servo drive and an Arduino Uno (In particular, the servo motor is a Leadshine BLM57050 and the servo drive is a Leadshine ACS306).

Currently, I am able to run the servo motor with an Arduino Uno using the following code,

int PUL_pin = 6;               //Declaration of the PUL signal control pin as pin 8
int DIR_pin = 9;               //Declaration of the DIR signal control pin as pin 9

void setup() {
  //Setup code to run once:
  pinMode(PUL_pin, OUTPUT);
  pinMode(DIR_pin, OUTPUT);


void loop() {
  digitalWrite(PUL_pin, LOW);
  digitalWrite(PUL_pin, HIGH);
  digitalWrite(DIR_pin, HIGH);

However, this code will continuously run the servo motor and provides no positional control.

I was wondering, how would I be able to code the Arduino such that it allows for angular position control of the servo motor?

As of know, I know that 4000 pulse signals (PUL signals) allow for one complete rotation of the servo motor, and there is an associated linear function where based upon an input of the angular position of the servo motor, the output will be the amount of PUL signals needed to reach the specified angular position of the servo.

To control the amount of PUL signals sent to the servo drive would I have to insert a for loop within the void loop() function?

As of now, I am under the belief that the void loop() function runs continuously, which results in PUL signals being continuously sent to the servo drive (which results in the continuous motion of the servo motor). Is this a correct assumption? Is there any way for me to set this loop such that it only runs for a specified amount of iterations rather than continuously?

Any help is greatly appreciated. Thanks!

Post a link to the datasheet for your motor and for your motor driver.

Be aware that when the word “servo” is used on this Forum people usually think of the devices used to control rudders and ailerons in flying model airplanes.


I don’t think this is a servo as we know it - it’s a motor with a rotatory encoder attached , the company provides a positioning system for it which is the second unit mentioned.From a very quick look at the data sheet it’s a three phase brushless motor, with an encoder on the back .

You need to study the data sheet carefully to understand how to use it

It’s EXACTLY a servo...
Just broken out into its component parts.

OP is finally someone that understands the difference between servo motors, rc servos and stepper motors... Good luck with your project.

Here they are...

OP, you’ll need to write a couple of fairly simple functions to read and control the unit elegantly. Get started, and post your efforts here, well help with contributions. Unfortunately, we don’t have the same controller & motor to test against.

I don’t think this is a servo as we know it - it’s a motor with a rotatory encoder attached , the company provides a positioning system for it , which can make the system “ look” like a stepper motor to the outside world . The data sheet gives details of the type of stepper it replaces and how to drive it . Hence the OP is sending pulses to it .

I think the OP needs to look at how the Arduino works by looking at the examples and understand what’s going on . Yes “loop” runs continually , but you can code this loop so that it only moves the motor in response to some external source ( eg a switch)

Logically something g like “ if switch on step motor on 100 steps” or whatever . If the switch is off , when the program “loop”’s instruction see the switch is off at each pass the motor won’t move.

It is EXACTLY a servo motor with a closed-loop control system.
It’s NOT an RC servo (which is a complete servo loop in a small box)

In introductory Tutotials, there is a simple explanation, or you can trawl through Wikipedia for more info.

Hello Everyone!,

Thank you so much for the replys and assistance.

I wanted to give everyone a quick update to say that me and my project group were able to get the servo motor to rotate for a specified amount of rotations. Here is the Arduino code that allowed us to do so,

int PUL_pin = 5;
int DIR_pin = 6;

void setup() {
  pinMode(PUL_pin, OUTPUT);
  pinMode(DIR_pin, OUTPUT);
  for(int i=0; i<=PUL_signal_value; i++){
  digitalWrite(PUL_pin, LOW);
  digitalWrite(PUL_pin, HIGH); 

void loop() {

where the variable PUL_signal_value is the output of a linear function for the amount of pulse signals to send to the servo drive based upon the desired angular position of the servo motor.

Again, thank you all for the help, it was much appreciated!