timer issue

hi all , i tried to write a sketch to move a servo for 8 hours then go back to 0 and detach until the morning and repeat, now, if i use small mills to test it works fine , but when i tesst this sketch, nothing happeaned for 24, then servo is buzzing but not moving, im new at this , and sat here for 2 weeks , trying to find out what i have done wrong, and now i finnaly ask, as im lost
thanks
craig

#include <SimpleTimer.h>
#include <Servo.h> // create servo object to control a servo
Servo myservo; // create servo object to control a servo

// the timer object

SimpleTimer timer;

int pos = 0; // variable to store the servo position

void setup() {

myservo.write(0);

Serial.begin(9600);

timer.setInterval(86400000, moveservo); // move servo every 24 hours

}

void moveservo() {

myservo.attach(9);

for (pos = 0; pos <= 180; pos += 1) { // 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(28800000); // waits 15ms for the servo to reach the position

}

for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees

myservo.write(pos); // tell servo to go to position in variable 'pos'

delay(15); // waits 15ms for the servo to reach the position

if (pos == 0) {

myservo.detach(); // Turn off Servo motor between moves

}

}

}

void loop() {

timer.run();

}

What do you think this does?

delay(28800000); // waits 15ms for the servo to reach the position

Hi there!

I see you have a line of code as shown below:

delay(28800000);

This will cause an 8 hour delay. So the motor will only move three degrees in the 24 period, and is reset when the timer calls the moveservo() function again.

Try setting this delay to 15ms by using the following line:

delay(15);

Good luck!

ah i thought it was for move servo to pos 180 and takes 8 hours to get there and the other is 180 to 0 in 15mills?

No, in fact you do not need to move your servo in steps.

myservo.write(180); // Move to pos 180
delay(8 hours);
myservo.write(0); // Move to pos 0

But.. You should not use delay at all. You could use an "one shot" timer which is set to start 8 hours after the servo has been moved to pos 180.

thanks for your reply and info
hes what im try to do, i want to move the servo for 8 hours, 0 to 180, then back to 0, in 15mills, then wait 16 hours trhen move 8 hours, its for a solar tracker ( a very crude one), im just mixed up in the timing.... and probaly a lot move, your sugestions , are all noted and i will try when i get home, thanks for your info
craig

You need to know that "servo.write(180)" will cause the servo to move as fast as it can to the specified position. If that is too fast for your application, you must keep using the "for" loop with some delay in it in order to slow it down - but definately not 8 hours of delay for each step! :wink: