<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Servo speed]]></title><description><![CDATA[<p dir="auto">Hi guys</p>
<p dir="auto">I am in the process of automating my central heating system (network gas boiler for heaters and tap water)</p>
<p dir="auto">A part of this project is to use a RC servo to control the thermostat knob</p>
<p dir="auto">Rotation of the knob has to be done much slower than the average servo speed</p>
<p dir="auto">Using delay() in sketches in order to slow down servo travel is a non-sense</p>
<p dir="auto">I tried VarSpeedServo library :  but servo movement wasn't neat and it looks like it's using delay()...</p>
<p dir="auto">So i wrote that little bit of sketch:</p>
<pre><code>#include &lt;Servo.h&gt;
Servo myservo;  // create servo object to control a servo
#define servoMin 10
#define servoMax 170
int servoTarget = 90;               // incoming serial data - servo target position
int servoPos    = 90;               // actual servo position
unsigned long servoDelay = 1000;    // time delay between 2 servo position increments
unsigned long servoPrevMillis;

void setup() {
  myservo.attach(9);    // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);   // opens serial port, sets data rate to 9600 bps
  Serial.print("Servo at ");
  Serial.println(servoTarget);
  myservo.write(servoTarget);
}

void loop() {
  if (Serial.available() &gt; 0)  {
    servoTarget = Serial.parseInt();
    Serial.print("I received: ");
    Serial.println(servoTarget);
  }
  if ( (servoTarget != servoPos)
       &amp;&amp; (servoTarget &lt; servoMax) &amp;&amp; (servoTarget &gt; servoMin)
       &amp;&amp; ( (millis() - servoPrevMillis) &gt;= servoDelay) ) {
    if ( servoTarget &gt; servoPos )
      servoPos++;
    else
      servoPos--;
    myservo.write(servoPos);
    delay(10);                     // wait for the servo to get there
    Serial.println(servoPos);
    servoPrevMillis = millis();
  }
}
</code></pre>
<p dir="auto">As i am quite happy with the result i though i would share it!</p>
]]></description><link>https://forum.mysensors.org/topic/9000/servo-speed</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 05:26:12 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/9000.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Feb 2018 12:04:49 GMT</pubDate><ttl>60</ttl></channel></rss>