Boris LeonovSam KristoffArthur Brown
Published © MIT

Servo Signals and Characterization

Exploring the signals behind Arduino's Servo library, and characterizing a servo's response to pulse width.

EasyProtip1 hour4,968
Servo Signals and Characterization

Things used in this project

Hardware components

Servos (Tower Pro MG996R)
Most servos have the same operating parameters.
×1
OpenScope MZ
Digilent OpenScope MZ
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1

Software apps and online services

Digilent WaveForms Live

Story

Read more

Code

Servo Characterization

Arduino
Use this code to characterize the servo. It was written for the Arduino Uno.
#include <Servo.h>

// create a servo object
Servo servo; 

//analog input from the potentiometer
int potPos = A0;

void setup() {
  // link the servo to pin 9, and set the pulse width limits (544ms and 2400ms in this case)
  servo.attach(9, 544,2400);  

  //set the analog pin as an input
  pinMode(potPos, INPUT);
}

void loop() {
  //store the potentiometer position as a float
  float level = analogRead(potPos);

  //calculate analog data as a voltage
  float voltage = 5*level/1024;

  //make sure the voltage isn't outside the acceptable range
  if(voltage < 0){
    voltage = 0;
  }
  if(voltage > 5){
    voltage = 5;
  }

  //scale voltage to 180 degrees
  servo.write(36 * voltage);

  //give the servo time to move to new position
  delay(15);
}

Credits

Boris Leonov

Boris Leonov

10 projects • 15 followers
Electrical engineering student in the Seattle area. Electrical and mechanical DIY enthusiast. Fixer of things, large and small.
Sam Kristoff

Sam Kristoff

35 projects • 30 followers
Director of Engineering at Digilent.
Arthur Brown

Arthur Brown

14 projects • 15 followers
Applications engineer and digital logic geek

Comments

Add projectSign up / Login