Animated Cat Toy

973

4

2

Introduction: Animated Cat Toy

It never fails. I want to play with my cat and she wants to sleep. She wants to play and I am busy. What to do? The Automated Cat Toy mimics my cat’s favorite game - chase the laser dot.

The purpose of this Instructable is two-fold:

1) demonstrates automating a task and

2) continues the instructional sequence on using the 2020 Lego Mindstorm Robot Inventor Kit.

This Instructionable focuses on programming the Robot Inventor’s sound. It also elaborates on the movement, motor, and distance sensor commands which were introduced in the “Lego Robot Inventor Kit - Blast: On His Own” Instructable and the “Happy Pi Day!” Instructable.

Supplies

Lego Set - Mindstorms (51515)

Selected parts including hub, battery, 3 motors, distance sensor, technic beams (1x11, 1x7), connector beams, wheels, frames, pins, and bushing.

Additional Legos

1x1 plate round (4073) - red - quantity 5

1x1 round brick (3062b) - white or gray - quantity 10

2x2 round plate (4032) - white - quantity 2

2x2 round plate (4032) - red - quantity 1

2x2 round brick (3941) - white - quantity 2

2x2 dish (4740) - dark bluish gray - quantity 2

1x1 technic brick (6541) - reddish brown or dark bluish gray - quantity 1

Arduino Nano and Arduino Software

Laser Diode

Breadboard

9-volt Battery

Battery connector

Piece of Wire for the tail

Velcro

Mindstorms software

Step 1: Build the Mouse

This step shows how to build the Mouse. Follow the images using parts from Lego Kit 51515 as well as the additional lego parts listed under Supplies.

1) Connect the three motors to each other using black pins, position eight black pins on the outputs of the two outside motors, position one (1/2) pin on the center motor, attach the connector beams (3x3) to the bottom of the two outside motors, attach 1x3 beams to the outside of each connector beam, and insert one blue (pin/axle) pin on the outside of each connector beams (see images 1 and 2).

2) Connect 1x11 beam to front of the connector beams, attach 1x7 beam to front of 1x11 beam, insert five 1x1 round red plates into the middle of the 1x7 beam (the mouth), and attach all four wheels (see image 3).

3) Connect two 1x9 beams (stacked) to the motors between the rear tires using 3L blue pins and attach two 1x9 beams (stacked) to the motors between the front tires using 3L blue pins. These beams raise the hub higher (so that it doesn’t interfere with the wheels) and flatten the wires (see image 4).

4) Connect ten 1x1 round bricks together (thread the extra piece of wire through the bricks), position one 1x1 technic brick to the (½) pin on the middle motor, and connect the string of round bricks to the technic brick (see image 5).

5) Connect the technic frame to the top of the hub using black pins, attach 1x9 beam to the front of the hub using black pins, attach two 1x2 beams to the front of the hub, and insert two black pins in the 1x9 beam, one black pin in each 1x2 beam, and four black pins to the bottom of the hub (see image 6).

6) Connect two 2x2 round plates and two 2x2 round bricks together, attach a 2x2 cone to the round plates/bricks, attach a white 2x2 plate and a red 2x2 plate to the top of the cone to form a nose. Attach the hub to the motors, connect a 1x5 beam to the two 1x2 beams, and attach the nose to the 1x5 beam using a 3L axle with a bushing (see image 7).

7) Connect two 1x3 beams to the front of the technic frame using black pins and connect a 2x2 dish to each 1x3 beam (see image 8) for ears.

8) Attach distance sensor to the black pins on the front (see image 8) for eyes.

Step 2: Attach Wires to the Hub

This step shows the attachment of the motor and distance sensor wires to the hub.

1) Attach the motors and distance sensor to the hub (see image 1 for the lettering).

Port D - Distance sensor (see image 2).

Port A - Left motor for left wheel (see image 3).

Port C - Center motor for tail (see image 3).

Port E - Right motor for right wheel (see image 3).

Step 3: Set Up the Mindstorm Program

This step shows how to set up the Lego program (Mindstorms App) which will control the Mouse’s movement.

1) Open Mindstorms App (see image 1).

2) Click on Projects (bottom of image 1).

3) Scroll down to Other (see image 2).

4) Click on Create new Project (see image 2 for + symbol).

5) Select Word Blocks and click Create (see image 3).

6) Click on the three vertical dots and select Rename Project (see image 4).

7) Type “Mouse” for name (see image 5).

8) The new project automatically gets the code line “When Program Starts” (see image 6).

Step 4: Outline the Programming Logic

The code (see images 1 and 2) instructs the Mouse to move forward until an obstacle is encountered. Then, the mouse reverses and alternates between turning left and right.

Step 5: Write Code: Set Up

This step prepares the motors and the distance sensor for programming. It also sets up the one variable used in the program to monitor left and right turns.

1) Make a variable named “times” (see image 1) and drag “Set times to” under the “When program starts” command (see image 2). Make sure the "times" variable is selected from the drop down menu and a "0" is in the white oval (see image 2).

2) Drag “Set speed to” from Motor Category to under the “Set times to” command (see image 2). Make sure "Motor C" (the tail) is selected from the drop down menu and put "25" in the white oval (see image 2). The speed can be set between 1% and 100% of maximum speed.

3) Drag “Set movement motors to” from Movement Category to under “Set speed” command (see image 2). Select motors A and E (see image 3) with A on the left and E on the right.

4) Drag “Set movement speed” from Movement Category to under “Set movement motors to” (see image 2). Put "50" in white oval. The speed can be set between 1% and 100% of maximum speed.

Step 6: Write Code: Programing the Sound

This step programs the playing of the cat meow sound just before the Mouse's first move to get the cat's attention.

1) Drag “Start sound “Cat Meow 1” from the Sound Category (see image 1) to under “Set movement speed to” (see image 2). The “Play sound” is similar but it completes the sound before moving on to the next step.

The Cat Meow 1 shows up because I previously selected it from the sound library.

1. Click on the dark violet oval and select "Add Sound" (see image 3).

2. Click on the "Library" and scroll down to select Cat Meow 1 (see image 4).

3. You also can edit the sound by clicking on the dark violet oval and selecting "Edit Sound" (see image 3).

4. The sound editing screen (see image 5) allows for editing (echo, louder, softer, looping, cutting, copying, pasting, and deleting) the selected sound.

5. An entirely new sound may also be recorded in this section by clicking on "Record" (see top of image 6) and then clicking on the red circle (see bottom right of image 6).

2) Clicking on the last image (image 7) shows a video with audio so that you can hear the Cat Meow coming from my computer. If you watch long enough you also will hear the beeps (see Step 9).

Note: Other than beeps, the sound is played from your device (computer, tablet) and not the hub.

Step 7: Write Code: Movement

This step programs the Mouse to start moving.

1) Drag “Start moving” from the Movement Category to under the “Start sound” command (see image 1). Make sure "straight:0" is selected for the white oval.

Step 8: Write Code: Wait Until

Steps 8 through 13 presents the code section which will be moved into the repeat loop in Step 14. Specifically Step 8 programs the distance sensor to determine when the Mouse is closer than 12” from an obstacle.

1) Drag "Wait until" (see image 1) from the Control Category to an open space below the first section of code (see image 2).

2) Drag “Distance Sensor (icon) is” from the Sensors Category (see image 3) to an open space near “Wait until” (see image 4).

3) Change the variables: motor D, closer than, 12, and in (see image 5).

4) Drag the “Distance Sensor (icon) is” inside the “Wait until” darker area (see image 6).

Note: Once the Mouse is closer than 12” from an obstacle, the next step in the code executes.

Step 9: Write Code: Beep

This step programs the hub to beep three times when the Mouse encounters an obstacle.

1) Drag “Set volume to” from Sound Category (see image 1) to below “Drag Sensor” (see image 2). Make sure "100" is in the white oval.

2) Drag “Play beep for seconds” from Sound Category (see image 1) to below “Set Volume” (see image 2). Repeat two more times (see image 2). Change the first white oval to "88" (the key) and the second white oval to ".3" (duration in seconds) for the three commands.

Note: The beep sound will play from the hub.

Step 10: Write Code: Reverse Movement

This step programs the Mouse to move in reverse for 10 inches.

1) Drag “Move for” from Movement Category to below the last “Play beep” (see image 1).

2) Change the variables: down arrow, 10, and in (see image 2).

Step 11: Write Code: If/Then - Right/Left

This step sets up the If/Then command to determine whether the Mouse turns right or left after backing up. Throughout the running of the program, the variable times will be 0, 1, 2, or 3. The variable was set to 0 in the setup phase of the code. When the variable is 0 or 1, the mouse turns left and when it is 2 or 3 the mouse turns right. The mouse moves left, left, right, and right which keeps it from getting stuck in a corner.

1) Drag "If then else” (see image 1) from Control Category to an open space (see image 2).

2) Drag “Or” from Operators Category to an open space near “If then else” (see image 3).

3) Drag “=“ from Operators Category to an open space near “If then else” (see image 4). Repeat for a second “=“ (see image 4). Change the first ovals to times and put 0 in the second oval for the first “=“ and 1 in the second oval for the other “=“ (see image 4).

4) Drag the “times = 0” into the first dark space on the “Or” and the “times =1” into the second dark space on “Or” (see image 5).

5) Drag the “Or into the dark space on “If then else” (see image 6).

