Skip to content

RoboKnight-INSAT/arduino-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Arduino-based robotic arm code for moving chess pieces

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.

Main Loop (loop())

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.

Code Components

1. Servo Setup

  • The robot uses 5 servos connected to pins {5, 6, 9, 10, 11}.

  • At startup, each servo moves to its default "initial" angle.

2. move() Function

  • 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 &currentAngle, int targetAngle)

3. home() Function

  • Resets the arm to a neutral "home" position after every move.

Getting Started: How to Run the Code

To run this project on your Arduino board:

  1. Clone the repository:

    git clone https://github.com/RoboKnight-INSAT/arduino-code.git
  2. Navigate to the project directory:

    cd robotic-chess-arm
  3. Open the .ino file in the Arduino IDE and connect your Arduino board.

  4. Select the correct board and port from the Tools menu.

  5. Upload the code to the board.

  6. Open the Serial Monitor (Ctrl + Shift + M) to send commands like 1:1|3:3.

What Happens When a Command Is Received

  1. Parse the move:
    The code extracts pos1 (start) and pos2 (end) from the received command.

  2. Reset Arm State:
    Before starting the move, the servos are gently brought back to their default angles.

  3. Go to pos1:
    The robot arm moves to the piece's current location.

  4. Pick up the piece:
    Servo 5 (gripper) closes to grab the piece.

  5. Go to pos2:

    • If pos2 is 0:0, the piece is dropped in a "box" position (i.e. captured).

    • Otherwise, the robot moves to the destination square.

  6. Drop the piece:
    The gripper opens.

  7. Go home:
    All servos return to the home position.

  8. Send "done" over Serial to notify that the move is complete.

Summary

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages