{"id":52350,"date":"2026-11-01T10:51:00","date_gmt":"2026-11-01T10:51:00","guid":{"rendered":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/"},"modified":"2026-11-01T10:51:00","modified_gmt":"2026-11-01T10:51:00","slug":"sg90-servo-control","status":"publish","type":"siratek_tutorial","link":"https:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/","title":{"rendered":"Controlling an SG90 Servo"},"content":{"rendered":"<body><p><\/p>\n<h2>What it does<\/h2>\n<p>A hobby servo is a small geared motor with a position sensor and a control circuit inside. You do not tell it to turn; you tell it <strong>where to be<\/strong>, and it drives itself there and holds.<\/p>\n<p>That is the whole idea, and it is the reason a servo is usually the right first moving part. A plain DC motor spins at whatever speed the voltage gives it and has no idea where it is. A servo goes to 90 degrees and stays at 90 degrees, pushing back if something tries to move it.<\/p>\n<p>The SG90 is the small blue one, about nine grams, with a lead of three wires ending in a female header. It rotates through roughly 180 degrees.<\/p>\n<h2>Before you begin<\/h2>\n<h3>Required parts and tools<\/h3>\n<ul>\n<li>An Arduino Uno or compatible board.<\/li>\n<li>One SG90 micro servo. This is Siratek product 2754.<\/li>\n<li>Three male-to-male jumper wires, to go into the servo\u2019s female header.<\/li>\n<li>For anything beyond the first test: a separate 5 V supply, such as four AA cells or a USB power bank with a breakout.<\/li>\n<\/ul>\n<p>The horns and the small screw in the bag are the plastic arms that fit the output shaft. Fit one before testing, so you can see the movement.<\/p>\n<h3>The three wires<\/h3>\n<table>\n<thead>\n<tr>\n<th>Wire colour<\/th>\n<th>What it is<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Brown, sometimes black<\/td>\n<td>Ground<\/td>\n<\/tr>\n<tr>\n<td>Red<\/td>\n<td>Power, 5 V<\/td>\n<\/tr>\n<tr>\n<td>Orange, sometimes yellow or white<\/td>\n<td>Signal<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Brown to <code>GND<\/code>, red to <code>5V<\/code>, orange to a digital pin. The colours on the Siratek part are brown, red and orange, with the signal wire on the outside edge of the connector.<\/p>\n<p>Reversing power on a servo can destroy it immediately, and the connector will happily go on backwards. Check the colours against the table before plugging in.<\/p>\n<h3>Powering it, which is the part most tutorials skip<\/h3>\n<p>An SG90 draws a few tens of milliamps turning freely. <strong>Stalled, or starting a movement under load, it can draw several hundred.<\/strong><\/p>\n<p>The Uno\u2019s <code>5V<\/code> pin cannot supply that. What happens is not a clean failure: the servo starts to move, the supply voltage dips, the ATmega328P browns out and resets, and the board starts again. To the reader it looks like the code is crashing, and no amount of reading the sketch will find it.<\/p>\n<p>So:<\/p>\n<ul>\n<li><strong>One small servo, moving slowly, nothing else connected, on USB power: fine for a first test.<\/strong> That is what the example below is.<\/li>\n<li><strong>Anything real<\/strong> \u2014 two servos, a servo under load, a servo alongside a display or sensors \u2014 needs its own 5 V supply.<\/li>\n<\/ul>\n<p>When you give it one, <strong>join the grounds<\/strong>. The servo\u2019s supply ground and the Uno\u2019s <code>GND<\/code> must be connected, or the signal has no shared reference and the servo twitches at random. This is the single most common fault with separately powered servos, and it looks like a broken servo.<\/p>\n<p>Power from the separate supply goes to the servo\u2019s red wire. The signal still comes from the Arduino. The Arduino\u2019s <code>5V<\/code> pin is not involved at all.<\/p>\n<h3>What the signal actually is<\/h3>\n<p>A servo is not controlled by voltage or by PWM duty cycle in the usual sense. It expects a pulse roughly every 20 milliseconds, and the <strong>width<\/strong> of that pulse sets the position: about 1.0 millisecond for one end of the travel, about 1.5 for the middle, about 2.0 for the other end.<\/p>\n<p>The <code>Servo<\/code> library generates those pulses for you, which is why the sketch below is three lines long. It is worth knowing what is underneath, because it explains two things you will meet: why any digital pin works rather than only the PWM-marked ones, and why the library quietly takes over a hardware timer.<\/p>\n<h2>Pin reference<\/h2>\n<table>\n<thead>\n<tr>\n<th>Wire<\/th>\n<th>Connect to<\/th>\n<th>Purpose<\/th>\n<th>Notes<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Brown<\/td>\n<td>Uno <code>GND<\/code><\/td>\n<td>Ground<\/td>\n<td>And to the separate supply\u2019s ground, if used<\/td>\n<\/tr>\n<tr>\n<td>Red<\/td>\n<td>Uno <code>5V<\/code>, or a separate 5 V supply<\/td>\n<td>Power<\/td>\n<td>Separate supply for anything beyond a first test<\/td>\n<\/tr>\n<tr>\n<td>Orange<\/td>\n<td>Uno <code>D9<\/code><\/td>\n<td>Signal<\/td>\n<td>Any digital pin works<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<figure class=\"siratek-tutorial-figure\"><img decoding=\"async\" src=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/sg90-servo-control-wiring.svg\" alt=\"An SG90 servo with brown to ground, red to a separate 5V supply, orange to pin 9, and the two grounds joined\" loading=\"lazy\"><figcaption>The signal comes from the Arduino; the current comes from the supply. The grounds must be joined.<\/figcaption><\/figure>\n<h2>Wiring steps<\/h2>\n<p>For the first test, on USB power only:<\/p>\n<ol>\n<li>Unplug the USB cable.<\/li>\n<li>Fit a horn to the servo\u2019s output shaft so the movement is visible.<\/li>\n<li>Brown wire to <code>GND<\/code>.<\/li>\n<li>Red wire to <code>5V<\/code>.<\/li>\n<li>Orange wire to <code>D9<\/code>.<\/li>\n<li>Plug the USB cable back in. The servo may twitch once as the pin settles. That is normal.<\/li>\n<\/ol>\n<p>For anything more, replace step 4: red wire to the separate supply\u2019s positive, and run a wire from that supply\u2019s ground to the Uno\u2019s <code>GND<\/code>.<\/p>\n<h2>Software and libraries<\/h2>\n<p><code>Servo<\/code> ships with the Arduino IDE. Nothing to install.<\/p>\n<p>It is worth knowing what it costs you. On an Uno the library uses <strong>Timer1<\/strong>, which is the timer behind <code>analogWrite()<\/code> on <strong>pins 9 and 10<\/strong>. So as soon as a sketch includes <code>Servo.h<\/code> and attaches a servo, those two pins stop working as PWM outputs, whether or not the servo is on either of them.<\/p>\n<p>If an LED on pin 9 or 10 stops dimming the moment you add a servo, this is why, and the fix is to move the LED to pin 3, 5, 6 or 11. <em>Dimming and Speed Control with PWM<\/em> covers which timer drives which pin.<\/p>\n<h2>Minimal working example<\/h2>\n<pre><code>\/\/ Siratek: sweeping an SG90 servo.\n\n#include &lt;Servo.h&gt;\n\nServo arm;\n\nvoid setup() {\n  arm.attach(9);\n}\n\nvoid loop() {\n  arm.write(0);\n  delay(1000);\n\n  arm.write(90);\n  delay(1000);\n\n  arm.write(180);\n  delay(1000);\n\n  arm.write(90);\n  delay(1000);\n}<\/code><\/pre>\n<p><code>write()<\/code> takes an angle in degrees. The servo goes there as fast as it can and holds.<\/p>\n<p>The <code>delay()<\/code> calls are not the servo moving; they are you waiting for it. The library returns immediately and the servo takes its own time, roughly a tenth of a second per sixty degrees on an SG90. Ask for a new position before it has arrived and it simply changes course.<\/p>\n<h3>Moving at a chosen speed<\/h3>\n<p>Because <code>write()<\/code> always moves at full speed, a controlled sweep means stepping the angle yourself.<\/p>\n<pre><code>\/\/ Siratek: a smooth sweep, without blocking the rest of the sketch.\n\n#include &lt;Servo.h&gt;\n\nServo arm;\n\nint angle = 0;\nint step = 1;\nunsigned long lastMove = 0;\n\nconst int moveInterval = 15;  \/\/ milliseconds per degree\n\nvoid setup() {\n  arm.attach(9);\n  arm.write(angle);\n}\n\nvoid loop() {\n  if (millis() - lastMove &gt;= moveInterval) {\n    lastMove = millis();\n\n    angle += step;\n    if (angle &gt;= 180 || angle &lt;= 0) {\n      step = -step;\n    }\n\n    arm.write(angle);\n  }\n\n  \/\/ Other work can happen here. Nothing is blocked.\n}<\/code><\/pre>\n<p>This is the <code>millis()<\/code> pattern from <em>Timing Without delay()<\/em>, applied to movement. Larger <code>moveInterval<\/code> gives a slower sweep.<\/p>\n<h3>Finding the real limits<\/h3>\n<p><code>write(0)<\/code> and <code>write(180)<\/code> are nominal. Real SG90s vary, and asking for an angle past the mechanical stop makes the servo push against it and buzz, drawing stall current the whole time. That is how servos get hot and how gears get stripped.<\/p>\n<pre><code>\/\/ Siratek: find the usable range of your own servo.\n\/\/ Watch and listen. Back off as soon as it buzzes or strains.\n\n#include &lt;Servo.h&gt;\n\nServo arm;\n\nvoid setup() {\n  Serial.begin(9600);\n  arm.attach(9);\n  Serial.println(\"Siratek: type an angle and press Enter.\");\n}\n\nvoid loop() {\n  if (Serial.available() &gt; 0) {\n    int angle = Serial.parseInt();\n    if (angle &gt;= 0 &amp;&amp; angle &lt;= 180) {\n      arm.write(angle);\n      Serial.print(\"moved to \");\n      Serial.println(angle);\n    }\n  }\n}<\/code><\/pre>\n<p>Creep up from 90 towards each end. When the servo buzzes and stops moving, you have found the stop. Note the two numbers and keep your project a few degrees inside them.<\/p>\n<h2>Expected result<\/h2>\n<p>A visible movement to each position, with a short whirr, and then silence. A servo that is holding position and not loaded should be quiet.<\/p>\n<p>Continuous buzzing means it is fighting something: a mechanical stop, a horn pressing against the case, or a demanded angle it cannot reach. Buzzing is not normal and should be investigated rather than ignored.<\/p>\n<h2>Troubleshooting<\/h2>\n<table>\n<thead>\n<tr>\n<th>Symptom<\/th>\n<th>Likely cause<\/th>\n<th>Check or fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Board resets when the servo moves<\/td>\n<td>Current beyond the supply<\/td>\n<td>Separate 5 V supply, grounds joined<\/td>\n<\/tr>\n<tr>\n<td>Twitches at random, never settles<\/td>\n<td>Separate supply, grounds not joined<\/td>\n<td>Join the supply ground to Uno <code>GND<\/code><\/td>\n<\/tr>\n<tr>\n<td>No movement at all<\/td>\n<td>Signal wire on the wrong pin<\/td>\n<td>Orange to the pin named in <code>attach()<\/code><\/td>\n<\/tr>\n<tr>\n<td>No movement, servo warm<\/td>\n<td>Power reversed<\/td>\n<td>Check brown to <code>GND<\/code>, red to 5 V<\/td>\n<\/tr>\n<tr>\n<td>Buzzes continuously<\/td>\n<td>Pushed against a stop<\/td>\n<td>Find the real range; stay inside it<\/td>\n<\/tr>\n<tr>\n<td>Moves but will not reach 0 or 180<\/td>\n<td>Normal part variation<\/td>\n<td>Use the range you measured<\/td>\n<\/tr>\n<tr>\n<td>Jitters slightly while holding<\/td>\n<td>Normal for a cheap servo<\/td>\n<td>Detach when idle if it matters<\/td>\n<\/tr>\n<tr>\n<td>LED on pin 9 or 10 stops dimming<\/td>\n<td><code>Servo<\/code> has taken Timer1<\/td>\n<td>Move the LED to 3, 5, 6 or 11<\/td>\n<\/tr>\n<tr>\n<td>Second servo makes both misbehave<\/td>\n<td>One supply, not enough current<\/td>\n<td>Separate supply sized for both<\/td>\n<\/tr>\n<tr>\n<td>Gets hot after a few minutes<\/td>\n<td>Holding against a load<\/td>\n<td>Reduce the load, or detach between moves<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Next steps<\/h2>\n<ul>\n<li><strong>Easier first:<\/strong> <em>Powering Your Project<\/em>, which is the background to everything above.<\/li>\n<li><strong>Related product:<\/strong> the MG90S, Siratek 2758, the same size with metal gears and more torque.<\/li>\n<li><strong>Next project:<\/strong> drive the angle from a potentiometer, which makes the servo follow a knob.<\/li>\n<\/ul>\n<h2>Sources and attribution<\/h2>\n<p>All text, wiring guidance and code in this tutorial are original Siratek work.<\/p>\n<ul>\n<li>Arduino core documentation for the <code>Servo<\/code> library and its use of Timer1 on the Uno.<\/li>\n<li>The three-wire lead and colour order described here were read from the Siratek product photographs for item 2754.<\/li>\n<\/ul>\n<p>Current draw, pulse widths and the usable angular range vary between individual servos, and are given here as typical values with a procedure for measuring your own. No third-party tutorial text, diagrams, photographs or code has been reproduced here.<\/p>\n<p><\/p>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>A hobby servo is a small geared motor with a position sensor and a control circuit inside. You do not tell it to turn; you tell it where to be, and it drives itself there and holds.<\/p>\n","protected":false},"featured_media":0,"template":"","siratek_tutorial_level":[],"class_list":["post-52350","siratek_tutorial","type-siratek_tutorial","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Controlling an SG90 Servo - siratek<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Controlling an SG90 Servo - siratek\" \/>\n<meta property=\"og:description\" content=\"A hobby servo is a small geared motor with a position sensor and a control circuit inside. You do not tell it to turn; you tell it where to be, and it drives itself there and holds.\" \/>\n<meta property=\"og:url\" content=\"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/\" \/>\n<meta property=\"og:site_name\" content=\"siratek\" \/>\n<meta property=\"og:image\" content=\"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/sg90-servo-control-wiring.svg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/sg90-servo-control\\\/\",\"url\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/sg90-servo-control\\\/\",\"name\":\"Controlling an SG90 Servo - siratek\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/sg90-servo-control\\\/#primaryimage\"},\"image\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/sg90-servo-control\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/sg90-servo-control-wiring.svg\",\"datePublished\":\"2026-11-01T10:51:00+00:00\",\"breadcrumb\":{\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/sg90-servo-control\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/sg90-servo-control\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/sg90-servo-control\\\/#primaryimage\",\"url\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/sg90-servo-control-wiring.svg\",\"contentUrl\":\"https:\\\/\\\/siratek.net\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/sg90-servo-control-wiring.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/sg90-servo-control\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/siratek.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https:\\\/\\\/siratek.net\\\/index.php\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Controlling an SG90 Servo\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/siratek.net\\\/#website\",\"url\":\"https:\\\/\\\/siratek.net\\\/\",\"name\":\"siratek\",\"description\":\"Your Best Electronic Retail Shop\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/siratek.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Controlling an SG90 Servo - siratek","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/","og_locale":"en_US","og_type":"article","og_title":"Controlling an SG90 Servo - siratek","og_description":"A hobby servo is a small geared motor with a position sensor and a control circuit inside. You do not tell it to turn; you tell it where to be, and it drives itself there and holds.","og_url":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/","og_site_name":"siratek","og_image":[{"url":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/sg90-servo-control-wiring.svg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/","url":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/","name":"Controlling an SG90 Servo - siratek","isPartOf":{"@id":"https:\/\/siratek.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/#primaryimage"},"image":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/#primaryimage"},"thumbnailUrl":"http:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/sg90-servo-control-wiring.svg","datePublished":"2026-11-01T10:51:00+00:00","breadcrumb":{"@id":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/#primaryimage","url":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/sg90-servo-control-wiring.svg","contentUrl":"https:\/\/siratek.net\/wp-content\/uploads\/2026\/11\/sg90-servo-control-wiring.svg"},{"@type":"BreadcrumbList","@id":"http:\/\/siratek.net\/index.php\/tutorials\/sg90-servo-control\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/siratek.net\/"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https:\/\/siratek.net\/index.php\/tutorials\/"},{"@type":"ListItem","position":3,"name":"Controlling an SG90 Servo"}]},{"@type":"WebSite","@id":"https:\/\/siratek.net\/#website","url":"https:\/\/siratek.net\/","name":"siratek","description":"Your Best Electronic Retail Shop","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/siratek.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial"}],"about":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/types\/siratek_tutorial"}],"version-history":[{"count":0,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial\/52350\/revisions"}],"wp:attachment":[{"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/media?parent=52350"}],"wp:term":[{"taxonomy":"siratek_tutorial_level","embeddable":true,"href":"https:\/\/siratek.net\/index.php\/wp-json\/wp\/v2\/siratek_tutorial_level?post=52350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}