Introduction: Using an Arduino Drawing Robot With Hour of Code Tutorials

Picture of Using an Arduino Drawing Robot With Hour of Code Tutorials

I created an Arduino drawing robot for a workshop to help teen girls get interested in STEM topics (see https://www.instructables.com/id/Arduino-Drawing-Robot/). The robot was designed to use Turtle-style programming commands such as forward(distance) and turn(angle) to create interesting pasterns.

During the workshop, we used the "Anna and Elsa" tutorial from the Hour of Code to help the participants become familiar with programming in preparation for programming their robot. The tutorial uses graphical programming blocks to help avoid the roadblocks of typing and syntax, but the equivalent JavaScript code can be viewed, creating a powerful bridge to learning a commonly used and powerful programming language.

Our discovery was that since the tutorial used a similar commands for moving Anna around the screen, and that JavaScript's formatting structure is very similar to Arduino C code, that drawing patterns could be created and tested in the browser, and then the generated JavaScript code copied and modified to drive the robot in Arduino! Using code to control something in the physical world is an engaging demonstration of the power of programming.

Step 1: Hour of Code Tutorial

Picture of Hour of Code Tutorial

Both the "Anna and Elsa" and the "Artist" Hour of Code tutorials use commands like "move" and "turn" to move the characters around the screen. As the tutorial progresses, you learn the power of loops and nested loops. In step 12 of Anna for example, you use nested loops to create a snowflake patern. At the end of the tutorial, you are given a blank slate to experiment with.

Step 2: Starting Arduino Code

Picture of Starting Arduino Code

If you need help getting started with Arduino, there is not better place to start than the "Getting Started with Arduino" page at www.Arduino.cc.

You, of course, will need to have built and tested your Arduino Drawing Robot.

I have written the code that takes care of all the details of running the stepper motors and provides the simple commands for moving and turning. Download the attached Arduino sketch and place it in your Arduino sketch folder. Then open it with the Arduino IDE. It may ask to place it in a new folder, which is fine.

Step 3: Modify the Code

Picture of Modify the Code

Once you have a pattern in the tutorial you want to use, click on the " Show Code" button. Copy and paste the code into the loop() function of the Arduino sketch. This code is from Anna and Elsa Step 11:

for (var count2 = 0; count2 < 4; count2++) {
for (var count = 0; count < 2; count++) { moveForward(100); turnRight(60); moveForward(100); turnRight(120); } turnRight(90); }

Note that the "var" JavaScript variable type is not a standard data type Arduino. The equivalent would be "int" for integer. To make life easy, I've added some code so Arduino knows that when we say "var", we means "int". Code is all about abstraction.

Compile and upload the code! It is just that simple. If the robot's drawing doesn't match what you got in the tutorial, you may need to calibrate your robot or check for loose wheels or dragging parts.

Let me know what you come up with!

Comments

framakers (author)2017-02-04

Wow, this is a really interesting instructable! Very useful, because it can help make the step from programming in hour of code towards using hardware.

favior (author)2016-07-22

Does the Arduino hour of code INO work with the PRO Trinket as well or does the code need to be modified?

skumar231 (author)2015-11-30

good one ...

karlt1 (author)2015-11-28

Very nice.

it will be fun to draw what have been done in hour of code tuto.

just one thing.

in the .ino file you don't use : jumpForward()

this fonction is use by ana and elsa for jump.

is it :

void jumpForward(float distance){

penup;

backward(distance);

pendown;

}

thanks for this tuto.

karl

MakersBox (author)karlt12015-11-28

Totally forgot about jumps! Good catch. I'll add that.