Chapter 10: Creating Plankton from SpongeBob SquarePants – Part 2

In the previous chapter, you built Plankton’s frame. The major components, frame, and sensor have all been installed. What comes next is adding additional elements to make the robot look more like Plankton and write code to bring it to life.

In this chapter, we will continue to develop the robot by doing the following:

  • Adding final details to give the appearance of Plankton
  • Programming the robot to be interactive

Technical requirements

To build the robot, all you will need is the Robot Inventor kit. For programming, you will require the LEGO MINDSTORMS app/software.

Access to the code can be found here: https://github.com/PacktPublishing/Smart-Robotics-with-LEGO-MINDSTORMS-Robot-Inventor/blob/main/Chapter%209%20Plankton%20Code.lms.

If you would like a more detailed photo-by-photo build process of the robot, please refer to the following link to view the images: https://bit.ly/3cDrHdw.

Adding the aesthetic details

Alright, you are closing in on this build. It is time to add the details that will make the robot feel more like a robotic Plankton!

Let’s get started by locating the following pieces:

  • Eight blue connector pins
  • Six black connector pins
  • Four teal 5L beams
  • Four teal 3L beams
  • Two teal 3x5 L beams
  • Two teal 2x4 L beams

Here is a visual of the parts needed for this section:

Figure 10.1 – Laying out parts to bring Plankton to life

Figure 10.1 – Laying out parts to bring Plankton to life

Start with the main build and turn to the side of the Intelligent Hub. Add one black connector pin and one 3x5 L beam to each side of the Intelligent Hub:

Figure 10.2 – 3x5 L beams added to the side of the Intelligent Hub

Figure 10.2 – 3x5 L beams added to the side of the Intelligent Hub

Next, add four blue connector pins along the black open frame attached to the front of the Intelligent Hub, leaving the 2L side of the pin exposed:

Figure 10.3 – Blue axle pins added to the open frame

Figure 10.3 – Blue axle pins added to the open frame

Add a teal 3L beam and a 5L beam to the blue connector pins to begin to build out the teal cover for Plankton:

Figure 10.4 – 3L and 5L beams added to the open frame

Figure 10.4 – 3L and 5L beams added to the open frame

Add a black connector pin right below the last blue connector pin that is exposed. Note the following image where the finger is showcasing where to insert the pin:

Figure 10.5 – Black pin added below the blue axle pin

Figure 10.5 – Black pin added below the blue axle pin

Add a teal 2x4 L beam to the bottom and then a teal 5L beam covering the pin connectors:

Figure 10.6 – 2x4 L beam and a 5L beam added to the side

Figure 10.6 – 2x4 L beam and a 5L beam added to the side

Once you have done that, insert another black connector pin in the top corner. Lastly, cover that up with a teal 3L beam:

Figure 10.7 – Side view of Plankton’s face

Figure 10.7 – Side view of Plankton’s face

Here is how it should appear when complete:

Figure 10.8 – Front side view of Plankton’s face

Figure 10.8 – Front side view of Plankton’s face

Here is the front facing view where you can start to see the robot taking shape. The Intelligent Hub will serve as the face once you get to the programming phase:

Figure 10.9 – Front view of Plankton

Figure 10.9 – Front view of Plankton

For the next layer of detail, locate the following parts:

  • Six black connector pins
  • One black 7L beam
  • Two teal 3x3 Technic pieces
Figure 10.10 – Layout of parts for the face

Figure 10.10 – Layout of parts for the face

Add a black connector pin to both ends of the black 7L beam. Connect the beam to the two 3x3 teal pieces. They will be moveable at this point because of the single pin connecting them to the black beam, but that is OK. Insert a black connector pin in the middle hole of each of the 3x3 Technic pieces:

Figure 10.11 – 3x3 teal pieces connected with a black 7L beam

Figure 10.11 – 3x3 teal pieces connected with a black 7L beam

Using the final two black connector pins, you will add these to the main frame of the build. Locate the pin holes that are directly underneath the Intelligent Hub and insert them as shown in the following image:

Figure 10.12 – Black pins added under the Intelligent Hub

Figure 10.12 – Black pins added under the Intelligent Hub

Insert the piece into the black connector pins. You may have to be patient to get a good hold, but it should work out just fine:

