Hi guys! I recently bought an arduino and I'm just starting to get into programing. I'm trying to make my arduino move a servo arm about 120 degrees every 6 hours then go back to the initial position. Could you please help me? Oh and I've tried it with a 5 s delay instead of 6 hours and the servo was running all the time(it was still vibrating). Any way of getting rid of that (hibernate, or something like that?) ? And if not, how would it affect the servo?(lifespan??)
You will have to post a copy of your code as we can't read minds. And please put it between code tags - the # button above the editing space.
Also describe how you have everything wired up. The servo should not be powered from the Arduino.
There are dozens of Threads about servos on the forum. Have you studied any of them? You may find the answer there already.
...R
I strongly suggest a more descriptive subject line.
- I m a noob at this so take me slowly
- to wire up the servo I used this tutorial, in that the servo is wired to the arduino: Arduino Playground - SingleServoExample . isn't it good?
3.as for the code I used the servo sweep example and added a delay. The problem that I have is making the 6h timer and where to position it in 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 < 120; pos += 1) // goes from 0 degrees to 120 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 10ms for the servo to reach the position
}
for(pos = 120; pos>=1; pos-=1) // goes from 120 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 10ms for the servo to reach the position
}
delay(5000);
}
If you want to delay for six hours instead of five seconds then change your code to replace the delay of five seconds with a delay of six hours.
Your subject line still gives no useful information about what you want. This is the thing that you hope is going to attract the attention of people who know about the subject you're asking about, so it is in your interest (as well as ours) to use a meaningful subject line that indicates what you're asking about.
for(pos = 0; pos < 120; pos += 1) // goes from 0 degrees to 119 degrees
It's a small difference, but important.
eh... didn't saw that. thx AWOL
How would I write the 6 hour delay? 21600000?
And about the servo that keeps running...any idea of making it stop between "cycles"?
thx for spending (losing) some time here :))
John
How would I write the 6 hour delay?
1000UL * 60UL * 60 UL * 6 UL
Let the compiler do the legwork.
Ok thanks.
You can shut off pulses to the servo, just give it time to settle into the new position. Although if it is doing a lot of hunting, you may find that you have some electrical noise that needs to be taken care of, or the noise could cause the servos to move out of position during the 6 hour wait.
detach(servoPin) is the command to use.