01 Robotic Gripper Control
01 Robotic Gripper Control
In this section, you can learn to detect the distance of obstacle through glowing
ultrasonic module. The opening and closing of the robotic gripper can be
controlled simultaneously.
1. Program Flowchart
2. Ultrasonic Sensor
1
3. Program Download
Note
Remove the Bluetooth module before downloading the program. Or the program will
Please switch the battery box to the ‘OFF’ when connecting the Type-B download
cable. This action prevents the download cable from accidentally touching the power pins
1) Locate and open “ultrasonic_claw” program file in the same directory of this
section.
3) Click “Select Board”, and the software will automatically detect the current
Arduino serial port. Next, click to connect.
2
4) Click to download the program into Arduino. Then just wait for it to
complete.
4. Program Outcome
When powering miniAuto on, the glowing ultrasonic sensor on it will measure
the distance to the obstacles and control the rotation angle of the servo
accordingly. The servo is mounted on the miniAuto’s robotic gripper. Rotate the
servo will drive the gripper to open and close.
3
5.1 Import Library File
Import the required library file of controlling the glowing ultrasonic sensor and
the servo for the game.
4
5.3 Initial Settings
In the “setup()” function, initialize the serial communication and set its baud
rate to 9600. Then, the servo connection is initialized. The value of “angle” is
passed as the rotation angle parameter to the servo. The servo rotates, driving
the robotic gripper to close.
5
2) When the distance is less than 80mm, the glowing ultrasonic sensor will be
a breathing light mode, showing red at a speed of 0.1s.
4) When the distance is 180 to 320mm, the glowing ultrasonic sensor will
display a blue light, with the color getting bluer as the distance increases.
5) When the distance is 320 to 500mm, the glowing ultrasonic sensor will
display a green light, with the color getting greener as the distance increases.
6) When the distance is greater than 500mm, the green LED on the glowing
ultrasonic sensor will be steady on.
6
5.6 Servo Control Function
Use an “if” statement to limit the maximum effective value of the distance to
500mm. Because the “map()” function will be used to map the current distance
(effective range: 0-500) to the servo rotation angle parameter (effective range:
0-80).
If the distance is greater than 500, it will result in an invalid “angle” parameter
due to mapping out of range.
After the “angle” is obtained, write it to the servo. The servo will rotate to drive
the robotic gripper to open and close. The closer the distance to the obstacle,
the more the robotic gripper closes, and vice versa.
7. FAQ
Q1:since the code was upload, the distance measured by the ultrasound is
always 0.
A:please check that you have connected the 4-pin cable to the I2C interface.
Q2:the distance measured by the ultrasonic sensor is sometimes accurate,
and sometimes inaccurate.
A:please use a smooth and flat object for distance measurement, and avoid
prolonged close-range detection of the obstacle.