{"id":203,"date":"2020-05-25T15:29:39","date_gmt":"2020-05-25T15:29:39","guid":{"rendered":"https:\/\/samndave.org.uk\/ourdoc\/?p=203"},"modified":"2025-07-10T16:11:34","modified_gmt":"2025-07-10T16:11:34","slug":"project-rotary-encoder-servo","status":"publish","type":"post","link":"https:\/\/samndave.org.uk\/index.php\/2020\/05\/25\/project-rotary-encoder-servo\/","title":{"rendered":"Project: Rotary Encoder &#038; Servo"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Can we control a servo with a rotary encoder? Can we make it turn in the same direction as we turn the rotary encoder? What could we attach to the servo arm? Perhaps use this to control a crane or fork lift? Can it be attached to some lego to make something interesting?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 1: <\/strong>Set up the rotary encoder. Review <a href=\"https:\/\/samndave.org.uk\/2020\/05\/25\/microbit-rotary-encoder\/\">Micro:bit Rotary Encoder<\/a> and connect up the hardware. Run the test code to make sure the encoder is working.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2: <\/strong>Can you turn this code into a function? Sit in the loop and call a function checkEncoder(), which will report back the direction (if any) it is being turned. Perhaps return 0 for stationary, 1 for turning clockwise and 2 for turning anti-clockwise. Consider returning two values to also report the state of the button.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 4: <\/strong>Connect the servo. Follow <a href=\"https:\/\/samndave.org.uk\/2020\/05\/15\/microbit-sg09-servo\/\">Micro:bit SG09 Servo<\/a> and test the servo. Note, both examples use pin0 so you will have to make adjustments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 5: <\/strong>Can you turn the servo in the same direction as the rotary encoder? You may need to write a function to tell the servo to move by X number of degrees. Try playing with different values for X and different sensitivities to control how fast the encoder turns the servo. Don&#8217;t forget to make sure you do not try to turn the servo beyond it&#8217;s limits.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Can we control a servo with a rotary encoder? Can we make it turn in [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6],"tags":[],"class_list":["post-203","post","type-post","status-publish","format-standard","hentry","category-microbit","category-project"],"_links":{"self":[{"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/posts\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/comments?post=203"}],"version-history":[{"count":1,"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/posts\/203\/revisions"}],"predecessor-version":[{"id":1177,"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/posts\/203\/revisions\/1177"}],"wp:attachment":[{"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/media?parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/categories?post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/samndave.org.uk\/index.php\/wp-json\/wp\/v2\/tags?post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}