Interactive Arcade-Style Claw Machine Built with VEX Robotics
A functional claw machine game built using VEX Robotics components and programmed for precise control and user interaction.
Custom-designed claw mechanism with adjustable grip strength.
Button interface for X, Y, Z axes and drop action.
L298 H-bridge drives on three axes with PWM speed control.
If/else logic coordinates motion and servo-based claw open/close.
#include <Servo.h>
// === Pin Definitions ===
// Buttons (wired with pull-down resistors)
const int btnLeftPin = 2;
const int btnRightPin = 3;
const int btnForwardPin = 4;
const int btnBackPin = 5;
const int btnDropPin = 6;
// Motor driver pins (L298-style H-bridge)
const int xDirPin = 7; // X-axis direction
const int xPwrPin = 9; // X-axis PWM (enable)
const int yDirPin = 8; // Y-axis direction
const int yPwrPin = 10; // Y-axis PWM
const int zDirPin = 11; // Z-axis (vertical) direction
const int zPwrPin = 12; // Z-axis PWM
// Servo for claw open/close
const int clawServoPin = 13;
Servo clawServo;
// Claw positions
const int CLAW_OPEN_POS = 0; // degrees
const int CLAW_CLOSED_POS = 90; // degrees
void setup() {
// Configure button inputs
pinMode(btnLeftPin, INPUT);
pinMode(btnRightPin, INPUT);
pinMode(btnForwardPin, INPUT);
pinMode(btnBackPin, INPUT);
pinMode(btnDropPin, INPUT);
// Configure motor outputs
pinMode(xDirPin, OUTPUT);
pinMode(xPwrPin, OUTPUT);
pinMode(yDirPin, OUTPUT);
pinMode(yPwrPin, OUTPUT);
pinMode(zDirPin, OUTPUT);
pinMode(zPwrPin, OUTPUT);
// Initialize motors off
analogWrite(xPwrPin, 0);
analogWrite(yPwrPin, 0);
analogWrite(zPwrPin, 0);
// Attach and initialize claw servo
clawServo.attach(clawServoPin);
clawServo.write(CLAW_OPEN_POS);
Serial.begin(9600);
}
void loop() {
// Read buttons (HIGH when pressed)
bool left = digitalRead(btnLeftPin);
bool right = digitalRead(btnRightPin);
bool forward = digitalRead(btnForwardPin);
bool back = digitalRead(btnBackPin);
bool drop = digitalRead(btnDropPin);
// X-axis control
if (left) {
digitalWrite(xDirPin, LOW); // direction: left
analogWrite(xPwrPin, 200); // speed (0–255)
}
else if (right) {
digitalWrite(xDirPin, HIGH); // direction: right
analogWrite(xPwrPin, 200);
}
else {
analogWrite(xPwrPin, 0); // stop X-axis
}
// Y-axis control
if (forward) {
digitalWrite(yDirPin, LOW); // direction: forward
analogWrite(yPwrPin, 200);
}
else if (back) {
digitalWrite(yDirPin, HIGH); // direction: back
analogWrite(yPwrPin, 200);
}
else {
analogWrite(yPwrPin, 0); // stop Y-axis
}
// Z-axis (vertical) always moves when drop button is held
if (drop) {
// Lower claw to pick up
digitalWrite(zDirPin, LOW);
analogWrite(zPwrPin, 200);
} else {
// Raise claw back up
digitalWrite(zDirPin, HIGH);
analogWrite(zPwrPin, 200);
}
// Claw open/close action when drop is pressed
if (drop) {
clawServo.write(CLAW_CLOSED_POS);
} else {
clawServo.write(CLAW_OPEN_POS);
}
delay(10); // Debounce & loop pacing
}