Figure 10.13 – Black beam with two 3x3 teal pieces added to the black pins

Figure 10.13 – Black beam with two 3x3 teal pieces added to the black pins

Locate the following pieces next:

  • Ten black connector pins
  • Three teal 9L beams
  • Three teal 3x3 Technic pieces
Figure 10.14 – Layout of parts for Plankton’s face

Figure 10.14 – Layout of parts for Plankton’s face

Start this part by adding two black connector pins to the bottom of each of the three teal 3x3 Technic pieces:

Figure 10.15 – Preparation for the 3x3 teal pieces

Figure 10.15 – Preparation for the 3x3 teal pieces

Next, attach one of the teal 9L beams to these three pieces:

Figure 10.16 – 3x3 pieces connected on the 9L beam

Figure 10.16 – 3x3 pieces connected on the 9L beam

Then, add two black connector pins to the outside teal 3x3 pieces:

Figure 10.17 – Black pins added to the outside of the 3x3 elements

Figure 10.17 – Black pins added to the outside of the 3x3 elements

Next, add a teal 9L beam to the top, followed up by two more black connector pins to add the final teal 9L beam:

Figure 10.18 – 9L beam added to the top of the 3x3 elements

Figure 10.18 – 9L beam added to the top of the 3x3 elements

This part will clip onto the main frame where you just added the part right below Intelligent Hub. Use the two black connector pins sticking out of the center pin hole to secure this piece to the main frame.

Here is how it should appear at this point:

Figure 10.19 – Add this build piece to the underside of Plankton’s face and above the mouth

Figure 10.19 – Add this build piece to the underside of Plankton’s face and above the mouth

You are getting super close to the end! There are just a few more final details to enhance this robot build. Locate the following pieces:

  • Six black connector pins
  • Two teal 2x4 L beams
  • Two teal 5L beams
Figure 10.20 – Layout of parts for the outline of Plankton’s face

Figure 10.20 – Layout of parts for the outline of Plankton’s face

Start by adding the black connector pins around the open frame that is attached to the front of the Intelligent Hub:

Figure 10.21 – Black pins added to the open frame

Figure 10.21 – Black pins added to the open frame

Add the teal 2x4 L beams to the bottom corners facing out, along with the 5L beams on top of the L beams. This will leave the top exposed, as demonstrated in the following image:

Figure 10.22 – Teal 2x4 L beams and 5L beams added to the open frame

Figure 10.22 – Teal 2x4 L beams and 5L beams added to the open frame

You are going to add Plankton’s eyebrow next. To do this, you will require the following parts:

  • One yellow 5L axle
  • One teal 9L beam
  • One black 1L round connector
  • One black 2L round connector
  • Two black elbow connector pins
  • Two black connector pins
  • Two blue connector pins
Figure 10.23 – Layout of parts for the eyebrow

Figure 10.23 – Layout of parts for the eyebrow

First, take the yellow axle piece and slide one of the black 2L and 1L round connectors to the middle. Secure them in place using the curved connectors on either side. Then, insert a blue connector pin at the ends of each curved connector:

Figure 10.24 – 7L beam and eyebrow build

Figure 10.24 – 7L beam and eyebrow build

Then, on the teal beam, add a black connector pin on the fourth pin hole from the edge on both sides:

Figure 10.25 – Eyebrow build complete

Figure 10.25 – Eyebrow build complete

Next, add the eyebrow piece to the opposite side of the teal beam that has two black connector pins sticking out.

Add this piece to the top of the head of Plankton:

Figure 10.26 – Eyebrow added to Plankton’s face

Figure 10.26 – Eyebrow added to Plankton’s face

The face is now complete, so it is time to build out the arms to add to the arm motors.

Building the arms

This is the final build part for the robot before you get to code and bring your Plankton to life! You are going to build two simple arms to bring some extra character and movement to your robot.

To do this, you will require the following parts:

  • 12 black connector pins
  • Two teal 9L beams
  • Two teal T beams
  • Four teal 3L beams
  • Four round teal connectors
  • Two blue connector pins
Figure 10.27 – Layout of parts for the arms

Figure 10.27 – Layout of parts for the arms

