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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//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);
}