user1215: I have an Arduino Uno R3 board and after some time not in use it seems to have corrupted. My code is below, basically I want to rotate a servo 90 degrees every 12 hours but as soon as I plug it in the servo starts rotating non-stop. Have tried multiple delay steps and shortening and lengthening the write but the same effect happens.
#include <Servo.h>

Servo myservo;

void setup {
  myservo.attach(10);
}

void loop() {
  myservo.write(90); 
  delay(3600000);
}


user54930: That was useful. 
I was getting the same rotation thing when I had servos at 90. What I did to stop that was use the detach command. Using the Particle Photon with a continuous servo attached.
bool state = LOW;

Servo servo1;
Servo servo2;// create servo object to control a servo 
                // a maximum of eight servo objects can be created 

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

void setup() 
{ 
  servo1.attach(D0);
  servo2.attach(D1);
  Spark.function("test", testFunction);
  servo1.attach(10);
  servo1.write(90);
  servo2.attach(10);
  servo2.write(90);
} 


void loop() 
{              
    servo2.detach(), servo1.detach();
    delay (25);
    servo2.attach(D0), servo1.attach(D1);
    delay (25);
    servo1.write(0), servo2.write(180);
    delay (1000);
    servo2.write(180), servo1.write(0);
    delay (1000);
    //I did this to make the servo not move when it is at 90.
    servo2.detach(), servo1.detach(); 
    delay (25);
    servo1.write(90), servo2.write(90);
    delay (1000);
    //end
    //You must attach the servos again to make them move again.
    servo2.attach(D0), servo1.attach(D1);
    delay (25);
    //end
    servo1.write(180), servo2.write(0);
    delay (1000);
    servo2.write(180), servo1.write(100);
    delay (1000);

}

int testFunction(String args) {

    return 200; // This is checked in the web app controller for validation
}


user84: I suppose you are using a continuous servo otherwise you won't be able to make it turn 90° more than twice (a normal servo has a varying angle of only 180°).
Now if you are using a continuous servo, you have to be aware that the value you pass to myservo.write() does not represent an angle anymore!
With a continuous servo, the value passed to myservo.write() now means a speed of rotation where, but the rnage of acceptable values is the same as for a normal servo, i.e. [0; 180]:

0 means max speed clockwise
90 means no motion
180 means max speed counter-clockwise

Now if you want to turn the servo exactly 90°, then you must know the max speed of the servo, and from that, compute the time during which you must let it turn:
// Start turning clockwise
myservo.write(0);
// Go on turning for the right duration
delay(TURN_TIME);
// Stop turning
myservo.write(90);

The problem here is to compute TURN_TIME. For this, you must check the datasheet of your servo.
On my own servo, a Feetech Micro 1.3kg Continuous Rotation Servo FS90R, the max speed is:

0.12s/60° when powered with 4.8V
0.10s/60° when powered with 6V

However, with the Arduino UNO, the supplied voltage should be exactly 5V, neither 4.8V, nor 6V.
If we take a linear approximation, then we can apply the following formula to find out the speed T (in s/60°):
T = (0.12 - 0.10) * (V - 4.8) / (4.8 - 6.0) + 0.12

Hence, for 5V, we can take it for granted that the max speed should be:
T = (0.12 - 0.10) * (5.0 - 4.8) / (4.8 - 6.0) + 0.12 = 0.116667

Since we need 90°, this means we must run the servo at its max speed during:
T' = T * 1.5 = 0.175s

Hence we now have the following program:
#include <Servo.h>

#define TURN_TIME 175

Servo myservo;

void setup {
    myservo.attach(10);
    // Initially the servo must be stopped 
    myservo.write(90);
}

void loop() {
    // Start turning clockwise
    myservo.write(0);
    // Go on turning for the right duration
    delay(TURN_TIME);
    // Stop turning
    myservo.write(90);

    // Wait for 12h
    delay(12 * 3600 * 1000);
}

Of course, you will need some eperiments to find the exact right values; you may also find out that the servo may be sensitive to noise and even when it should not move (value = 90), it does move (not fast, but still it moves).

1215: <p>I have an Arduino Uno R3 board and after some time not in use it seems to have corrupted. My code is below, basically I want to rotate a servo 90 degrees every 12 hours but as soon as I plug it in the servo starts rotating non-stop. Have tried multiple delay steps and shortening and lengthening the write but the same effect happens.</p>

<pre><code>#include &lt;Servo.h&gt;

Servo myservo;

void setup {
  myservo.attach(10);
}

