Pages: [1] 2   Go Down
Author Topic: Servos Delay  (Read 2620 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 hi guys,
  i'm a complete new bee, i've buy an arduino uno to control one servo, i need to control it with a very simple program to move it in the 0° position to the 180°position, wait here for 25seconds, and go back to the 0 position, waiting 25sec and again and again...
   does this little program will do this:
 
  // Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.


#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
 
void loop()
{
  for(pos = 0; pos < 180; pos += 10)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 10 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(20000);                       // waits 20sec for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=10)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(20000);                       // waits 20sec for the servo to reach the position
  }
}

 Your opinion and help will be appreciated.
  best regards
christophe
« Last Edit: May 27, 2011, 03:54:55 pm by christophe31 » Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 67
Posts: 3701
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not quite, no. You need to look at the delays you're using. Hook it up and try it though, it'll quickly become obvious what's wrong.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26332
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your description says 25 seconds, the code suggests 20 seconds (though it's in the wrong place).
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes , but it's just for example, in fact i'll change this delay with test, the most important it's to have the delay in seconds, and to change it, if needed.

   do you think this code like writting here will do this? (with the 20sec delay).

  myy arduino it's on the way and i'll try the code as soon as receive.
  your opinion will be appreciated.
  may be if someone have one arduino linked with an servos , someone can test this.
  christophe
« Last Edit: May 27, 2011, 03:52:48 pm by christophe31 » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26332
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
do you think this code like writting here will do this?
No, your servo will move extremely slowly, taking six minutes to sweep 180 degrees.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is something like below what you are looking for?

Code:
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
int a = 10;
int b = 170;

void setup() {
  Serial.begin(9600);
  myservo.write(a); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  myservo.write(a);
  Serial.println(a);
  delay(5000);
 
  myservo.write(b);
  Serial.println(b);
  delay(5000);
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is something like below what you are looking for?

Code:
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
int a = 10;
int b = 170;

void setup() {
  Serial.begin(9600);
  myservo.write(a); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-test"); // so I can keep track of what is loaded
}

void loop() {

  myservo.write(a);
  Serial.println(a);
  delay(5000);
 
  myservo.write(b);
  Serial.println(b);
  delay(5000);
}

  oh , in this case it's only the loop who have delay, is it correct?
  in mine i've put the delay in the travel of the arms position.
  if it's that , i understand, and will try this one, and make you one video to show youthe result as soon as i receive the arduino.
  thanks for all your help.
  regards
christophe
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I understand correct you nedd a loop() like this:

void loop()
{
  for(pos = 0; pos <= 180; pos += 10)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 10 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15); //delay so that servo reach new position - depends on step - experiment with speed;
      }

delay(25000); //waits 25sec in 180 deg. position

  for(pos = 180; pos>=0; pos-=10)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
     delay(15); //delay so that servo reach new position - depends on step - experiment with speed;
  }

delay(25000); //waits 25sec in 0 deg. position
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8856
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i've buy an arduino uno to control one servo, i need to control it with a very simple program to move it in the 0° position to the 180°position, wait here for 25seconds, and go back to the 0 position, waiting 25sec and again and again...

So you want:
Code:
#include <Servo.h>
 
Servo myservo;
 
void setup()
  {
  myservo.write(0);  // Set initial position
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  }
 
 
void loop()
  {
  myservo.write(180);  // "move it [from] the 0° position to the 180°position,"
  delay(25*1000);  // "wait here for 25 seconds,"
  myservo.write(0);  // "and go back to the 0 position, "
  delay(25*1000);  // "waiting 25 sec"
  // "and again and again..."
  }
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 hi guy's,
   i've receive tonight my arduino uno, and after 5 min of coding, try the code that you have give to me, and i've found one who work fine like i want :
    goes to one position
    Wait the time i want there
    goes to the original position.
   here the code:
  #include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
 
void loop()
{
  for(pos = 0; pos < 180; pos += 180)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 180°
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(28000);                       // waits 28s for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=180)     // goes from 180 degrees to 0 degrees
  {                                   // in step on 180°
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(28000);                       // waits 28s for the servo to reach the position
  }
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26332
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop()
{
  for(pos = 0; pos < 180; pos += 180)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 180°
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(28000);                       // waits 28s for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=180)     // goes from 180 degrees to 0 degrees
  {                                   // in step on 180°
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(28000);                       // waits 28s for the servo to reach the position
  }

Well, that's one(long winded) way of doing it.
Simpler might be
Code:
void loop()
{
    myservo.write(0);             
    delay(28000);                       
    myservo.write(180);
    delay(28000);
 
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 ok i'll try this one too.
 thanks
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 ok so i've try this simplest code, but now, the servos don't do the loop, in fact it does the code one time , and that's all......
   any idea?

  how to proceed to be sure to erase and empty the memory ? to upload code like new card

 edit:
  i've succeed with this code:
  #include <Servo.h>
 
Servo myservo;
Servo servo_b;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);
  servo_b.attach(10);  // attaches the servo on pin 9 to the servo object
}
 
 
void loop()
{
  for(pos = 0; pos<=180; pos += 180)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 180°
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(22000);                       // waits 28s for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-= 180)     // goes from 180 degrees to 180 degrees
  {                                   // in step on 180°
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(100);                       // waits 28s for the servo to reach the position
  }
 
}
 
   don't take care of the servo_b, it'ss for another function, and as you note the second delay ( 100ms), doesn't do anything, the servos goes in up/down position each 22sec,
  christophe
« Last Edit: June 02, 2011, 06:28:37 am by christophe31 » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26332
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
how to proceed to be sure to erase and empty the memory ? to upload code like new card
There is no need - any sketch uploaded will overwrite the previous one.

I don't understand why it doesn't loop - the code should be functionally equivalent to the one with loops.
Can you post the entire sketch, please?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
ok so i've try this simplest code, but now, the servos don't do the loop, in fact it does the code one time , and that's all......
   any idea?

Sounds like you put that code in the setup() function instead of the loop() function.  If it was in the loop() function, it would get executed repeatedly.  It's very simple code, so there's really no room for any other explanation.
Logged


Pages: [1] 2   Go Up
Jump to: