Hi!
Can anyone help me programme my servo. I have 4 servos and i dont know how to programme all 4 of them to move one after the other and not at the same time. I really need help it's my project work.
Thanks
Hi!
Can anyone help me programme my servo. I have 4 servos and i dont know how to programme all 4 of them to move one after the other and not at the same time. I really need help it's my project work.
Thanks
Come up with a spec that's a bit more precise than "one after another"" and show us the code you've written so far.
Post your code that moves one of them.
Add a delay() to allow one servo to complete its motion before you tell the next servo to move.
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo; Â // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; Â Â // variable to store the servo position
void setup() {
myservo.attach(3); Â // attaches the servo on pin 3 to the servo object
myservo.attach(5); Â // attaches the servo on pin 5 to the servo object
myservo.attach(6); Â // attaches the servo on pin 6 to the servo object
myservo.attach(9); Â // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 4) { // goes from 0 degrees to 180 degrees
 // in steps of 1 degree
 myservo.write(pos); // tell servo to go to position in variable 'pos'
 delay(15)
 myservo.write(pos);
 delay(15)
 myservo.write(pos);
 delay(15)
 myservo.write(pos);
 delay(15);      // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 4) { // goes from 180 degrees to 0 degrees
 myservo.write(pos);        // tell servo to go to position in variable 'pos'
 delay(15)
 myservo.write(pos);
 delay(15)       Â
 myservo.write(pos);
 delay(15)
 myservo.write(pos);
 delay(15);            // waits 15ms for the servo to reach the position
}
}
Please read these posts:
How to use this forum - please read. and
Read this before posting a programming question ...
You may also find useful information that would answer your question here:
Useful links - check here for reference posts / tutorials
You have posted code without using code tags. The code tags make the code look
like this
when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.
Also, do you realize how short 15 milliseconds is?
I want to know how to make 1 servo to turn from 0 to 180 degrees and back from 180 to 0 degrees then the 3 others do the same thing one after the other
Hint:
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Where should i write this code? And how can i modify the program to make 1 servo to turn from 0 to 180 degrees and back from 180 to 0 degrees then the 3 others do the same thing one after the other. I am new here so i don't know, so if someone could please send the written code.
Thanks a lot
Do you realize how short a time period 15 milliseconds is?
We want it to go from 0 to 180 degrees, wait for 15 ms then go from 180 to 0 degrees. We want it to go fast. But then we would like it to stop so that the other 3 more could do the same. Should the waiting time be 120 ms?
Nana111:
We want it to go from 0 to 180 degrees, wait for 15 ms then go from 180 to 0 degrees. We want it to go fast. But then we would like it to stop so that the other 3 more could do the same. Should the waiting time be 120 ms?
Hint: How do you know when it has reached 180 degrees?
Because it moves from one end to the other (180 degrees------ ------ 0 degrees). The servo makes a complete rotation from 0 degrees to 180 degrees, waits for 15ms, then 180 degrees to 0 degrees.
Nana111:
Because it moves from one end to the other (180 degrees------ ------ 0 degrees). The servo makes a complete rotation from 0 degrees to 180 degrees, waits for 15ms, then 180 degrees to 0 degrees.
You are telling me that it moves from one end to the other. You have not said how long a time it takes.
Also have you followed the suggestion in reply #7?
Also, do you realize how short a time 15 milliseconds is?
Where should we put it ?
We basically want to do whats in this video ; Multiple Servo Control with Arduino Uno R3 - YouTube but instead of the 4 servo work at the same time, we want them to work (one rotation back and forth (0 to 180 to 0)) one after the other. It takes 15 ms to do a rotation and that's how fast we want it to be.
Nana111:
Where should we put it ?
Here:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
(you have 4, apparently...)
How fast is your eyesight? Can you see the beginning and end of a 15 millisecond long event?
It takes 15 ms to do a rotation and that's how fast we want it to be.
That's pretty quick. Do you have the servo spec?