{"id":944,"date":"2022-01-05T12:10:40","date_gmt":"2022-01-05T06:40:40","guid":{"rendered":"https:\/\/botuniverse.in\/?p=944"},"modified":"2022-01-15T17:33:30","modified_gmt":"2022-01-15T12:03:30","slug":"how-to-use-a-sg-90-servo","status":"publish","type":"post","link":"https:\/\/botuniverse.in\/index.php\/2022\/01\/05\/how-to-use-a-sg-90-servo\/","title":{"rendered":"How to use a SG-90 \/ SG90 Servo with an Arduino"},"content":{"rendered":"\n<h2>Basic Info About the SG-90 \/ SG90 Servo<\/h2>\n\n\n\n<p>A standard servo typically consists of a small electric motor, a potentiometer,<br>controller, and gears. The position of the output shaft is constantly<br>measured by the internal potentiometer and compared with the position set by the Arduino.<\/p>\n\n\n\n<p>If there is any difference between the two values, the motor is moved so that both the values are balanced. They also happen to be high torque motors. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2>The Circuit for SG-90 \/ SG90 Servo motor with an Arduino<\/h2>\n\n\n\n<p>Connect the 5V pin of the servo to the 5V pin of the Arduino Uno. This will act as the power supply for the module.<\/p>\n\n\n\n<p>Connect the GND pin of the serve to the GND pin of the Arduino Uno.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/www.electrovigyan.com\/wp-content\/uploads\/2021\/01\/servo-n-1200x628.jpg\" alt=\"Interface SG90 servo motor with Arduino - ElectroVigyan\"\/><\/figure>\n\n\n\n<p>Connect the Signal (SIG) Pin of the module to digital pin 5 of the Arduino Uno. <\/p>\n\n\n\n<h2>PWM Pins on the Arduino<\/h2>\n\n\n\n<p>This pin is a PWM pin. &nbsp;A PWN pin is marked by &#8220;~&#8221;. A PWM pin is a digital pin that is capable of pulse width modulation. Basically, you have a higher degree of control if you use a PWM pin over other pins. Digital Pins 3,5,6,9,10,11 are PWM pins. If your 5th pin is not free make sure you attach the SG 90 servo in any of the pins listed above otherwise it might lead to malfunctioning.<\/p>\n\n\n\n<p>All the signals that we send to the servo in order to control it will be through the pin 5 of the Arduino.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2>Code for SG-90 \/ SG90 Servo Motor with an Arduino<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;Servo.h&gt; \/\/Imports the library Servo\n\nServo servo; \/\/Defines the object Servo of type(class) Servo\nint angle = 10; \/\/ Defines an integer\n\nvoid setup() {\n  servo.attach(5); \/\/ States that the servo is attached to pin 5\n  servo.write(angle); \/\/Sets the servo angle to 10degrees\n}\n\n\nvoid loop() { \n\n\n\/\/ The following for loop runs till the servo is turned till 180degrees\n  for(angle = 10; angle &lt; 180; angle++) {                                  \n    servo.write(angle);               \n    delay(15);                   \n  } \n\n\/\/The following for loop goes back till servo is turned till 10degrees\n  for(angle = 180; angle &gt; 10; angle--){                                \n    servo.write(angle);           \n    delay(15);       \n  } \n}<\/code><\/pre>\n\n\n\n<p>If your SG90 servo is not working, you might try to power it with an external power supply as the Arduino Uno might not be able to serve that current requirement. Usually connecting one servo is not a problem, but if it is you can try fixing it using the method discussed above.<\/p>\n\n\n\n<p>We hope we have helped you in knowing more about the SG90 servo but still if you may need any help regarding the SG90 servo, you can mail us at ideas@botuniverse.in <\/p>\n\n\n\n<p>To order the SG90 servo now, <a href=\"https:\/\/botuniverse.in\/index.php\/product\/sg-90-servo-motor\/\" data-type=\"URL\" data-id=\"https:\/\/botuniverse.in\/index.php\/product\/sg-90-servo-motor\/\" target=\"_blank\" rel=\"noreferrer noopener\">click here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Basic Info About the SG-90 \/ SG90 Servo A standard servo typically consists of a small electric motor, a potentiometer,controller, and gears. The position of the output shaft is constantlymeasured by the internal potentiometer and compared with the position set by the Arduino. If there is any difference between the two values, the motor is moved so that both the&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[36,37,72,69,68,66,71,67,70],"_links":{"self":[{"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/posts\/944"}],"collection":[{"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/comments?post=944"}],"version-history":[{"count":11,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/posts\/944\/revisions"}],"predecessor-version":[{"id":970,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/posts\/944\/revisions\/970"}],"wp:attachment":[{"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/media?parent=944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/categories?post=944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/botuniverse.in\/index.php\/wp-json\/wp\/v2\/tags?post=944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}