Unpredictable Behavior From Servo Motor

To preface my post, I have been developing an AI-controlled robotic arm for the past few months.

A major roadblock has been the behavior of the servo motors. Although the code compiles, in practice, the motors act erratically. Below, I have attached a video that demonstrates how one servo motor behaves when the program runs.

Essentially, the program reads a string of characters formatted "$00000" into the Arduino UNOs serial port. The dollar sign is used simply for the sake of readability and to ensure that the numbers being fed into the Arduino correspond to the proper finger. In the string, the numbers represent whether the finger is opened (1) or closed (0) and the finger itself, with the leftmost number representing the thumb and the rightmost representing the pinky. If there is a change, the servo motor will either turn 180 degrees clockwise or counterclockwise.

The Artificial Intelligence component works as intended since when the motor was tested using the serial monitor in the Arduino IDE, the motor still exhibited the same unpredictable behavior. I have copied the Arduino code below.

I'm lost at this point. I'm not sure whether the issue is that there isn't enough power since the only source would be the laptop which supports both the Arduino and its shield (via USB). Perhaps I need an external battery or power supply. I'm starting to think it could be the servo motor itself, but then again maybe my code is to blame. Anyways, if anybody has any clue, let me know! Any help is much appreciated.

Link: IMG_5079.MOV - Google Drive

<-- Code -->

#include <Servo.h>

//servo for each individual finger
Servo thumbServo;
Servo indexServo;
Servo middleServo;
Servo ringServo;
Servo pinkyServo;

int vals[] = {0, 0, 0, 0, 0}; //array that stores whether the finger is open or closed
String stringReceived = ""; //stores the string received
int counter = 0;
void setup() {
  // put your setup code here, to run once:
  //initializes the serial
  Serial.begin(9600);
  thumbServo.write(0);
  thumbServo.attach(7);
  indexServo.write(0);
  indexServo.attach(8);
  middleServo.write(0);
  middleServo.attach(9);
  ringServo.write(0);
  ringServo.attach(10);
  pinkyServo.write(0);
  pinkyServo.attach(11);





}

void loop() {
  //Serial.println(Serial.available());
  if (Serial.available() > 0) {
    char c = Serial.read();
    if (counter <= 5) {
      if (counter == 0) {
        stringReceived += "";
      }
      else {
        stringReceived += String(c);
      }
      counter++;
    }
    else {
      counter = 1;
      stringReceived = "";
    }
    if (counter == 6) {
      for (int i = 0; i < 5; i++) {

        vals[i] = stringReceived.substring(i, i + 1).toInt();
        Serial.print("Index: " + String(i) + " " + vals[i]);
        Serial.print("\n");
      }

      /* Thumb Servo */
      if (vals[0] == 1) {
        thumbServo.write(180);
        delay(17);
        Serial.print("Success");
      }
      else if (vals[0] == 0) {
        thumbServo.write(0);
        delay(17);
        Serial.print("Success");
      }
      /*Index Servo */
      if (vals[1] == 1) {
        indexServo.write(180);
        delay(17);
        Serial.print("Success");
      }
      else if (vals[1] == 0) {
        indexServo.write(0);
        delay(17);
        Serial.print("Success");
      }
      /*Middle Servo */
      if (vals[2] == 1) {
        middleServo.write(180);
        delay(17);
        Serial.print("Success");
      }
      else if (vals[2] == 0) {
        middleServo.write(0);
        delay(17);
        Serial.print("Success");
      }
      /*Ring Servo */
      if (vals[3] == 1) {
        ringServo.write(180);
        delay(17);
        Serial.print("Success");
      }
      else if (vals[3] == 0) {
        ringServo.write(0);
        delay(17);
        Serial.print("Success");
      }
      /*Pinky Servo */
      if (vals[4] == 1) {
        pinkyServo.write(180);
        delay(17);
        Serial.print("Success");
      }
      else if (vals[4] == 0) {
        pinkyServo.write(0);
        delay(17);
        Serial.print("Success");
      }
      Serial.println("String Received: " + stringReceived);
    }

  }
}

I would bet on that.

How do you distinguish one "Success" from another?

I am surprised that you have not measured the voltage at each servo as it moves.