• Elementary
  • Lesson 25 – Pamper your Robot Pet Part 2

Lesson 25 – Pamper your Robot Pet Part 2

Lesson Description

In this lesson, you will learn to make a robot pet that reacts when it is pampered with hands using IR sensors. It will turn left/right or smile/play sound when detected.

ACTIVITY: MAKING A ROBO-PET

Make a robot pet that reacts when it is pampered with hands. The robot can detect the pampering using IR sensors, and act accordingly.

The objective is to make the robot execute certain actions when it detects a hand:

  • When the hand is detected on the Left sensor, turn left.
  • When the hand is detected on the Right sensor, turn right.
  • When the hand is detected on both the left and right sensors, introduce Quarky and smile.
  • When nothing is detected, do nothing.

CODING STEPS

Follow the steps below:

  1. Create a New file in PictoBlox App.
  2. Connect Quarky to PictoBlox.
  3. Add a when flag clicked block from the Events
  4. Go to the Sensors palette and add two set () IR sensor thresholds to () block and write the threshold value you found in the last activity.
  5. Add set robot orientation as () block and set the orientation as vertical.
  6. Next, add a forever block from the Control We’re using this block because we want to check if the sensor detects the line continuously.
  7. Then, add an if-else block inside the forever
  8. Next, go to the Sensors palette and add an is () IR sensor active? block inside the white space of the if-else
  9. Duplicate the if block and put it inside the two branches of the if blocks. Change the value to IR-L.
  10. Now we have four branches all indicating four conditions. Let’s go over it one by one.
    1. The first case is when no hand is detected. Add a clear screen block from the Display
    2. The second case is when the IR-R sensor detects the hand. In this case, the robot will turn Left. Add go () at () % speed for () seconds block from the Robot Set the direction to left and time to 0.3 seconds.
    3. The third case is when the IR-L sensor detects the hand. In this case, the robot will turn Right. Add go () at () % speed for () seconds block from the Robot Set the direction to right and time to 0.3 seconds.
    4. Lastly, both sensors detect the hand. Make the Robot smile and play sound – Hi, I am Quarky using the play sound () until done block.
  11. The code is complete. Run and test it.

Table of Contents