void loop() {
  myservo.write(90); 
  delay(3600000);
}
</code></pre>
 54930: <p>That was useful. 
I was getting the same rotation thing when I had servos at 90. What I did to stop that was use the detach command. Using the Particle Photon with a continuous servo attached.</p>

<pre><code>bool state = LOW;

Servo servo1;
Servo servo2;// create servo object to control a servo 
                // a maximum of eight servo objects can be created 

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

void setup() 
{ 
  servo1.attach(D0);
  servo2.attach(D1);
  Spark.function("test", testFunction);
  servo1.attach(10);
  servo1.write(90);
  servo2.attach(10);
  servo2.write(90);
} 


void loop() 
{              
    servo2.detach(), servo1.detach();
    delay (25);
    servo2.attach(D0), servo1.attach(D1);
    delay (25);
    servo1.write(0), servo2.write(180);
    delay (1000);
    servo2.write(180), servo1.write(0);
    delay (1000);
    //I did this to make the servo not move when it is at 90.
    servo2.detach(), servo1.detach(); 
    delay (25);
    servo1.write(90), servo2.write(90);
    delay (1000);
    //end
    //You must attach the servos again to make them move again.
    servo2.attach(D0), servo1.attach(D1);
    delay (25);
    //end
    servo1.write(180), servo2.write(0);
    delay (1000);
    servo2.write(180), servo1.write(100);
    delay (1000);

}

int testFunction(String args) {

    return 200; // This is checked in the web app controller for validation
}
</code></pre>
 84: <p>I suppose you are using a continuous servo otherwise you won't be able to make it turn 90° more than twice (a normal servo has a varying angle of only 180°).</p>

<p>Now if you are using a continuous servo, you have to be aware that the value you pass to <code>myservo.write()</code> does not represent an angle anymore!</p>

<p>With a continuous servo, the value passed to <code>myservo.write()</code> now means a speed of rotation where, but the rnage of acceptable values is the same as for a normal servo, i.e. <code>[0; 180]</code>:</p>

<ul>
<li><code>0</code> means max speed clockwise</li>
<li><code>90</code> means no motion</li>
<li><code>180</code> means max speed counter-clockwise</li>
</ul>

<p>Now if you want to turn the servo exactly 90°, then you must know the max speed of the servo, and from that, compute the time during which you must let it turn:</p>

<pre><code>// Start turning clockwise
myservo.write(0);
// Go on turning for the right duration
delay(TURN_TIME);
// Stop turning
myservo.write(90);
</code></pre>

<p>The problem here is to compute <code>TURN_TIME</code>. For this, you must check the datasheet of your servo.</p>

<p>On my own servo, a <a href="http://www.feetechrc.com/product/analog-servo/micro-1-3kg-cm-360-degree-continuous-rotation-servo-fs90r/" rel="noreferrer">Feetech Micro 1.3kg Continuous Rotation Servo FS90R</a>, the max speed is:</p>

<ul>
<li>0.12s/60° when powered with 4.8V</li>
<li>0.10s/60° when powered with 6V</li>
</ul>

<p>However, with the Arduino UNO, the supplied voltage should be <strong>exactly 5V, neither 4.8V, nor 6V</strong>.</p>

<p>If we take a linear approximation, then we can apply the following formula to find out the speed <code>T</code> (in <strong>s/60°</strong>):</p>

<pre><code>T = (0.12 - 0.10) * (V - 4.8) / (4.8 - 6.0) + 0.12
</code></pre>

<p>Hence, for 5V, we can take it for granted that the max speed should be:</p>

<pre><code>T = (0.12 - 0.10) * (5.0 - 4.8) / (4.8 - 6.0) + 0.12 = 0.116667
</code></pre>

<p>Since we need 90°, this means we must run the servo at its max speed during:</p>

<pre><code>T' = T * 1.5 = 0.175s
</code></pre>

<p>Hence we now have the following program:</p>

<pre><code>#include &lt;Servo.h&gt;

#define TURN_TIME 175

Servo myservo;

void setup {
    myservo.attach(10);
    // Initially the servo must be stopped 
    myservo.write(90);
}

void loop() {
    // Start turning clockwise
    myservo.write(0);
    // Go on turning for the right duration
    delay(TURN_TIME);
    // Stop turning
    myservo.write(90);

    // Wait for 12h
    delay(12 * 3600 * 1000);
}
</code></pre>

<p>Of course, you will need some eperiments to find the <strong>exact</strong> right values; you may also find out that the servo may be sensitive to noise and even when it should not move (value = <code>90</code>), it does move (not fast, but still it moves).</p>