6) Drag “Move for” from Movement Category to under the “If” (see image 7). Change the first drop down box to left arrow, put 5 in the white oval, and select "in" from the second drop down arrow (see image 7) .

7) Drag another “Move for” from the Movement Category to under the “else” (see image 7). Change the first drop down box to right arrow, put 5 in the white oval, and select "in" from the second drop down arrow (see image 7) .

8) Drag “Start moving” from the Movement Category to under the “Move [left arrow] for” command (see image 7). Make sure straight:0 is selected for the white oval.

9) Drag “Start moving” from the Movement Category to under the “Move [right arrow] for” command (see image 7). Make sure "straight:0" is selected for the white oval.

10) Drag the entire “If Then Else” command under “Move [down arrow] for” (see image 8).

Step 12: Write Code: Wag the Tail

This step programs the C Motor to move which wags the tail.

1) Drag “Run for” from Motors Category (see image 1) to an open space and then drag a second “Run for” from Motors Category to under the first "Run for" (see image 2).

2) Change variables for the first “Run for”: C, [right arrow], 45, degrees (see image 2).

3) Change variables for the second “Run for”: C, [left arrow], 45, degrees (see image 2).

4) Drag the two “Run for” below the “If then else” block (see image 3).

Step 13: Write Code: Change the Variable

This step increases the variable "times" by one until it reaches 3 and then resets it to 0.

1) Drag "If then else” from Control Category (see image 1) to an open space (see image 2).

2) Drag “times” variable from Variable Category (see image 3) and “=“ from Operators Category to area near the “If then else” command (see image 4).

3) Move “times” to the first white oval in “=“ and type "3" in the second white oval (see image 5).

4) Drag “=“ to dark area in “If then else” (see image 6).

5) Drag “Set to” from Variables Category (see image 3) to under “If” (see image 7). Make sure variable is "times" and "0" is in the white oval (see image 7).

6) Drag “Change by” from Variables Category (see image 3) to under “else” (see image 8). Make sure variable is "times" and put "1" in the white oval (see image 7).

7) Drag “If then else” block to under “Run for” (see image 8).

Step 14: Write Code: Repeat

This step adds the “Repeat” block to the code and inserts the code into the block.

1) Drag “Repeat” from Control Blocks Category (see image 1) to an open area and put "5" in the white oval (see image 2). The "5" means that the block will repeat five times.

2) Move “Repeat” under “Start moving” (see image 3).

3) Drag the new code segment inside the “Repeat” block (see image 4).

Step 15: Write Code: Finalize the Program

This step adds the last two lines of code to the program. These lines stop the motors and end the program.

1) Drag “Stop moving” from the Movement Category and “Stop” from the Control Category (see image 1).

2) Drag “Stop moving” and “Stop” below “Repeat” loop (see image 2). Make sure “and exit program” is selected from the drop down menu. Since these two lines are outside the repeat block, they will not be repeated.

3) See images 3 and 4 for the entire code.

4) Clicking on the last (image 5) shows a video of the Mouse responding to obstacles.

Step 16: Design Circuit for Laser Pointer

This step creates the laser pointer/Arduino circuit.

1) Position the Arduino Nano on the breadboard (see image 1).

2) Connect the 9-volt battery to Gnd and VIN (see images 1 and 2).

3) Connect the laser to Gnd and D5 (see images 1 and 2).

Step 17: Program the Arduino to Control the Laser Pointer

This step creates the Arduino program which controls the laser pointer. The pointer will turn on for 3 seconds and off for 1 second.

1) Open Arduino program.

2) Type the code shown in image 1.

3) Watch the laser turn on and off.

Step 18: Attach the Breadboard and 9 Volt Battery to the Hub

This step attaches the breadboard and the 9 volt battery to the hub.

1) Attach velcro to the top of the hub, the long side edge and back on the breadboard, and both narrow sides and the back of the battery (see image 1).

2) Position the breadboard and battery on the top of the hub (see images 1 and 2).

Step 19: Test Auomated Mouse

This step tests all the features to ensure everything is working.

1) Turn on hub.

2) Press hub icon in upper right hand corner of the screen (see image 1) and follow the on-screen directions to complete the connection sequence.

3) Place the Mouse on floor.

4) Click on the start icon (see image 2) in the lower right hand corner of the screen.

5) Watch the Mouse checking for errors or problems (see image 3).

6) My cat catching the dot as soon as the Mouse stops - she is a little lazy. You may increase the number of repeats if you have a lazy cat as well.

Automation Contest

Participated in the
Automation Contest

Be the First to Share

    Recommendations

    • Home Decor Challenge

      Home Decor Challenge
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Box Challenge

      Box Challenge

    2 Comments

    0
    JJ Slabbert
    JJ Slabbert

    2 months ago

    Very creative.

    0
    bmohnsen
    bmohnsen

    Reply 2 months ago

    Thank you