Designing a Piano With TinkerCAD Codeblocks

Introduction: Designing a Piano With TinkerCAD Codeblocks

About: STEM Teacher at TASIS The American International School in England. Passionate about STEM and educational Robotics.

This is a 6th Grade Coding project, where my students had to use TinkerCAD Codeblocks, in order to design using coding their own original pianos. The purpose of this activity is to introduce the importance of using variables and loops in coding. Here is a step by step guide for the keyboard and the main part of the piano. Then the students came up with their own ideas and designs.

Step 1: Declaring the Variables

For the main part of the project, the keyboard, we need to declare 5 variables. The first 3 variables represent the 3 dimensions of our boxes (width, height, length). We also use 2 counters, for the repeat function.

  • Go to the math section and move the "Set item to 1" command to the coding area.
  • Change the name of the variable to "width" and the initial value to 5.
  • Repeat the 2 previous steps 5 times.
  • Set the length "variable" to 50, the "height" variable to 5, the "i" counter to -10 and the "j" counter to -15.

Step 2: Adding the White Keys

Now that we declared the variables we are ready to create the white keys. These keys can be represented by a solid box.

  • Go to the shapes section and select the "Box". Drag this command and drop it to the coding section.
  • Select the white color and mark it as "solid". Expand this block and change the dimensions.
  • Set W to "width" variable, set L to "length" variable and H to "height", by simply dragging the 3 variables from the data section.
  • Go to the modify section on your left hand side and select the move block and attach it to the add box command.
  • Set X to "i" * "width" and Z to "height" / 2. Leave the Y value as it is. You will find the arithmetic operation blocks in the math section (0+0 block).
  • From the math section select the "change item by 1" and attach it underneath the move block. Change item to "i".
  • From the control section select the repeat function block. Envelop the 3 previous commands (add box, move, change). These 3 commands need to be within the repeat function.

Step 3: Adding the Black Keys

Repeat all the steps from the Step 1 and make the following adjustments:

  • The black box dimensions are W : "width" / 2 , L : "length" / 2, H : "height".
  • Change the parameters in the move box to X : "j" * "width" / 2 , Y : "length" / 4 and H : "height" * 1.5 .
  • Change "j" by 2.
  • Repeat 2 times by changing the value in the repeat function.

There is no black key between the 5th and the 6th key. For this reason, we need to use another repeat function:

  • Repeat the previous steps (see above) but this time, repeat 3 times by changing from 2 to three the counter in the repeat codeblock and move the box by (j+2) * "width"/2 on the X axis, by "length"/4 on the Y axis and by "height" * 1.5 on the Z axis.
  • Add another repeat function that includes the other two repeat codeblocks. Set its value to 2. That means that the first part of the code will be executed 2x2 = 4 times in total and the second part (the black keys) will be executed 2x3 = 6 times.
  • Add another "change "j" by 4" codeblock after the end of the second repeat function and before the external repeat codeblock.

The last step we need to do is to create a single black key between the first and the second white keys. In order to do so we need to use the following commands:

Add a solid black box. Its dimensions are W : "width" / 2 , L: "length" / 2 , H : "height"

Add a move codeblock. Expand the codeblock and set the X value to -19 * "width" / 2, the Y value to "length" / 4 and the Z value to "height" * 1.5.

Step 4: Wrapping Up

These are the steps for the main part of the piano. Here's the link for the code on TinkerCAD.

You will also find below the links for two piano designs that me and my students were working on:

Piano No. 1:

Piano No. 2:

Block Code Contest

Participated in the
Block Code Contest

Be the First to Share


    • Toys & Games Contest

      Toys & Games Contest
    • Arduino Contest

      Arduino Contest
    • Barbecue Speed Challenge

      Barbecue Speed Challenge



    5 months ago

    Very cool. Thanks for sharing!