Day 10:Robo Pet

Lesson Description

In this lesson, we are going to make a robot pet that reacts when it is pampered with hands. The robot can detect the pampering using IR sensors, and act accordingly.

 Robot Pet

Assembling the Vertical Robot

We will see how to transform the Horizontal Robot into the Vertical Robot in this topic.

Assembly

  1. By far, your robot looks like this.
  2. Remove the battery holder lock and then the battery holders. Gently unsnap from the edges.
  3. Remove the castor wheel from the robot and attach it to the castor plate A5.
  4. Mount the castor plate on the backside of the board.
  5. Mount the battery holders and the battery holder lock to secure the battery.
  6. You can even place the cutout a.k.a the skin of the robot to make it look cuter. 🙂

Your vertical robot is now assembled and ready to run!

Activity 1: Making a Hand Detection System

 

In this lesson, we will make the Quarky detect the hands.

IR Sensors

Let us understand the IR Sensors. An infrared (IR) sensor is an electronic device that measures and detects infrared radiation in its surrounding environment. IR is invisible to the human eye.

Quarky has 2 IR sensors.

Let’s understand how they work.

An IR sensor consists of 2 LEDs: one which transmits the IR light and one which receives the IR light. When the IR rays are transmitted, they bounce from the nearest surface and get back to the receiver LED. That’s how an IR sensor detects an object.

PET1 (2)

We can get the sensor values in PictoBlox based on that value. We can estimate whether there is an obstacle.

  1. If the sensor detects nothing, its output value is increased. This means that the sensor is active.
  2. If it detects an obstacle, its output value decreases. This means that the sensor is inactive.

We need first to calibrate the IR sensors, i.e., make sure they’re working fine. For that, we’ll make a script in PictoBlox to calibrate them.

evive Alert
IR sensors DON’T work in sunlight. IR rays from the sun increase the overall threshold of the sensors; therefore they stay active all time. A closed environment or nighttime is the place/time to work with your line following robot.

Activity 2: Making a Robo-Pet

In the last topic, you understood how to calibrate IR sensors.

Why not 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:

  1. When the hand is detected on the Left sensor (IRL inactive), turn left.
  2. When the hand is detected on the Right sensor (IRR inactive), turn right.
  3. When the hand is detected on both the left and right sensors (Both IRR & IRL are inactive), introduce Quarky and smile.
  4. When nothing is detected (Both IRR & IRL are active), do nothing.

 

Lets Code

  1. Add a when flag clicked block from the Events palette.
  2. Go to the Sensors palette and add two set () IR sensor thresholds to () block and write the threshold value you found in the last lesson.
  3. Add set robot orientation as () block and set the orientation as vertical.
  4. Next, add a forever block from the Control palette. We’re using this block because we want to check if the sensor detects the line continuously.
  5. Then, add an if-else block inside the forever block.
  6. Next, go to the Sensors palette and add an is () IR sensor active? block inside the white space of the if-else block. The IR sensor will be active when it detects the black line. This means that its value should be greater than the threshold value. This block will essentially check if the sensor value is greater than the threshold value.
  7. Duplicate the if block and put it inside the two branches of the if blocks. Change the value to IR-L.
  8. Now we have four branches all indicating four conditions. Let’s go over it one by one.
  9. The first case is when no hand is detected. Add a clear screen block from the Display palette.
  10. 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 palette. Set the direction to right and time to 0.3 seconds.
  11. 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 palette. Set the direction to left and time to 0.3 seconds.
  12. Lastly, both sensors detect the hand. Make the Robot smile and play sound – Hi, I am Quarky using the play sound () until done block.

The code is complete.Run and test it.

Table of Contents