Bekir Bilge
Published © CC BY-NC

Automatic Servo Tester with Arduino Nano

Some servos may be corrupted or may be working incorrectly. With this project you can make a fast servo tester.

AdvancedFull instructions provided3 hours4,160
Automatic Servo Tester with Arduino Nano

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Rotary Potentiometer, 500 kohm
Rotary Potentiometer, 500 kohm
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Blank Circuit Board
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Automatic/Manually Servo Tester

Diagram of Automatic/Manually Servo Tester

Code

Automatic/Manually Servo Tester

Arduino
That code is automatic/manually servo tester for Arduino.
#include <Servo.h>

Servo myservo1,myservo2;  // create 2 servo objects to control servos

int potpin = A0;  // analog pin used to connect the potentiometer
int butonpin = A1; // analog pin used to connect the push buton
int val;    // variable to read the value from the analog pin
bool press=LOW;  // variable to store the buton press 
int pos = 0;    // variable to store the servo position
void setup() {
  myservo1.attach(3);  // attaches the servo1 on pin 3 to the servo1 object
  myservo2.attach(5);  // attaches the servo2 on pin 5 to the servo1 object
  Serial.begin(9600);  // generates serial connection
}

void loop() {
  
  	press=digitalRead(butonpin);		   // reads the value of the buton (HIGH or LOW)
    Serial.println(press);
  if (press == 1) {                   // if push buton pressed automatic mode starts
    for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo1 to go to position in variable 'pos'
    myservo2.write(pos);              // tell servo2 to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo1 to go to position in variable 'pos'
    myservo2.write(pos);              // tell servo2 to go to position in variable 'pos'
     delay(15);                       // waits 15ms for the servo to reach the position
  }
  } else {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo1.write(val);                 // sets the servo1 position according to the scaled value
  myservo2.write(val);                 // sets the servo2 position according to the scaled value
  delay(15);                           // waits for the servo to get there

  }
  }

Credits

Bekir Bilge

Bekir Bilge

1 project • 2 followers

Comments