<?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[Multiple Servos]]></title><description><![CDATA[<p dir="auto">Hi there,<br />
Could someone help me with a sketch for running multiple servos.<br />
Like in the example for the Relay Actuator<br />
#define SERVO_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)<br />
#define NUMBER_OF_SERVOS 1 // Total number of attached relays</p>
<p dir="auto">My current sketch is:</p>
<pre><code>
// Debug
#define MY_DEBUG
// Partea cu Conexiunea la net
#define MY_GATEWAY_ENC28J60
#define MY_IP_ADDRESS 192,168,1,66
#define MY_PORT 5003
#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
#include &lt;UIPEthernet.h&gt;
// Sfarsit parte

#include &lt;SPI.h&gt;
#include &lt;MySensors.h&gt;
#include &lt;Servo.h&gt;

#define SERVO_DIGITAL_OUT_PIN 4
#define SERVO_MIN 0 // Fine tune your servos min. 0-180
#define SERVO_MAX 180  // Fine tune your servos max. 0-180
#define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo
#define CHILD_ID 10   // Id of the sensor child

MyMessage msg(CHILD_ID, V_DIMMER);
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created Sensor gw(9,10);
unsigned long timeOfLastChange = 0;
bool attachedServo = false;
bool state;

void setup()
{
  // Request last servo state at startup
  request(CHILD_ID, V_DIMMER);
}

void presentation()  {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Servo", "1.0");

  // Register all sensors to gw (they will be created as child devices)
  present(CHILD_ID, S_DIMMER);
}

void loop()
{
  if (attachedServo &amp;&amp; millis() - timeOfLastChange &gt; DETACH_DELAY) {
     myservo.detach();
     attachedServo = false;
  }
}

void receive(const MyMessage &amp;message) {
  myservo.attach(SERVO_DIGITAL_OUT_PIN);
  attachedServo = true;
  if (message.type==V_DIMMER) { // This could be M_ACK_VARIABLE or M_SET_VARIABLE
     int val = message.getInt();
     myservo.write(SERVO_MAX + (SERVO_MIN-SERVO_MAX)/100 * 1.8 * val); // sets the servo position 0-180
     // Write some debug info
     Serial.print("Servo changed. new state: ");
     Serial.println(val);
     }
   timeOfLastChange = millis();
}
</code></pre>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.mysensors.org/topic/6931/multiple-servos</link><generator>RSS for Node</generator><lastBuildDate>Sun, 07 Jun 2026 17:05:52 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/6931.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 31 May 2017 05:09:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Multiple Servos on Wed, 31 May 2017 22:44:09 GMT]]></title><description><![CDATA[<p dir="auto">Found this on <a href="http://arduino.cc" rel="nofollow ugc">arduino.cc</a> forum.<br />
I think there should be a way for creating different servo objects for each servo but I don't know how to do that.</p>
<p dir="auto">Any sugestion from <a class="plugin-mentions-user plugin-mentions-a" href="/user/mfalkvidd" aria-label="Profile: mfalkvidd">@<bdi>mfalkvidd</bdi></a> ?</p>
<pre><code>#include &lt;Servo.h&gt;

 Servo myservo[6]; 
  
int pinAttch = 0;    // variable to store pin attachment
int servWrite = 0;    // variable to store servo writing

void setup() {
  Serial.begin(9600);
  for(pinAttch = 2; pinAttch &lt; 7; pinAttch++)
    {                                                
    myservo[pinAttch].attach(pinAttch);
    }  
  }

void loop() {

for(servWrite = 2; servWrite &lt; 7; servWrite++)
  {                                                
   
  myservo[servWrite].write(80);
  delay(2000);

  }
exit(0); 

}```</code></pre>
]]></description><link>https://forum.mysensors.org/post/68154</link><guid isPermaLink="true">https://forum.mysensors.org/post/68154</guid><dc:creator><![CDATA[numanx]]></dc:creator><pubDate>Wed, 31 May 2017 22:44:09 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple Servos on Wed, 31 May 2017 22:23:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gohan" aria-label="Profile: gohan">@<bdi>gohan</bdi></a><br />
Debug print when changing the dimmer slider to different values.</p>
<p dir="auto">0;255;3;0;9;Eth: 0;0;3;0;2;<br />
0;255;3;0;9;Eth: 0;0;3;0;2;Get Version<br />
0;255;3;0;9;Eth: 0;1;1;1;3;7<br />
Servo changed. new state: 7<br />
0;255;3;0;9;Eth: 0;0;3;0;18;PING<br />
0;255;3;0;9;Eth: 0;1;1;1;3;21<br />
Servo changed. new state: 21<br />
0;255;3;0;9;Eth: 0;1;1;1;3;36<br />
Servo changed. new state: 36<br />
0;255;3;0;9;Eth: 0;0;3;0;18;PING<br />
0;255;3;0;9;Eth: 0;0;3;0;18;PING</p>
]]></description><link>https://forum.mysensors.org/post/68153</link><guid isPermaLink="true">https://forum.mysensors.org/post/68153</guid><dc:creator><![CDATA[numanx]]></dc:creator><pubDate>Wed, 31 May 2017 22:23:47 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple Servos on Wed, 31 May 2017 22:04:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/numanx" aria-label="Profile: numanx">@<bdi>numanx</bdi></a> start adding some debug prints and see where data is not correct</p>
]]></description><link>https://forum.mysensors.org/post/68152</link><guid isPermaLink="true">https://forum.mysensors.org/post/68152</guid><dc:creator><![CDATA[gohan]]></dc:creator><pubDate>Wed, 31 May 2017 22:04:09 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple Servos on Wed, 31 May 2017 21:39:53 GMT]]></title><description><![CDATA[<p dir="auto">Ok so here is the sketch with the for cycles.<br />
But it still won't work. The servos are presented to the Controller but it won't make any move.<br />
I think the problem is with the void receive.<br />
I don't know how to change</p>
<pre><code>   	digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
</code></pre>
<p dir="auto">for the servo</p>
<pre><code>     myservo.write(SERVO_MAX + (SERVO_MIN-SERVO_MAX)/100 * 1.8 * val); // sets the servo position 0-180
</code></pre>
<pre><code>// Debug
#define MY_DEBUG
// Partea cu Conexiunea la net
#define MY_GATEWAY_ENC28J60
#define MY_IP_ADDRESS 192,168,1,66
#define MY_PORT 5003
#define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
#include &lt;UIPEthernet.h&gt;
// Sfarsit parte

#include &lt;SPI.h&gt;
#include &lt;MySensors.h&gt;
#include &lt;Servo.h&gt;

#define SERVO_1 4 // Arduino Digital I/O pin number for first servo (second on pin+1 etc)
#define NUMBER_OF_SERVOS 2 // Total number of attached servos
#define SERVO_MIN 0 // Fine tune your servos min. 0-180
#define SERVO_MAX 180  // Fine tune your servos max. 0-180
#define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo
//#define CHILD_ID 10   // Id of the sensor child

//MyMessage msg(CHILD_ID, V_DIMMER);
Servo myservo;  // create servo object to control a servo
unsigned long timeOfLastChange = 0;
bool attachedServo = false;
bool state;

void before()
{
    for (int servo=1, pin_S=SERVO_1; servo&lt;=NUMBER_OF_SERVOS; servo++, pin_S++) {
      myservo.attach(pin_S);
    }
}

void setup()
{
  // Request last servo state at startup
    for (int servo=1, pin_S=SERVO_1; servo&lt;=NUMBER_OF_SERVOS; servo++, pin_S++) {
      request(servo, V_DIMMER);
  }
}

void presentation()  {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Servo", "1.0");
    // Register all sensors to gw (they will be created as child devices)
  for (int servo=1, pin_S=SERVO_1; servo&lt;=NUMBER_OF_SERVOS; servo++, pin_S++) {
      present(servo, S_DIMMER);
  }
}

void loop()
{
  if (attachedServo &amp;&amp; millis() - timeOfLastChange &gt; DETACH_DELAY) {
     myservo.detach();
     attachedServo = false;
  }
}

void receive(const MyMessage &amp;message) {
  attachedServo = true;
  if (message.type==V_DIMMER) { // This could be M_ACK_VARIABLE or M_SET_VARIABLE
     int val = message.getInt();
     myservo.write(SERVO_MAX + (SERVO_MIN-SERVO_MAX)/100 * 1.8 * val); // sets the servo position 0-180
     // Write some debug info
     Serial.print("Servo changed. new state: ");
     Serial.println(val);
     }
   timeOfLastChange = millis();
}

</code></pre>
]]></description><link>https://forum.mysensors.org/post/68150</link><guid isPermaLink="true">https://forum.mysensors.org/post/68150</guid><dc:creator><![CDATA[numanx]]></dc:creator><pubDate>Wed, 31 May 2017 21:39:53 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple Servos on Wed, 31 May 2017 06:15:00 GMT]]></title><description><![CDATA[<p dir="auto">You stripped a lot of code from the relay sketch, I think you need to put back all the FOR cycles it you want the code handle automatically the number of servos</p>
]]></description><link>https://forum.mysensors.org/post/68082</link><guid isPermaLink="true">https://forum.mysensors.org/post/68082</guid><dc:creator><![CDATA[gohan]]></dc:creator><pubDate>Wed, 31 May 2017 06:15:00 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple Servos on Wed, 31 May 2017 06:09:04 GMT]]></title><description><![CDATA[<p dir="auto">Individually, thanks for your reply!</p>
]]></description><link>https://forum.mysensors.org/post/68081</link><guid isPermaLink="true">https://forum.mysensors.org/post/68081</guid><dc:creator><![CDATA[numanx]]></dc:creator><pubDate>Wed, 31 May 2017 06:09:04 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple Servos on Wed, 31 May 2017 06:08:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/numanx" aria-label="Profile: numanx">@<bdi>numanx</bdi></a> but do you want to control each servo individually or all together at the same time?</p>
]]></description><link>https://forum.mysensors.org/post/68079</link><guid isPermaLink="true">https://forum.mysensors.org/post/68079</guid><dc:creator><![CDATA[gohan]]></dc:creator><pubDate>Wed, 31 May 2017 06:08:31 GMT</pubDate></item></channel></rss>