We made a device that would let you “high five” with another person anywhere in the world. If both persons move their hands towards the sensor, then the servo will raise a laser cut part into the air to signify a high five. After 2 seconds, the “hand” will lower and you can choose to high five again. It will only work when both people do the “high five” motion at around the same time. This is different from our original idea; it felt as if what we had done originally didn’t fit the assignment description so instead we decided that we wanted to detect the presence of a “high five” motion.

//By: Dillon Shu, Jack Rooney
//Sonar code by: Garth Zeglin
#include <Servo.h&gt;
const int TRIG_PIN = 9;
const int ECHO_PIN = 11;

const int MAX_DISTANCE = 450;

const long SOUND_SPEED = 34000;

const long TIMEOUT = (2 * MAX_DISTANCE * 1000000) / SOUND_SPEED;

int index = 0;
const int SERVO_PIN = 7;
float last_ten_inputs[10];

bool highFive = false;

int input = 0;
int output = 0;

int angle = 0;

float old_angle = 0;
Servo controlledServo;

void setup(void)
{
  Serial.begin(115200);
  pinMode(TRIG_PIN, OUTPUT);
  digitalWrite(TRIG_PIN, LOW);
  pinMode(ECHO_PIN, INPUT);

  controlledServo.attach(SERVO_PIN);
  controlledServo.write(0);
}

void loop()
{
  long duration = ping_sonar();

  float distance = -1;

  if (duration &gt; 0) {
    distance = (duration * 1e-6 * SOUND_SPEED) / 2;
    last_ten_inputs[index] = distance;
    index++;
  } 

  delay(30);
  float angle;

  if (index == 10)
  {

    index = 0;
    if (check_high_five())
    {
      highFive = true;
      output = 0;
      input = 0;
      Serial.end();
      Serial.begin(115200);
      while (highFive)
      {
        output = 1;
        Serial.println(1);
        if (Serial.available())
        {
          input = Serial.parseInt();
          Serial.find('\n');
        }
        if (output == 1 &amp;&amp; input == 1)
        {
          highFive = false;
          raiseHand();
          delay(2000);
          lowerHand();
          input = 0;

        }
        if (index == 10)
        {
          highFive = false;
        }
        index++;

        delay(1000);
      }
    }
    index = 0;
    output = 0;
  }
  delay(300);
}

void raiseHand()
{
  for (int i = angle; i < 30; i++)
  {
    controlledServo.write(i);
    delay(10);
  }
  angle = 30;
}

void lowerHand()
{
  for (int i = angle; i &gt; 0; i--)
  {
    controlledServo.write(i);
    delay(10);
  }
  angle = 0;
}
bool check_high_five()
{
  for (int i = 0; i < 8; i++)
  {

    if (!(last_ten_inputs[i + 1] - last_ten_inputs[i] < 1))
    {
      return false;
    }
  }

  if (last_ten_inputs[9] - last_ten_inputs[8] < 1 &amp;&amp; last_ten_inputs[0] - last_ten_inputs[9] &gt; 5)
  {
    return true;
  }
  return false;
}

long ping_sonar(void)
{
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  return pulseIn(ECHO_PIN, HIGH, TIMEOUT);
}