Insert the blue connector pins to the ends of both 9L beams. Cover up the blue connector pins with the round teal connector pieces:

Figure 10.28 – Round connectors added to the 9L beams

Figure 10.28 – Round connectors added to the 9L beams

Insert two black connector pins to all of the 3L beams and T beams:

Figure 10.29 – Black pins added to the parts

Figure 10.29 – Black pins added to the parts

From here, go ahead and connect these parts to the 9L beams to complete the arms:

Figure 10.30 – Arms assembled

Figure 10.30 – Arms assembled

Using your final four black connector pins, add two to each of the T pieces to connect the arms to the motors:

Figure 10.31 – Black pins added

Figure 10.31 – Black pins added

And finally, you add the antenna. Find the two antenna pieces and two gray connector pins:

Figure 10.32 – Antenna parts

Figure 10.32 – Antenna parts

Insert the pins in the top of the head and attach the antenna:

Figure 10.33 – Arms and antenna added to Plankton

Figure 10.33 – Arms and antenna added to Plankton

And now for the final part! Find the round teal element:

Figure 10.34 – Round connector

Figure 10.34 – Round connector

Use this round teal part to hide the small red axle part exposed on the side:

Figure 10.35 – Round connector added to the red axle

Figure 10.35 – Round connector added to the red axle

And with that you have successfully built Plankton! Let’s now bring him to life, complete with all his crankiness!

Figure 10.36 – Complete build of Plankton

Figure 10.36 – Complete build of Plankton

This is a good time to work to hide the wires behind Plankton using wire clips. Ensure that they are not so tight that the wires can’t move as Plankton moves:

Figure 10.37 – Back view of Plankton

Figure 10.37 – Back view of Plankton

Double-check your build from this side, along with the front and back views of the previous images:

Figure 10.38 – Side view of Plankton

Figure 10.38 – Side view of Plankton

The build is now complete. It is now time to write code to bring the robot to life.

Writing the code

You have this wonderful Plankton build and it is only cool if it indeed moves and interacts with the environment. This code will walk you through some ways to bring Plankton to life, while providing enough openness to be tweaked to your liking.

The code for this project is designed to achieve the following objectives:

  • Use two motors to create arm movement.
  • Use one motor to enable the head to turn.
  • Use one motor to open and close the mouth.
  • Use a color sensor to code voice or movements.
  • Use a distance sensor to trigger responses.

The ports

Before you dive into the code, let’s be sure that your motors and sensors are properly plugged into the proper ports. The neck motor, which will allow Plankton to move to the left and right, should be in port A. The motor that opens and closes the mouth needs to be in port C. The arms will be in ports D and E. The color sensor on the front of Plankton will be plugged into port F. Later, if you want to add the distance sensor for some optional coding and interactions, then that will go into port B.

Plankton robot program

Again, this code will get your build up and running while providing you with lots of room for your own unique style to be infused as you wish. Just take things one step at a time and you should be up and running in no time.

When the program starts the code

This section of code will be the code for what happens when the robot starts up. It is basically designed to calibrate the robot to the same original position before engaging in interactions:

  1. Open up the MINDSTORMS software.
  2. Click on Projects at the bottom of the menu bar.
  3. Scroll down to Other and click on Create New Project.
  4. Choose to make a Words Blocks program
  5. Start with the When Program Starts block, which is the default block on the screen:
    Figure 10.39 – The start block to begin coding

    Figure 10.39 – The start block to begin coding

  6. Create a Variable named Voices in the Orange Variable section:
    • Select Make a Variable.
    • Name it Voices.
  7. Drag the Set Variable To block under the when program starts block.
  8. Insert a purple Light block called turn on and design the eye of Plankton.
  9. Insert a purple Light block called set Center Button light to and change it to black so it is off when in use.
  10. Insert two blue Motor blocks called set speed to. Change the speed to 10%. One blue motor block will be for motor A, and the second block for motor C.
  11. Insert four blue Motor blocks called go to shortest path to position 0. Make one block for motors A, C, D, and E. This will reset the robot to its original position before anything begins.
  12. Insert two yellow Events blocks called broadcast. Name one Mouth and the other Neck. This will eventually activate movements for the mouth and neck.
  13. Insert an orange Control block called wait and make this .5 seconds.
  14. Insert a purple Sound block called start sound. From this menu, you can choose a sound from the library or, if you have any Plankton sound files of your own, you can add these here.
  15. Insert an orange Control block called repeat. Make the repeat block repeat for three cycles. Inside the repeat block, add a purple Light block called start animation. When you click on the drop-down menu, you will see the following options:
    Figure 10.40 – Menu to create your own animation

    Figure 10.40 – Menu to create your own animation

  16. Choose Animation Editor.
  17. Design your own animation of the eyes opening and closing, or you can use the one I made, which is found in the coding example:
    Figure 10.41 – Animation creation panel

    Figure 10.41 – Animation creation panel

  18. Be sure to select the animation from the drop-down menu that you created.
  19. Insert an orange Control block named wait under the Animation block. Start at .25, but you can adjust this to your liking so that the animations are viewable.

