PRO
RoboHappy
USA
Asked
New gripper control - help needed
I still need help controlling each gripper using both its IR sensor and a lever switch to detect when the gripper has closed.
I'm running this as ARC built-in JavaScript on an EZB (the script uses ADC channels and servo ports). The code I have so far:
var rightGripperServo = v9;
var leftGripperServo = v25;
var rightIr = ADC1;
var leftIr = ADC2;
var rightLever = ADC6;
var leftLever = ADC7;
var closeSpeed = 10; // 0 = fastest, 10 = slowest
function closeRightGripperOnIR() {
while (true) {
ADC.waitForLower(rightIr, 35);
print("Right IR detected object. Closing gripper...");
Servo.setSpeed(rightGripperServo, closeSpeed);
Servo.setPosition(rightGripperServo, 1);
while (ADC.get(rightLever) != 0) {
sleep(20);
}
print("Right object now gripped");
// Keep holding - do NOT release servo
Servo.setSpeed(rightGripperServo, 0);
}
}
function closeLeftGripperOnIR() {
while (true) {
ADC.waitForLower(leftIr, 35);
print("Left IR detected object. Closing gripper...");
Servo.setSpeed(leftGripperServo, closeSpeed);
Servo.setPosition(leftGripperServo, 1);
while (ADC.get(leftLever) != 0) {
sleep(20);
}
print("Left object now gripped");
// Keep holding - do NOT release servo
Servo.setSpeed(leftGripperServo, 0);
}
}
// closeGrippersSlowUntilSwitch();
Can you make separate scripts for each gripper?
Desired behavior for either the left or right gripper:
- Open the gripper via a speech command (using ARC speech recognition Robot Skill).
- The gripper finds the object to grab via its IR detector.
- The gripper begins to close slowly onto the object.
- The object presses the lever switch.
- The servo stops but continues holding the object. The gripper will continue to hold the object until told to release it.
Thanks!
Related Hardware (view all EZB hardware)
EZ-B V4
by EZ-Robot
EZ-B v4/2 robot controller: dual Cortex ARM, Wi-Fi, audio/video, 24 servo/digital ports, I2C/UART, camera and Synthiam ARC control for custom robots
Wi-Fi / USB
Servos
24
Camera
Audio
UART
3
I2C
ADC
8
Digital
24
Related Robot Skills (view all robot skills)
Movement Script
by Synthiam
Trigger direction-specific scripts when ARC movement panels change; assign scripts per direction/stop, access direction and speed (JS/Python/EZ).
Ultrasonic Distance
by Synthiam
Displays HC-SR04 ultrasonic distance readings in ARC; scriptable via GetPing(), pausable, sets a variable with multiplier, optional NMS output

Yes - it’s better to split this into two separate scripts, one for the right gripper and one for the left gripper. That keeps each gripper independent and easier to debug.
A couple of important fixes first:
ADC.get()should read the analog sensor port onlyDigital.get()instead ofADC.get()Right Gripper Script
Left Gripper Script
Notes
ADC6/ADC7to digital ports because a lever switch is typically an on/off input.v25for the left gripper servo. That’s fine if it’s a virtual servo port from a servo skill. If it is a physical EZ-B servo port, that would need to be changed.Open / Release behavior
You mentioned:
That usually means you want a separate release script for each gripper. For example:
and similarly for the left gripper.
Best ARC setup
If you’re using speech recognition in ARC:
"open right gripper""open left gripper""release right gripper""release left gripper"If you want, I can help you make this into a cleaner structure with:
If you share:
v9andv25are definitely virtual servo portsI can tailor the scripts exactly to your grippers.
I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.