Sign in:

Tutorial #6: Back up bot


In this tutorial you’re going to explore Conditionals. Don’t let the fancy name worry you! If you talk through the concepts they are actually a pretty intuitive coding practice.

An “if statement” is a coding tool that allows you to create an action if something occurs. A simple example is: If I see you wave “hello”, then I will wave hello in response.

Conditionals are statements that outline requirements for whether or not something has occurred. Conditionals allow us to be more specific when we write an if statement. To continue with our earlier example… If I see you wave hello and you are looking at me, then I will wave hello in response.

Let’s start programming so you can see how if statements and conditionals help expand your robot’s capabilities!


  1. In this tutorial you are going to create a robot that will drive forward when it detects a nearby object but reverse if it gets too close.
  2. Before you begin, be sure to download the “cubelets_tutorial_6.cubelet” starter file.

  3. Then assemble the tutorial robot using the on-screen instructions.
  4. Power on your robot and be aware that your Drive Cubelet may still be running a custom program. Be sure that your robot won’t drive away when you power it on! There’s no need to return your Cubelets to the default program if you’re going to program them again, but you may find it easier to do so.
  5. Click the connection icon and complete the Bluetooth pairing process.
  6. Next you’ll need to load the “cubelets_tutorial_6.cubelet” file. Click the load icon in the toolbar. Then follow the system dialogue to select the proper file.

    Load a .cubelet file.

  7. In this tutorial you’ll be creating a program for your Drive Cubelet. This program has two sections. The first portion tells your Drive Cubelet to move forward according to the weighted average Block Value. The second portion tells your Drive Cubelet to switch motor directions to a set level for a fixed period of time if the Block Value exceeds 180.
  8. Let’s start with the first portion, finish the first line of code so it sets the actuator value to the weighted average.
  9. In the next line you’ll see the start of an if statement and a conditional. In the future, you can find these blocks in the “Logic” menu. Complete the conditional statement so that it reads “if the weighted average is greater than 180.”
  10. If you’re having difficulties completing this section, click here for a hint.

    HINT: Use the weighted average block in the first puzzle piece window, and the number field in the second puzzle piece window. Set the number equal to 180. Finally, use the dropdown to select the greater than symbol (>).

  11. Nice job! You’ve completed the first part of your if statement. Now, arrange the remaining blocks inside of the if statement so that the robot switches directions, sets its motor to full speed for a period of 500 milliseconds then switches directions again so it moves forward.
  12. Alright, double check your work by clicking here to reveal the solution. If your program matches, you’re ready to program your Drive Cubelet. Select the Drive Cubelet from the block map and click “Program Selected Cubelet.”

  13. Once Cubelets Blockly has finished updating your Drive Cubelet, take a moment to experiment with the new behavior you created using an if statement and a conditional!
  14. In Tutorial #7 we are going to use the same robot as a starting point! If you’d like to focus on something else and wish to continue your tutorial progress later, select your Drive Cubelet from the block map and click “Restore Default Program.” Otherwise click here to proceed to Tutorial #7!