Here is what this code should look like when complete:

Figure 10.42 – Complete view of the program when it starts

Figure 10.42 – Complete view of the program when it starts

Now that you have the robot calibrated, it is time to write some code to interact with its environment. Let’s now take a look at some options for the color sensor.

Color sensor code

This section will walk you through the code for the color sensor. You can adjust the colors as well as what you want to have happen when a color is detected. For this example, you will program for sound effects. You will code one of these sections and then duplicate as many times as you wish for other colors:

Figure 10.43 – One section of code for one color

Figure 10.43 – One section of code for one color

  1. Insert a yellow Events block for when color is and choose a color. In this example, white is used.
  2. Insert two yellow Events blocks named broadcast and make one say Mouth and the other Arms Up.
  3. Insert an orange Control block named wait and set that block to .5 seconds.
  4. Insert a purple Sound block named start sound and select the sound file of your choice.
  5. Insert an orange Control block named repeat and set that to 3. Inside the repeat block, add a purple Light block called start animation and choose the same animation you designed previously, or create a new one if you prefer.
  6. Insert an orange Control block named wait and set that block to .5 seconds.

Repeat this process for other colors by right-clicking on this section of code and choosing Duplicate:

Figure 10.44 – Duplicate option to copy code

Figure 10.44 – Duplicate option to copy code

Here is what the code looks like at the end for the demo code; four colors with four different phrases. Note that one of these has different animations and movements, so remember you can tweak each one to your liking to do different things:

Figure 10.45 – Color sensor code

Figure 10.45 – Color sensor code

You now have the color sensor coded, but you now need Plankton to look like it is interacting. To do this, you need to write some code to open and close the mouth when it is talking.

Mouth open code

This section is pretty easy. You will basically write a simple code that moves the mouth motor back and forth. While easy to program, you can spend a great deal of time fine-tuning this to get it just the way you want Plankton to look while talking:

  1. Insert a yellow Event block named when I receive and change the option to Mouth in the drop-down menu.
  2. Insert an orange Control block named repeat and set it to 2.
  3. Inside the Repeat block, add a blue Motor block named motor run for. Choose motor C and have it move counterclockwise for 50 degrees.
  4. Inside the Repeat block, add another blue Motor block named motor go to shortest path to position. Choose motor C and set the position to 0.

Here is how the code appears when done:

Figure 10.46 – Mouth code

Figure 10.46 – Mouth code

Now that Plankton can give the appearance of speaking, you need to get his arms moving. If you have ever watched SpongeBob SquarePants, then you know he is quite animated despite being a simple Plankton. The key is the arms. Let’s bring them to life.

Arms up code

Next, you have some code to write to activate the arms. This is a demo code, so understand that you can change the arm movements and you can also create several different arm movement broadcast codes. For example, these arms go up and down, but you could have the arms alternate or only one arm move:

  1. Insert a yellow Events block named when I receive and change the option to Arms Up.
  2. Insert an orange Control block named repeat and set it to 2.
  3. Inside the repeat block, add a pink Movement block named set movement motors and choose motors D and #.
  4. Inside the repeat block, add a pink Movement block named set movement speed to 20%.
  5. Inside the repeat block, add a pink Movement block named move straight for -40 degrees.
  6. Inside the repeat block, add a pink Movement block named set movement speed to 20%.
  7. Inside the repeat block, add a pink Movement block named move straight for 40 degrees.
  8. Insert the Motor block, Motor D go shortest path, at position 0.
  9. Insert the Motor block, Motor E go shortest path, at position 0.

