
{"id":664,"date":"2017-02-14T11:32:13","date_gmt":"2017-02-14T11:32:13","guid":{"rendered":"http:\/\/dyor.roboticafacil.es\/?p=664"},"modified":"2018-04-20T12:22:01","modified_gmt":"2018-04-20T12:22:01","slug":"servo","status":"publish","type":"post","link":"https:\/\/dyor.webs.upv.es\/en\/servo\/","title":{"rendered":"Servo"},"content":{"rendered":"<p>Learn how to use a Servo. DYOR robots use <a href=\"https:\/\/roboticafacil.es\/producto\/servo-sg90\/\">SG90<\/a> or <a href=\"https:\/\/roboticafacil.es\/producto\/micro-servo-ts90m\/\">TS90M<\/a> servos to control movement of their grips or legs. Here we explain the working principle, connection diagrams and programming examples with <a href=\"https:\/\/dyor.webs.upv.es\/facilino-info\/\">Facilino<\/a> and Arduino and ESP processors.<\/p>\n<p class=\"wb-stl-heading3\"><!--more--><\/p>\n<h3 class=\"wb-stl-heading3\">How does a Servo work?<\/h3>\n<p>A servo is a direct continuous (DC) motor with an electronic board that allows you to control the position of the rotating axis with a pulse-position modulated signal (PPM). Most of the servos use a standard signal of 20ms period, whose minimum position can be set with a pulse width of 0.5ms, its maximum position with a pulse width of 2.5ms and its intermediate position with a pulse width of 1.5ms.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-609 aligncenter\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/c7d5c725d2774bd3e629ffbe497d1318_540x190.png\" alt=\"\" width=\"528\" height=\"190\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/c7d5c725d2774bd3e629ffbe497d1318_540x190.png 528w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/c7d5c725d2774bd3e629ffbe497d1318_540x190-300x108.png 300w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/p>\n<p>PPM specifications come from radio control (RC) systems, for this reason, electronic speed control (ESC) board used for controlling the speed of brushless motors (typically used in drones) are also controlled with the same signal (with some additional protocols). Actually, we can see PPM as a particular case of pulse width modulation (PWM) with a frequency of 50Hz to control the position. The position of the servo motor is done in closed-loop, meaning that it measures the actual angle of the shaft with a rotational potentiometer and depending on the difference (error) of this angle and the actual reference, a current is injected onto the motor (to one direction or the opposite). There&#8217;s a mechanical limitation which prevents the motor to rotate further, typically the maximum angle range is 180\u00ba. There exists models with different ranges, so it is convenient to google for specification on each case.<\/p>\n<h3 class=\"wb-stl-heading3\">Servo connection<\/h3>\n<p>Servos use a 3 pin connector. The cable colours and pinout depends on the manufacturer, although almost all are based on Hitachi connector and therefore they are compatible. This is the kind of connectors used also in many expansion boards, and particularly, Arduino Nano expansion board in DYOR robot. Fortunately, if we reverse the polarity of the connector, neither the Servo or Arduino will be damaged.<\/p>\n<p class=\"wb-stl-normal\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-611 aligncenter\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/c91b9be6b8f624c62b2bdc041a940c31_210x136.png\" alt=\"\" width=\"210\" height=\"136\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/c91b9be6b8f624c62b2bdc041a940c31_210x136.png 210w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/c91b9be6b8f624c62b2bdc041a940c31_210x136-75x50.png 75w\" sizes=\"auto, (max-width: 210px) 100vw, 210px\" \/><\/p>\n<h3 class=\"wb-stl-normal\">Servo control<\/h3>\n<p>In order to connect a Servo to Arduino expansion board, we can connected to any pin, while if we use ESP board it is preferable that they are connected to PWM pins.<\/p>\n<p class=\"wb-stl-normal\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-465 aligncenter\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/02e03d655c462badd7f1ecd7d81b9bcf_420x470.png\" alt=\"\" width=\"420\" height=\"466\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/02e03d655c462badd7f1ecd7d81b9bcf_420x470.png 420w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/02e03d655c462badd7f1ecd7d81b9bcf_420x470-270x300.png 270w\" sizes=\"auto, (max-width: 420px) 100vw, 420px\" \/><\/p>\n<p style=\"text-align: left;\">Here you can download Fritzing diagram:<\/p>\n<p class=\"wb-stl-normal\" style=\"text-align: center;\"><div class=\"\"><a href=\"https:\/\/dyor.webs.upv.es\/fritzing\/diagramas\/servo.fzz\" target=\"_self\" class=\"emd_dl_purple_light\" download>Fritzing Servo<\/a><\/div>    <style>            \r\n    .emd_dl_purple_light {\r\n        -moz-box-shadow:inset 0px 1px 0px 0px #e6cafc;\r\n        -webkit-box-shadow:inset 0px 1px 0px 0px #e6cafc;\r\n        box-shadow:inset 0px 1px 0px 0px #e6cafc;\r\n        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #c579ff), color-stop(1, #a341ee) );\r\n        background:-moz-linear-gradient( center top, #c579ff 5%, #a341ee 100% );\r\n        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#c579ff', endColorstr='#a341ee');\r\n        background-color:#c579ff;\r\n        -webkit-border-top-left-radius:0px;\r\n        -moz-border-radius-topleft:0px;\r\n        border-top-left-radius:0px;\r\n        -webkit-border-top-right-radius:0px;\r\n        -moz-border-radius-topright:0px;\r\n        border-top-right-radius:0px;\r\n        -webkit-border-bottom-right-radius:0px;\r\n        -moz-border-radius-bottomright:0px;\r\n        border-bottom-right-radius:0px;\r\n        -webkit-border-bottom-left-radius:0px;\r\n        -moz-border-radius-bottomleft:0px;\r\n        border-bottom-left-radius:0px;\r\n        text-indent:0;\r\n        border:1px solid #a946f5;\r\n        display:inline-block;\r\n        color:#ffffff !important;\r\n        font-family:Georgia;\r\n        font-size:15px;\r\n        font-weight:bold;\r\n        font-style:normal;\r\n        height:41px;\r\n        line-height:41px;\r\n        width:250px;\r\n        text-decoration:none;\r\n        text-align:center;\r\n        text-shadow:1px 1px 0px #8628ce;\r\n    }\r\n    .emd_dl_purple_light:hover {\r\n        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #a341ee), color-stop(1, #c579ff) );\r\n        background:-moz-linear-gradient( center top, #a341ee 5%, #c579ff 100% );\r\n        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#a341ee', endColorstr='#c579ff');\r\n        background-color:#a341ee;\r\n    }.emd_dl_purple_light:active {\r\n        position:relative;\r\n        top:1px;\r\n    }<\/style><\/p>\n<p class=\"wb-stl-normal\">A servo can be controlled by indicating its position in degrees, a value between 0\u00ba and 180\u00ba. The position of 90\u00ba is the intermediate position. In this example, we are generating and positioning the servo, connected to pin 3, on alternate positions (45\u00ba and 135\u00ba) every 2 sec.<\/p>\n<p class=\"wb-stl-normal\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-464 aligncenter\" src=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/01fc7b94bb62a6b44ec25377dcc92d2d_fancybox.png\" alt=\"\" width=\"405\" height=\"441\" srcset=\"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/01fc7b94bb62a6b44ec25377dcc92d2d_fancybox.png 405w, https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/01fc7b94bb62a6b44ec25377dcc92d2d_fancybox-276x300.png 276w\" sizes=\"auto, (max-width: 405px) 100vw, 405px\" \/><\/p>\n<p>It is important to remark that, since the signal period of a servo is 20ms, the minimum time between two consecutive Servo instructions should be greater than 20ms. Therefore, we should always guarantee that this time has elapsed by introducing delays or controlling the periodicity of the code, otherwise it won&#8217;t work. From a mechanical point of view, we should also consider that servos have some &#8220;slow&#8221; dynamics, which means that we should not require to apply commands which require rotational speed over their specifications (i.e.: between 500\u00ba\/sec and 600\u00ba\/sec).<\/p>\n<p style=\"text-align: left;\">Here you can download Facilino code for the previous example:<\/p>\n<p class=\"wb-stl-normal\" style=\"text-align: center;\"><div class=\"\"><a href=\"https:\/\/dyor.webs.upv.es\/facilino\/blockly\/code\/servo.bly\" target=\"_self\" class=\"emd_dl_red_darker\" download>Facilino Servo<\/a><\/div>    <style>            \r\n    .emd_dl_red_darker {\r\n        -moz-box-shadow:inset 0px 1px 0px 0px #f5978e;\r\n        -webkit-box-shadow:inset 0px 1px 0px 0px #f5978e;\r\n        box-shadow:inset 0px 1px 0px 0px #f5978e;\r\n        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f24537), color-stop(1, #c62d1f) );\r\n        background:-moz-linear-gradient( center top, #f24537 5%, #c62d1f 100% );\r\n        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f24537', endColorstr='#c62d1f');\r\n        background-color:#f24537;\r\n        -webkit-border-top-left-radius:0px;\r\n        -moz-border-radius-topleft:0px;\r\n        border-top-left-radius:0px;\r\n        -webkit-border-top-right-radius:0px;\r\n        -moz-border-radius-topright:0px;\r\n        border-top-right-radius:0px;\r\n        -webkit-border-bottom-right-radius:0px;\r\n        -moz-border-radius-bottomright:0px;\r\n        border-bottom-right-radius:0px;\r\n        -webkit-border-bottom-left-radius:0px;\r\n        -moz-border-radius-bottomleft:0px;\r\n        border-bottom-left-radius:0px;\r\n        text-indent:0;\r\n        border:1px solid #d02718;\r\n        display:inline-block;\r\n        color:#ffffff !important;\r\n        font-family:Georgia;\r\n        font-size:15px;\r\n        font-weight:bold;\r\n        font-style:normal;\r\n        height:41px;\r\n        line-height:41px;\r\n        width:250px;\r\n        text-decoration:none;\r\n        text-align:center;\r\n        text-shadow:1px 1px 0px #810e05;\r\n    }\r\n    .emd_dl_red_darker:hover {\r\n        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #c62d1f), color-stop(1, #f24537) );\r\n        background:-moz-linear-gradient( center top, #c62d1f 5%, #f24537 100% );\r\n        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#c62d1f', endColorstr='#f24537');\r\n        background-color:#c62d1f;\r\n    }.emd_dl_red_darker:active {\r\n        position:relative;\r\n        top:1px;\r\n    }<\/style><\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Sorry, this entry is only available in Espa\u00f1ol.<\/p>\n","protected":false},"author":1,"featured_media":646,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[71,97],"tags":[15,14,45,37,27,25],"class_list":["post-664","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-facilino-tutorial","tag-arduino","tag-dyor","tag-electronica","tag-facilino","tag-robot","tag-servo"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/e795ebc63a1f0bfee495303b5de29855_gallery.jpg","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":666,"url":"https:\/\/dyor.webs.upv.es\/en\/servo-360o\/","url_meta":{"origin":664,"position":0},"title":"360\u00ba Servo  (continuous rotation)","author":"soporte","date":"Tuesday February 14th, 2017","format":false,"excerpt":"Learn how to use a 360\u00ba servo (continuous rotation). Classic DYOR robot uses FS90R servos to control the wheel movement. Working principle, connection diagram and programming example with Facilino y Arduino. What is a 360\u00ba Servo? From the control point of view a 360\u00ba servo is different from a standard\u2026","rel":"","context":"In &quot;Arduino&quot;","block_context":{"text":"Arduino","link":"https:\/\/dyor.webs.upv.es\/en\/category\/electronica\/arduino\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/02\/facilino_servo360.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":5509,"url":"https:\/\/dyor.webs.upv.es\/en\/dyor-pandabot\/","url_meta":{"origin":664,"position":1},"title":"DYOR PandaBot","author":"Santi.RS","date":"Thursday May 27th, 2021","format":false,"excerpt":"Sorry, this entry is only available in Espa\u00f1ol.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/dyor.webs.upv.es\/en\/category\/blog\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2021\/05\/IMG_20210525_151001.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2021\/05\/IMG_20210525_151001.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2021\/05\/IMG_20210525_151001.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2021\/05\/IMG_20210525_151001.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2021\/05\/IMG_20210525_151001.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2021\/05\/IMG_20210525_151001.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":4411,"url":"https:\/\/dyor.webs.upv.es\/en\/dyor-guarda-patrulla\/","url_meta":{"origin":664,"position":2},"title":"DYOR Guarda patrulla","author":"Joatalla","date":"Wednesday May 15th, 2019","format":false,"excerpt":"Sorry, this entry is only available in Espa\u00f1ol.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/dyor.webs.upv.es\/en\/category\/blog\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2019\/05\/Robot-DYOR-frontal.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2019\/05\/Robot-DYOR-frontal.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2019\/05\/Robot-DYOR-frontal.jpeg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2019\/05\/Robot-DYOR-frontal.jpeg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2019\/05\/Robot-DYOR-frontal.jpeg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2019\/05\/Robot-DYOR-frontal.jpeg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":8152,"url":"https:\/\/dyor.webs.upv.es\/en\/dyor_tjs-cholo\/","url_meta":{"origin":664,"position":3},"title":"DYOR_TJ&#8217;s Cholo","author":"equihuaj","date":"Tuesday April 29th, 2025","format":false,"excerpt":"Description Description \u00a0","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/dyor.webs.upv.es\/en\/category\/blog\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2025\/04\/20250313_081716-scaled.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2025\/04\/20250313_081716-scaled.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2025\/04\/20250313_081716-scaled.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2025\/04\/20250313_081716-scaled.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2025\/04\/20250313_081716-scaled.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":3805,"url":"https:\/\/dyor.webs.upv.es\/en\/dyor-viseris\/","url_meta":{"origin":664,"position":4},"title":"DYOR Viseris","author":"Emilio","date":"Monday May 14th, 2018","format":false,"excerpt":"Sorry, this entry is only available in Espa\u00f1ol.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/dyor.webs.upv.es\/en\/category\/blog\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/viseris.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/viseris.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/viseris.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/viseris.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/viseris.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2018\/05\/viseris.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":2174,"url":"https:\/\/dyor.webs.upv.es\/en\/ensamblaje-dyor-footbot\/","url_meta":{"origin":664,"position":5},"title":"Assembly of DYOR FootBot","author":"soporte","date":"Sunday July  9th, 2017","format":false,"excerpt":"In this entry, we show the assembly of DYOR FootBot\u00a0with TinkerCAD and make with laser cutting: Componentes: Placa Arduino Nano I\/O + Arduino Nano v3 (rojo) Powerbank (azul oscuro) Bluetooth SPP-C o HC-06 (\u00e1mbar) Matriz de LEDs 8x8 max7219 (verde) Ultrasonido HC-SR04 (azul) Zumbador de sonido (negro) Servos FS90R, SG90,\u2026","rel":"","context":"In &quot;corte_laser&quot;","block_context":{"text":"corte_laser","link":"https:\/\/dyor.webs.upv.es\/en\/category\/fabricacion\/corte_laser\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/07\/dyor_football.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/07\/dyor_football.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/dyor.webs.upv.es\/wp-content\/uploads\/2017\/07\/dyor_football.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/posts\/664","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/comments?post=664"}],"version-history":[{"count":0,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/posts\/664\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/media\/646"}],"wp:attachment":[{"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/media?parent=664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/categories?post=664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dyor.webs.upv.es\/en\/wp-json\/wp\/v2\/tags?post=664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}