{"id":1775,"date":"2015-04-18T14:23:10","date_gmt":"2015-04-18T14:23:10","guid":{"rendered":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1775"},"modified":"2015-04-18T14:38:23","modified_gmt":"2015-04-18T14:38:23","slug":"building-lego-crane-using-arduino","status":"publish","type":"post","link":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/building-lego-crane-using-arduino\/","title":{"rendered":"How to build a Lego Crane using Arduino [Tutorial]"},"content":{"rendered":"\n<!-- Facebook Like Button v1.9.6 BEGIN [http:\/\/blog.bottomlessinc.com] -->\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=http%3A%2F%2Finspiredtoeducate.net%2Finspiredtoeducate%2Fbuilding-lego-crane-using-arduino%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px; height: 30px; align: left; margin: 2px 0px 2px 0px\"><\/iframe>\n<!-- Facebook Like Button END -->\n<p><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/crane1.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1780\" src=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/crane1.jpg\" alt=\"Lego Crane\" width=\"500\" height=\"281\" srcset=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/crane1.jpg 500w, http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/crane1-300x168.jpg 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>I&#8217;m always looking for new ways to play and build with my kids. \u00a0In the Rosario house hold, we enjoy building stuff with Lego&#8217;s. \u00a0 My kids have also enjoyed playing with Lego Wedo and Lego Mindstorm kits at our makerspace. \u00a0 For many families, getting access to a Lego Mindstorm EV3 kit\u00a0that\u00a0costs $350 to $400 can be a challenge. \u00a0 Even the Lego Wedo kits are not inexpensive. \u00a0 Our family already had a pretty nice collection of traditional Lego and Lego technic pieces. \u00a0I started wondering if I could build some pieces that would enable us to combine the world of Lego and Arduino. \u00a0In this blog post, I would like to share some of my experiences of building a fun Lego crane for my kids. \u00a0 I hope to use some of these ideas to engage older students in coding and making at our local makerspace. \u00a0 \u00a0You can see a video of the crane in action here:<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/Mqn19AiLnEU\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>Here&#8217;s some of the materials that you&#8217;ll need to build your own!<\/p>\n<ul>\n<li>Traditional Lego pieces<\/li>\n<li>Lego technic pieces &#8211; These lego pieces are used with Lego Mindstorm\/Wedo kits for constructing robots. \u00a0 They include parts like beams, gears, and connectors to enable pieces to turn and spin. \u00a0You can learn more about Lego technic <a href=\"http:\/\/en.wikipedia.org\/wiki\/Lego_Technic\" target=\"_blank\">from this post.<\/a><\/li>\n<li>1 Continuous rotation servo. \u00a0You can purchase this servo for about $15.00 . Here&#8217;s a link:<a href=\"https:\/\/www.parallax.com\/product\/900-00008\">https:\/\/www.parallax.com\/product\/900-00008<\/a>\n<\/li>\n<li>1 standard servo. \u00a0This costs about $14.00.  You can find it here: <a href=\"https:\/\/www.parallax.com\/product\/900-00005\">https:\/\/www.parallax.com\/product\/900-00005<\/a>\n<\/li>\n<li>Bread board<\/li>\n<li>Arduino<\/li>\n<li>Wires<\/li>\n<li>Computer to program and control the Arduino.<\/li>\n<li>2 Lego servo horns &#8211; I found the following design from Nenzilla from Thingiverse. \u00a0It works pretty well.\n<ul>\n<li><a href=\"http:\/\/www.thingiverse.com\/thing:134151\/#files\">http:\/\/www.thingiverse.com\/thing:134151\/#files<\/a><\/li>\n<li>Don&#8217;t have a 3D printer? \u00a0No problem, you can print the parts using Shapeways.com for $8 to $10. \u00a0Shapeways will deliver the parts to your door!<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>For this construction, you will need two Lego servo horns. \u00a0 Connect Lego technic beams to the Lego servo horns.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoLegoHorn.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1776\" src=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoLegoHorn.jpg\" alt=\"3D printed servo horn for lego\" width=\"500\" height=\"281\" srcset=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoLegoHorn.jpg 500w, http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoLegoHorn-300x168.jpg 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>In the following picture, you can see how we used Lego, rubber bands, the standard servo to enable the crane to turn left to right.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoBottom.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1779\" src=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoBottom.jpg\" alt=\"Left and right Lego servo\" width=\"500\" height=\"281\" srcset=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoBottom.jpg 500w, http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoBottom-300x168.jpg 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>In the following picture, you can see how we used the continuous rotation servo so that the string of the crane can be extended and retracted. \u00a0We&#8217;re just using rubber bands to connect the servo&#8217;s to traditional Lego pieces. \u00a0 We also used our second Lego servo horn.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoUpDown.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1777\" src=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoUpDown.jpg\" alt=\"Up down servo\" width=\"500\" height=\"281\" srcset=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoUpDown.jpg 500w, http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/servoUpDown-300x168.jpg 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Here&#8217;s how we connected the top beam with the support beam.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/craneTop.jpg\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1778\" src=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/craneTop.jpg\" alt=\"Constructing the top beam\" width=\"500\" height=\"281\" srcset=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/craneTop.jpg 500w, http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-content\/uploads\/2015\/04\/craneTop-300x168.jpg 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>What does the Arduino code look like?<\/h3>\n<p>In this section, we&#8217;ll give you an overview of the source code used to drive the servo&#8217;s.  In the Arduino platform, the host PC can communicate with the Arduino at runtime using serial communication.   In the code, you&#8217;ll see that we are using serial communication to send out servo commands in response to characters sent by the host PC.<\/p>\n<p><code><\/p>\n<p>#include <Servo.h> <\/p>\n<p>int incomingByte;      \/\/ a variable to read incoming serial data into<br \/>\nint angle = 0;<br \/>\nint delta = 3;<\/p>\n<p>Servo servoLeftRight;<br \/>\nServo servoUpDown;<\/p>\n<p>void setup() {<br \/>\n  \/\/ initialize serial communication:<br \/>\n  Serial.begin(9600);<\/p>\n<p>  angle = 90;  <\/p>\n<p>  servoLeftRight.attach(9);<br \/>\n  servoUpDown.attach(10);<br \/>\n  servoUpDown.write(90);<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n  \/\/ see if there's incoming serial data:<br \/>\n  if (Serial.available() > 0) {<br \/>\n    \/\/ read the oldest byte in the serial buffer:<br \/>\n    incomingByte = Serial.read();<\/p>\n<p>    if (incomingByte == 'd') {<\/p>\n<p>      angle = angle - delta;<br \/>\n      if(angle <= 0)\n        angle = 0;\n        \n      \/\/ move left   \n      servoLeftRight.write(angle);\n      delay(15);\n    } \n\n    if (incomingByte == 'a') {\n      angle = angle + delta;\n      if(angle >= 180)<br \/>\n        angle = 180; <\/p>\n<p>      \/\/move right<br \/>\n      servoLeftRight.write(angle);<br \/>\n      delay(15);<br \/>\n    } <\/p>\n<p>    if (incomingByte == 'w') {<br \/>\n      \/\/raise the hook<br \/>\n      servoUpDown.write(180);<\/p>\n<p>    } <\/p>\n<p>    if (incomingByte == 's') {<br \/>\n      \/\/lower the hook<br \/>\n      servoUpDown.write(0);<br \/>\n    } <\/p>\n<p>    if (incomingByte == ' ') {<br \/>\n      \/\/stop the continuous rotation servo<br \/>\n      servoUpDown.write(90);<br \/>\n    } <\/p>\n<p>  }<br \/>\n}<br \/>\n<\/code><\/p>\n<p>In the following setup code, we declare variables for the character typed by the user and the angle of the crane.  We also declare our servo&#8217;s. One servo is used to change the direction of the crane.  (servoLeftRight)   The other servo moves the hook of the crane up and down.  We initialize the direction servo to 90 degrees.    &#8220;ServoLeftRight&#8221; will be attached to Arduino pin 9.   &#8220;ServoUpDown&#8221; is connected to Arduino pin 10.<\/p>\n<p><code><br \/>\n#include <Servo.h> <\/p>\n<p>int incomingByte;      \/\/ a variable to read incoming serial data into<br \/>\nint angle = 0;<br \/>\nint delta = 3;<\/p>\n<p>Servo servoLeftRight;<br \/>\nServo servoUpDown;<\/p>\n<p>void setup() {<br \/>\n  \/\/ initialize serial communication:<br \/>\n  Serial.begin(9600);<\/p>\n<p>  angle = 90;  <\/p>\n<p>  servoLeftRight.attach(9);<br \/>\n  servoUpDown.attach(10);<br \/>\n  servoUpDown.write(90);<br \/>\n}<br \/>\n<\/code><\/p>\n<p>The &#8220;loop&#8221; function keeps repeating code forever.   If the Arduino finds bytes incoming from the host computer, we read the byte and do something useful with it.<br \/>\n<code><br \/>\nvoid loop() {<br \/>\n  \/\/ see if there's incoming serial data:<br \/>\n  if (Serial.available() > 0) {<br \/>\n    \/\/ read the oldest byte in the serial buffer:<br \/>\n    incomingByte = Serial.read();<\/p>\n<p>    \/\/Do something!!<\/p>\n<p>  }<\/p>\n<p>}<br \/>\n<\/code><\/p>\n<p>To send characters to your Arduino, you will need to open the serial monitor window by pressing CTRL+SHIFT+M .  By entering &#8216;d&#8217; or &#8216;a&#8217;, you will move the direction of the crane left and right.<br \/>\n<code><br \/>\n    if (incomingByte == 'd') {<\/p>\n<p>      angle = angle - delta;<br \/>\n      if(angle <= 0)\n        angle = 0;\n        \n      \/\/ move left   \n      servoLeftRight.write(angle);\n      delay(15);\n    } \n\n    if (incomingByte == 'a') {\n      angle = angle + delta;\n      if(angle >= 180)<br \/>\n        angle = 180; <\/p>\n<p>      \/\/move right<br \/>\n      servoLeftRight.write(angle);<br \/>\n      delay(15);<br \/>\n    }<br \/>\n<\/code><\/p>\n<p>In a similar fashion, entering &#8216;w&#8217; and &#8216;s&#8217; will raise and lower the hook. Sending a space character will stop the continuous rotation servo.<br \/>\n<code><br \/>\n    if (incomingByte == 'w') {<br \/>\n      \/\/raise the hook<br \/>\n      servoUpDown.write(180);<br \/>\n    } <\/p>\n<p>    if (incomingByte == 's') {<br \/>\n      \/\/lower the hook<br \/>\n      servoUpDown.write(0);<br \/>\n    } <\/p>\n<p>    if (incomingByte == ' ') {<br \/>\n      \/\/stop the continuous rotation servo<br \/>\n      servoUpDown.write(90);<br \/>\n    }<br \/>\n<\/code><\/p>\n<p>In a future blog post, I might try to recreate this program using ArduBlock to make the programming experience more accessible to kids.<\/p>\n<p>Let us know if you need help building your own Lego robots using Arduino.   I would enjoy hearing what you&#8217;re trying and building!<\/p>\n<p>Wish you the best!<\/p>\n<p><strong>Top Stories on InspiredToEducate.NET<\/strong><\/p>\n<p><strong>Learning To Code<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1319\">Easy Data Visualization with Google Charts and JavaScript<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=795\">Learn to Build Your Own Conversational Bot using ChatScript<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1285\">10 Free Resources for Learning JavaScript and HTML5<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1238\">17 Fun Tools To Teach Kids To Code by @ChrisBetcher<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=623\">Benefits of Teaching Kids To Code That No One Is Talking About<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1349\">Easy Recipes for Building Android Apps using MIT App Inventor<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=738\">12 Steps To 3D Print Your Minecraft Creations<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=849\">How to Build Your Mobile App using HTML<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1079\" target=\"_blank\">Simple Minecraft Programming Using ScriptCraftJS<\/a><\/li>\n<\/ul>\n<p><strong>Science Education<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1093\">Why hate science?<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=374\">7 ideas for creating a student centered learning environment by Paul Andersen<\/a><\/li>\n<li><a href=\"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/?p=1022\">Using candy to teach DNA structure<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Join the\u00a0<a href=\"https:\/\/www.facebook.com\/groups\/1529734900588516\/\" target=\"_blank\">Spark Macon Maker Space Community on Facebook<\/a><\/strong><\/p>\n\n<!-- Facebook Like Button v1.9.6 BEGIN [http:\/\/blog.bottomlessinc.com] -->\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=http%3A%2F%2Finspiredtoeducate.net%2Finspiredtoeducate%2Fbuilding-lego-crane-using-arduino%2F&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px; height: 30px; align: left; margin: 2px 0px 2px 0px\"><\/iframe>\n<!-- Facebook Like Button END -->\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m always looking for new ways to play and build with my kids. \u00a0In the Rosario house hold, we enjoy building stuff with Lego&#8217;s. \u00a0 My kids have also enjoyed playing with Lego Wedo and Lego Mindstorm kits at our makerspace. \u00a0 For many families, getting access to a Lego [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[22,4,24,16,23,11,8],"tags":[],"_links":{"self":[{"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/posts\/1775"}],"collection":[{"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/comments?post=1775"}],"version-history":[{"count":6,"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/posts\/1775\/revisions"}],"predecessor-version":[{"id":1786,"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/posts\/1775\/revisions\/1786"}],"wp:attachment":[{"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/media?parent=1775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/categories?post=1775"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/inspiredtoeducate.net\/inspiredtoeducate\/wp-json\/wp\/v2\/tags?post=1775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}