Here is what the code should look like when complete:

Figure 10.47 – Complete arm code

Figure 10.47 – Complete arm code

Plankton now speaks, moves his arms, and looks alive. We now have a few more small sections of code to expand his appearance. The following code section will allow Plankton to move his head back and forth to give one more layer of movement.

Neck turn code

Let’s now get the neck moving back and forth. This section of code is just like the previous sections. It is pretty straightforward to code, but realize you can fine-tune and tweak this code to your liking and have some real fun with this code:

  1. Insert a yellow Events block named when I receive and change the option to Neck.
  2. Insert a blue Motor block named Motor A run clockwise for 50 degrees.
  3. Insert an orange Control block named wait and change to .25 seconds.
  4. Insert a blue Motor block named Motor A run counterclockwise for 100 degrees.
  5. Insert an orange Control block named wait and change to .25 seconds.
  6. Insert a blue Motor block named Motor A go to shortest path to position 0.

Here is what the completed code should look like:

Figure 10.48 – Neck movement code

Figure 10.48 – Neck movement code

All the movements are now complete. What you need to add now is sound. You can add sounds from the library in the software or search online and find some files of your own to use. Always practice proper copyright usage.

Random sound generator code

Using the color sensor, you can have Plankton perform a variety of tasks based on color selections. For the demo, each color will have a new sound to be shared, but understand that you can trigger different demands:

  1. Insert a yellow Events block named when I receive and change the option to Random Sound.
  2. Insert an orange Control block named If. Within the block, add a green Operator block using the = equation. Drag in the name of your variable, Voice, and change the number to 1.
  3. Insert a purple Sound block named play sound until done. Add the sound of your choice.
  4. Right-click and duplicate this If block as many times as you have for colors you want to trigger. For each of these, simply change the number from 1 to 2 to 3 to 4. Change the sound file to the sound effect you want.

Here is what the code looks like:

Figure 10.49 – Sound files for bringing Plankton to life

Figure 10.49 – Sound files for bringing Plankton to life

Plankton is now ready. However, you have an additional sensor, so if you want to explore yet another bonus interaction component, you could build another device, creature, or setup to engage the distance sensor.

Optional distance sensor code

The distance sensor is not actually built into Plankton, which is why I made it optional. I created a small little creature that stands next to Plankton to use the sensor. If you want to use the sensor, then here is a sample code that would randomly play a sound file when an object is detected:

  1. Insert a yellow Event block named Distance Sensor B when closer than 8 cm.
  2. Insert an orange Variable block named set Voices to pick random 1 to 4 by adding a green Operator block named pick random.
  3. Insert a yellow Event block named broadcast Random Sound.
  4. Insert a purple Light block named start animation and choose your eye animation.

Here is what this code looks like:

Figure 10.50 – Distance sensor code

Figure 10.50 – Distance sensor code

Finally, here is the complete view of the code. If this is hard to read, please remember that you have access to the code file to make it easier to view on your device:

Figure 10.51 – The complete code layout

Figure 10.51 – The complete code layout

So now it is time to play and have fun. Enjoy Plankton and bring your own ideas to life.

Making it your own

What can you do to make this build unique to your own needs? Here are some suggestions and I look forward to your creative ideas.

Here are a few ideas to consider:

  • What are the different responses that Plankton could have using the color and distance sensors?
  • What types of eye animations could you create to bring more emotion to Plankton?
  • Could you incorporate the distance sensor into the Plankton build itself?

Summary

In summary, this robot was the biggest build of them all using motors and parts in new and exciting ways. There were many build techniques using gears, attachment techniques, and utilizing the creative constraints of one kit. You used motors to open and close a mouth, turn a neck, and animate arms. You have sensors to bring this robot to life in an animatronic sense, where you can have Plankton interact with his environment and those around him. Finally, it allows for complete freedom for you to make him behave as you wish.

My hope is that this build inspires you to build your own creations, monsters, characters, and suchlike, and that you will go on to do incredible work with all the skills you have gained.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset