Lego Crane

Thanks to projects like and MIT Scratch, students can encounter ideas from computer science using rich puzzle interfaces. Using these puzzle interfaces, students grow their skills of creativity and critical thinking while building something fun. Puzzle based programming interfaces put emphasis on the student learning sequencing, loops, and connecting appropriate pieces together. In this post, I wanted to share my experiences with Ardublock, a puzzle based programming interface for the Arduino platform. Using the most recent beta of Ardublock, I found that I could create an Arduino program to control motors quickly. I’m looking forward to seeing how students in our makerspace will enjoy the software.

The Arduino platform enables makers and students to program experiences involving electronics or sketches. You can learn more about this platform from the following blog post. In our previous blog post, we used Arduino, Lego’s, and a few servo motor’s to create a small toy crane. In this sketch, the user can move the crane by sending a character to the Arduino through the serial monitor.

  • w – moves the crane up.
  • s – stops the crane.
  • x – moves the crane down.
  • a – moves the crane left.
  • d – moves the crane right.

In the crane setup, pin 9 of the Arduino is connected to a standard servo. Pin 9 will be used to move the crane left and right. Pin 10 will be used to move the crane up and down. We initialize our variable for the direction or angle of the crane. We also send an angle of 90 degrees to both servo motors to ensure that the motors stop moving.

Ardublock setup


In the Arduino platform, the programmer needs to define a main loop of functionality.   In the crane control program, we start the process by accepting a character from the serial port and storing the character in a variable called “input.”   If we receive the character ‘d’ for move left, then the system changes the angle variable and writes the angle to the servo motor.  You can see the Ardublock code below.   The character ‘a’ for move right operates in a similar manner.    When we receive the characters x and w to move up and down, we write an appropriate value to the continuous rotation servo.   (0 = move up, 180 = move down)

Ardublock main loop

When using Ardublock, the student is not hidden from the C code generated by the tool.  The student can be encouraged to change the C code.  I see this as a nice learning advantage.   I want our students to make the connection between puzzle pieces and traditional code.

If you’re interested in learning more about this free and open source product, check out the following link:

Top Stories on InspiredToEducate.NET

Learning To Code

Science Education



This entry was posted in creativity, making, open source, programming, stem, technology, Uncategorized. Bookmark the permalink.