Open the arm when te object is close (using the IR distance sensor)

In this lecture you will not move the robot forward or backwards, but use one of the sensors of the Ozeki Dozer. Namely the IR distance sensor (on the front of the robot), which you can use to measure distance. The program will control the robot in a way that it will open it's gripper if some object is near enough to the infrared distance sensor and grabs the object by closing the gripper.

Figure 1 - Closes the claw of the Dozer on the object

Terms and Definitions

  • Gripper: The claw of the Ozeki Dozer. It consists of two arms which can be open or close.
  • IR sensor: The infrared sensor can detect signals from an infrared beacon and also can measure the distance of the nearest detected object. It has got three different modes for the users: proximity, beacon and remote. In this case, the proximity mode was used.
  • Proximity: Nearness in space, time or relationship. In this case, we mean the nearness in space on proximity.


Program code

Program code
Figure 2 - Program code that measures distance with IR sensor

Step-by-step guide

STEP 1: Preparations

After you have connected the Dozer to Ozeki 10, you can start programming. Open SNAP in Ozeki 10 and put a 'when green flag clicked' block down. The next block is 'forever' (see Figure 3). It is an infinite loop which means it will not stop executing the encapsulated blocks again and again, only if you click on the stop button near to the green flag button. Inside the 'forever' block put a 'wait until X' block where X is a condition. The execution will be paused until the condition becomes true.

Figure 3 - The first part of the program

STEP 2: Measure the object's proximity

Put an 'X < X' block into the 'wait until X' block's condition part. Set an 'Object proximity [sensor]' block ([sensor] is a sensor that can measure distance, like IR sensor, select the robot's sensor from the list) as X and '8' as Y (Figure 4). The IR sensor expresses the proximity in percentage. In this case 8% means that the object is about 6.5 cm far from the sensor. If the distance between the object and the sensor is less than 6.5 cm the gripper must open.

Figure 4 - The 'Object proximity' block

STEP 3: Rotate the motor

The next block is a 'Rotate X by Y degrees' block (as you can see on Figure 5), where X is a motor (in this case select motor C) and Y is a degree value. You have to use 1080 degrees to open the gripper enough. So it will rotate motor B clockwise 1080 degrees. After that put a 'wait until X' block again with an 'X > Y' block. Put the same values into X and Y as in the previous one. So the program after opening the gripper will wait for removing the object from the IR sensor.

Figure 5 - Rotating the motor

STEP 4: Test the program

Finally put the last 'Rotate B by -1080 degrees' block down (Figure 6) You are done and ready to test it. Click on the green flag button, the program starts waiting an object to be near to the IR sensor. Put your hands or something near to the IR sensor and robot's gripper will be open. Then it will wait to remove the object, so put your hands or the object away from the sensor and motor B will be rotated by 1080 degrees counterclockwise, so the gripper will be closed.

Figure 6 - The complete program that grabs and releases objects

More information


Thank you for visiting this page