{"id":4603,"date":"2022-12-05T19:37:31","date_gmt":"2022-12-05T19:37:31","guid":{"rendered":"https:\/\/rodmilstead.com\/pt\/?page_id=4603"},"modified":"2026-01-30T04:49:12","modified_gmt":"2026-01-30T04:49:12","slug":"2022-arduino-standard-servo-input","status":"publish","type":"page","link":"https:\/\/rodmilstead.com\/pt\/2022-arduino-standard-servo-input\/","title":{"rendered":"Arduino Standard Servo &#038; Input"},"content":{"rendered":"<p>This page includes the Arduino program and circuit for ONE servo controlled by a button\/switch.\u00a0 It is ready to run.<\/p>\n<p>You can copy\/paste the code into the Arduino program.\u00a0 There is a circuit diagram below the code.<\/p>\n<p>Build the circuit in Tinkercad and copy\/paste the program to make it run.<\/p>\n<p><strong>After you are done, move on to <a href=\"https:\/\/rodmilstead.com\/pt\/arduino-two-servos-two-buttons\/\" target=\"_blank\" rel=\"noopener\">Part 2: Two servos, Two Buttons<\/a><\/strong><\/p>\n<pre>#include &lt;Servo.h&gt;\r\nint button =2; \/\/assignments button\/switch to pin 2\r\nServo servo1;\/\/ assigns the variable servo1 to the servo\r\n\r\nvoid setup()\r\n{\r\npinMode (button, INPUT);\r\nservo1.attach (3);\r\nSerial.begin (9600);\r\n}\r\n\r\nvoid loop()\r\n{\r\nif (digitalRead (button) == HIGH)\/\/this is what happens when the button is pressed\r\n\r\n{\r\nservo1.write(0);\/\/servo moves\r\ndelay(1000);\/\/waits one second\r\nSerial.println(\"Button pressed\");\/\/sends a text message to serial monitor\r\ndelay (2000);\/\/waits two seconds\r\nservo1.write (180);\/\/servo moves\r\ndelay (1000);\/\/waits one second\r\n}\r\nelse\/\/this is what happens when the button is NOT pressed\r\n{\r\nservo1.write(0);\/\/servo resets to ZERO\r\nSerial.println(\"Button NOT pressed\");\/\/sends a text message to serial monitor\r\n}\r\n}<a href=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-05-at-11.37.59-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-4608\" src=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-05-at-11.37.59-AM-1024x705.png\" alt=\"\" width=\"660\" height=\"454\" srcset=\"https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-05-at-11.37.59-AM-1024x705.png 1024w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-05-at-11.37.59-AM-300x206.png 300w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-05-at-11.37.59-AM-768x528.png 768w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-05-at-11.37.59-AM-1536x1057.png 1536w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-05-at-11.37.59-AM.png 1930w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/a><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This page includes the Arduino program and circuit for ONE servo controlled by a button\/switch.\u00a0 It is ready to run. You can copy\/paste the code into the Arduino program.\u00a0 There is a circuit diagram below the code. Build the circuit in Tinkercad and copy\/paste the program to make it run. After you are done, move &hellip; <a href=\"https:\/\/rodmilstead.com\/pt\/2022-arduino-standard-servo-input\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Arduino Standard Servo &#038; Input<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-4603","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages\/4603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/comments?post=4603"}],"version-history":[{"count":13,"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages\/4603\/revisions"}],"predecessor-version":[{"id":4607,"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages\/4603\/revisions\/4607"}],"wp:attachment":[{"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/media?parent=4603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}