Brainstorming and Implementation

For our project, we wanted to make two identical turtle robots with wheel motors to move toward each other. When they touch, their wheel motors stop and they move their flippers (because they are happy to see each other!).

However, we faced many issues. For one, we had to balance the turtles on one wheel. We tried to achieve as such by adding weights on the sides and the back of the turtle. We also could not reduce the speed of the motor below 255 pwn. This made it difficult to control the turtles. Additionally, the DC motor for our second turtle stopped working, so we could only move one turtle. Lastly, our moving turtle does not move in a straight line.

All of these issues made us adjust our project heavily. We place the turtles close together to avoid the moving turtle from rotating. Second, we have to hold the second turtle up to ensure the two buttons make contact. Below are files, a video demo, and the code.

Code

Servo servo1;
Servo servo2;

int servoPos = 80;
int buttonState = 0;

void setup() {
  Serial.begin(9600);
  servo1.attach(5);
  servo2.attach(6);

  pinMode(buttonPin, INPUT);

  pinMode(MOT_A1_PIN, OUTPUT);
  pinMode(MOT_A2_PIN, OUTPUT);

  digitalWrite(MOT_A1_PIN, LOW);
  digitalWrite(MOT_A2_PIN, LOW);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  Serial.println(buttonState);
  if(buttonState != HIGH)
  {
    digitalWrite(MOT_A1_PIN, LOW);
    analogWrite(MOT_A2_PIN, 255);  //spin at 255 pwm
  }
  else
  {
    digitalWrite(MOT_A1_PIN, LOW);
    analogWrite(MOT_A2_PIN, 0);  //stop
   
    while(buttonState == HIGH)
    {

    if (servoPos == 80)       // move both servos up and down (move flippers)
    {
    servo1.write(180);
    servo2.write(180);
    servoPos = 180;
    delay(500);
    }
    else
    {
      servo1.write(80);
      servo2.write(80);
      servoPos = 80;
      delay(500);
    }
    buttonState = digitalRead(buttonPin);
    }
  }
}