Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Jeremy Lindsay
Published © MIT

Calibrating My Servos

All my servos are a little bit different to each other - I've built a rig to measure what PWM values turn my servos to a specific angle.

IntermediateFull instructions provided12 hours42,227
Calibrating My Servos

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Adafruit PWM Servo Driver Shield
×1
M3 bolt
×8
M3 washer
×8
LM2596 DC-DC Step down voltage converter
×1
Red PLA
×1
White PLA
×1
180 degree clear math protractor
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
9g servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fusion
Autodesk Fusion

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Repo for Servo Calibrator parts

Code

Sketch for servo calibrator device

C/C++
#include <Adafruit_PWMServoDriver.h>
#define analogIn A0

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

int inputValue = 0;
int tmpPwmValue = 0;

void setup() {
  Serial.begin(9600);
  pwm.begin();
  pwm.setPWMFreq(60);
}

void loop() {
  inputValue = analogRead(analogIn);

  // inputValue will be between 0 and 1024
  // By observation, servo min and max PWM values are usually betwee 100 and 612
  // The formula below allows us to simply convert analog input to PWM
  int pwmValue = (int)(100 + (inputValue / 2));
  pwm.setPWM(0, 0, pwmValue);

  // Check to make sure we're not unnecessarily displaying duplicate data
  if (pwmValue != tmpPwmValue)
  {
    Serial.print("Potentiometer Input = ");
    Serial.print(inputValue);
    Serial.print(", PWM = ");
    Serial.println(pwmValue);
  }

  tmpPwmValue = pwmValue;

  delay(15);
}

Credits

Jeremy Lindsay

Jeremy Lindsay

4 projects • 30 followers
I'm a software engineer who likes building things. C#, 3d printing, robotics, embedded software, and electronics.

Comments