This code is written for an Arduino-based robotic arm that moves chess pieces on a physical board using 5 servos. The robot listens for commands over the Serial port and moves the piece from one square to another, or throws it in the box if it's captured.
The program continuously listens for movement commands via the Serial port. The format of the command is:
x1:y1|x2:y2
-
x1:y1
= source square -
x2:y2
= destination square
For example:
1:1|3:3
means move the piece from a1
to c3
.
-
The robot uses 5 servos connected to pins
{5, 6, 9, 10, 11}
. -
At startup, each servo moves to its default "initial" angle.
-
Smoothly moves a servo from its current angle to a target angle.
-
Adds a small delay for each step to ensure smooth motion.
void move(Servo &servo, int ¤tAngle, int targetAngle)
- Resets the arm to a neutral "home" position after every move.
To run this project on your Arduino board:
-
Clone the repository:
git clone https://github.com/RoboKnight-INSAT/arduino-code.git
-
Navigate to the project directory:
cd robotic-chess-arm
-
Open the
.ino
file in the Arduino IDE and connect your Arduino board. -
Select the correct board and port from the Tools menu.
-
Upload the code to the board.
-
Open the Serial Monitor (Ctrl + Shift + M) to send commands like
1:1|3:3
.
-
Parse the move:
The code extractspos1
(start) andpos2
(end) from the received command. -
Reset Arm State:
Before starting the move, the servos are gently brought back to their default angles. -
Go to
pos1
:
The robot arm moves to the piece's current location. -
Pick up the piece:
Servo 5 (gripper) closes to grab the piece. -
Go to
pos2
:-
If
pos2
is0:0
, the piece is dropped in a "box" position (i.e. captured). -
Otherwise, the robot moves to the destination square.
-
-
Drop the piece:
The gripper opens. -
Go home:
All servos return to the home position. -
Send "done" over Serial to notify that the move is complete.
This code allows the robotic arm to:
-
Receive move instructions via Serial communication
-
Move precisely to pick up and place a chess piece
-
Handle special cases like capturing a piece
-
Reset after each move to stay consistent