How to Fix Inaccurate Shaft Angle Rotation Servo Motor on Arduino Controller

by ilhamdefra in Circuits > Arduino

1094 Views, 4 Favorites, 0 Comments

How to Fix Inaccurate Shaft Angle Rotation Servo Motor on Arduino Controller

IMG_20210302_143048.jpg
1da3982a76b71e15eb31d6390f053082.png
IMG-20200922-WA0005.jpeg

If you use 180 degree hobby servo and drive it with Arduino servo.write(); function, then you might encounter the actual angle shaft rotation of the motor didn't match to what you write inside the function parentheses (inside parentheses is angle value of the shaft, in degrees, rotating the shaft to that orientation).

In short, the way typical hobby servo motor used by many Arduino community work is by responding a signal output/sent from controller board (I/O pin of Arduino board) to the yellow cable of the servo, this method is called Pulse Width Modulation (PWM). Each servo motor manufacturer might have different specs of 0 degree position and 180 degree position of their product, make sure to pay attention for that information. For easier understanding how servo motor works responding signal from controller is shown on the picture above.

Instead of using Servo.write(); function, i prefer to use Servo.writeMicroseconds(); function. Anyway a servo is work by responding that microseconds value of digital signal from Arduino board I/O pin. Servo.write(); function is just to make beginner easier to learn and use servo in their Arduino project. Arduino library has compile how much microseconds signal send to declared servo pin by declaring angle value, the problem is not all servo will work and give actual rotation as Arduino Servo.write(); library.

By using Servo.writeMicroseconds(); probably will solve the problem of shaft rotation angle error because you directly have control how much microseconds signal that representing desired angle you want.

Supplies

List of component:

  • Any Arduino board (i use Uno)
  • PC/laptop (any OS)
  • Arduino IDE software, if you Windows user you can download from Microsoft Store, or use link here.
  • Jumper wire
  • Hobby Servo Motor (i use clone version of TowerPro MG996R)
  • Protractor
  • Servo disk (usually this is included when you buy servo)
  • Some double tape to attach protractor to servo disk

Find Your Servo Specific Angle

IMG_20210302_172345.jpg
Screenshot 2021-03-02 175639.png

Specific angle mean how much angle (in degrees) per microseconds of your servo motor shaft rotation. This is the core of the calibrating. Each servo model from various manufacturer/brand might will have different figure of the angle per microseconds. More expensive servo should be have smaller angle rotate per microseconds signal its responded, because they probably have better controller circuit, higher quality encoder (potentiometer), less gearbox backlash, etc.

Finding specific angle is first by attaching a simple arc measurement tools (i use protractor like picture shown). Then test run by set your servo at 0 degree position, check your servo manufacturer specs/datasheet, usually 0 degree position is 500-1000microseconds, in case servo i use is clone version of TowerPro MG996R, i assume 0 degree position is 550microseconds. Then drive the servo to any microseconds, let say 2250microseconds, the servo shaft will rotate. Measure the shaft rotation angle using the protractor from that 550 to 2250 position. In my case measured 200 degree.

Using Servo.writeMicroseconds(); to Drive Servo to Desired Angle Instead of Servo.write();

Screenshot 2021-03-02 183041.png

Using Servo.writeMicroseconds(); to drive servo to desired angle mean that you must calculate the microseconds signal value that needed inside the function parentheses, this is why specific angle is very important. or in other word how much signal value that represented 'x' degree.

Remember, in my case 0 degree position is 550microseconds, then to make the shaft rotate to desired 'x' degree angle is 0 degree signal added by desired angle divided by specific angle, or the formula can be written like on the picture. Write the formula inside the Servo.writeMicroseconds(); function parentheses.

Example to use this method to drive servo motor instead of using Servo.write(); function is shown on the arduino Files.