microseconds servo

if i command myservo.writeMicroseconds(700); will that play the servo for 700 microseconds?

Nope. The servo interprets the duration of the pulse, 700 microseconds in this case, as a position to move to.
A typical servo uses 1500 microseconds as a center position signal. 1000 microseconds is full left and 2000 microseconds is full right.

The actual range varies by manufacturer, model and, I believe, production run.

Your 700 microsecond value is very far left.

Do note that some servos become physically damaged if you attempt ro run them past their physical rotation limits.

Did you read the the Servo.writeMicroseconds() reference? Apparently not because the answer is no :wink:

ok that is very bad news i was makeing code for my robotic arm and now i really am stuck. :slightly_frowning_face: :slightly_frowning_face: would there be any other way to determine when the servos completed their moves here was my code

#include <Servo.h>
Servo servo_1;
Servo servo_2;
Servo servo_3;
Servo servo_4;

int potpin1 = 0;
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;


int raw_pot1;
int raw_pot2;
int raw_pot3;
int raw_pot4;

int servo_1data[100];
int servo_2data[100];
int servo_3data[100];
int servo_4data[100];

int pot1val;
int pot2val;
int pot3val;
int pot4val;

int s1done = 0;
int s2done = 0;
int s3done = 0;
int s4done = 0;

int arraystep = 0;
int arraystepplay =0;
unsigned long lasttime = 0;
int donemove;
unsigned long currentMillis;

void setup() {
Serial.begin(9600);
servo_1.attach(2); 
servo_2.attach(3);
servo_3.attach(4);
servo_4.attach(5);
pinMode(6,INPUT);//record button
pinMode(7,INPUT);//play button
}

void loop() {
raw_pot1 = analogRead(potpin1);
raw_pot2 = analogRead(potpin2);
raw_pot3 = analogRead(potpin3);
raw_pot4 = analogRead(potpin4);          
  
pot1val = map(raw_pot1, 0, 1023, 700, 2300);
pot2val = map(raw_pot2, 0, 1023, 700, 2300);
pot3val = map(raw_pot3, 0, 1023, 700, 2300);
pot4val = map(raw_pot4, 0, 1023, 700, 2300);

servo_1.writeMicroseconds(pot1val);
servo_2.writeMicroseconds(pot2val);
servo_3.writeMicroseconds(pot3val);
servo_4.writeMicroseconds(pot4val);

if(digitalRead(6) == HIGH){
delay(500);
servo_1data[arraystep] = pot1val;
servo_2data[arraystep] = pot2val;
servo_3data[arraystep] = pot3val;
servo_4data[arraystep] = pot4val;
Serial.println(arraystep);
arraystep++;
Serial.println(arraystep);
 }
if(digitalRead(7) == HIGH){
  
  lasttime = currentMillis;
  donemove = 0;
  servo_1.writeMicroseconds(servo_1data[arraystepplay]);
  servo_2.writeMicroseconds(servo_2data[arraystepplay]);
  servo_3.writeMicroseconds(servo_3data[arraystepplay]);
  servo_4.writeMicroseconds(servo_4data[arraystepplay]);
  while(donemove ==0){
  currentMillis = micros();
  Serial.println(currentMillis);
  if(currentMillis - lasttime >= servo_1data[arraystepplay]) s1done = 1;
  if(currentMillis - lasttime >= servo_2data[arraystepplay]) s2done = 1;
  if(currentMillis - lasttime >= servo_3data[arraystepplay]) s3done = 1;
  if(currentMillis - lasttime >= servo_4data[arraystepplay]) s4done = 1;
 
  if((s1done == 1) && (s2done == 1) && (s3done == 1) && (s4done ==1)) donemove =1;
  if(donemove == 1) arraystepplay ++;
 
  }
 }
}

A servo will typically have a rating of X degrees per second at a given load
This could be used as a rough estimate of the time for it to move from x0 degrees to x1 degrees.

If you really want to know when the servo has arrived at the position you sent it to you could use special servos with feedback. Adafruit sell a few About Servos and Feedback | Analog Feedback Servos | Adafruit Learning System

It's possible to modify many standard servos to provide similar feedback but it's a bit fiddly.

Steve

But most of the time you don't really need it. Because you want to move slower than the max speed aka, you have to make it move slower and you can assume it reached it's position pretty quick after you finished moving it all the way.

This little test sketch might help. :slight_smile:

/*
 Try this test sketch with the Servo library to see how your
 servo responds to different settings, type a position
 (0 to 180) or if you type a number greater than 200 it will be
 interpreted as microseconds(544 to 2400), in the top of serial
 monitor and hit [ENTER], start at 90 (or 1472) and work your
 way toward zero (544) 5 degrees (or 50 micros) at a time, then
 toward 180 (2400). 
*/
#include <Servo.h>
Servo servo;

void setup() {
  // initialize serial:
  Serial.begin(9600); //set serial monitor baud rate to match
  servo.write(90);
  servo.attach(9);
  prntIt();
}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    int pos = Serial.parseInt();
    pos = constrain(pos, 0, 2400);
    servo.write(pos);
    prntIt();
  }
}
void prntIt()
{
  Serial.print("  degrees = "); 
  Serial.print(servo.read());
  Serial.print("\t");
  Serial.print("microseconds =  ");
  Serial.println(servo.readMicroseconds());
}

here is what i got not exactly sure what the code does, would it be how long the servo take to move to that spot

degrees = 180 microseconds = 2400
degrees = 0 microseconds = 544
degrees = 170 microseconds = 2296
degrees = 0 microseconds = 544
degrees = 160 microseconds = 2193
degrees = 0 microseconds = 544
degrees = 150 microseconds = 2090
degrees = 0 microseconds = 544
degrees = 140 microseconds = 1987
degrees = 0 microseconds = 544
degrees = 130 microseconds = 1884
degrees = 0 microseconds = 544
degrees = 120 microseconds = 1781
degrees = 0 microseconds = 544
degrees = 100 microseconds = 1575
degrees = 0 microseconds = 544
degrees = 90 microseconds = 1472
degrees = 0 microseconds = 544
degrees = 80 microseconds = 1368
degrees = 0 microseconds = 544
degrees = 70 microseconds = 1265
degrees = 0 microseconds = 544
degrees = 60 microseconds = 1162
degrees = 0 microseconds = 544
degrees = 50 microseconds = 1059
degrees = 0 microseconds = 544
degrees = 40 microseconds = 956
degrees = 0 microseconds = 544
degrees = 30 microseconds = 853
degrees = 0 microseconds = 544
degrees = 20 microseconds = 750
degrees = 0 microseconds = 544
degrees = 10 microseconds = 647
degrees = 0 microseconds = 544

would it be how long the servo take to move to that spot

No. It's time for you to do some research on how servos work.

hooverdan:
here is what i got not exactly sure what the code does, would it be how long the servo take to move to that spot

degrees = 180 microseconds = 2400
degrees = 0 microseconds = 544

Did you have the servo connected and did you check the angle of the servo arm with the angle displayed on the monitor as you entered angles?
Can you please tell us your electronics, programming, Arduino, hardware experience?
How are you powering the servos?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks… Tom… :slight_smile:

hooverdan:
here is what i got not exactly sure what the code does, would it be how long the servo take to move to that spot

No it’s not telling you anything useful, just how the Servo library translates angles (0-180) into pulse lengths in microseconds(544-2400). It will give exactly the same numbers if the servo isn’t even connected.

We weren’t kidding (or wrong!) when we said there’s absolutely no way you can tell when a normal servo has finished moving. Let me try again…for a normal servo the information does not exist so there is no way anyone can possibly give it to you.

Steve