Best way to make a servo tester

if you need to test out a servo, this is code for it, it fully rotates your servo one way, and then the other to make sure its all good

// made by salim sargi
// material needed : arduino board, servo, jumper wires 
// connect the black/brown wire to gnd, the red one to 5v/vcc and the yellow/orange one to pin 3, output

// this code allows you to test your servo by making it slowly fully turn counter clockwise and then fully clockwise.
#include <Servo.h> 
int servoPin = 3; //the pin that the servo will be attached to 
Servo Servo1; // creates a sevo object
int dec = 5; // this determines by how much the servo will turn each 100 ms, of 5 degrees 
int val = 5; // this determines the position of the servo
void setup() { 
   Servo1.attach(servoPin); 
}
void loop(){ 
   Servo1.write(val); 
  val = val + dec ;
    delay(100);
  if (val == 180) {
    dec = dec * (-1);
  }
// if the servo has fully turned, this allows it to turn the other way
  if (val == 0) {
    dec = dec * (-1); 
  }
  // if the servo has fully turned, this allows it to turn the other way
}
// end of code 
1 Like

You can use WOKWI.COM to show a simulation of your code.

Enhancement - add three potentiometers, for magnitude of sweep, speed of sweep, and centerpoint of sweep. Or, add an LCD and make those three variables you can modify using a few buttons.
Just a thought.

I have found that someof the the little Chinese servos do not like to be stalled for very long before the motor butns out. Therefore until I characterize each one, i will not use their full sweep.

I find the full sweep, experimentally, and write it on the side.

1 Like

Hence my suggestion for some control over variables, and maybe an LCD readout. Of course, it all depends on how many servos you have to manage.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.