For my mechanism I created an actuated arm that moves using a stepper motor and gives you a “fist bump” if you get close to it (under 10 cm) By making the scaffolding / support out of clear acrylic, I was able to make the arm look somewhat similar to a real arm. This robot will never leave you hanging!

I brought in the code from Stepper Sweep and wove it in with the Read Sonar sketch for the ultrasonic sensor.

The most important few lines of code are these:

 unsigned int msec = wait_time / 700;
 unsigned int usec = wait_time - (700*msec);

which I used to lower the stepping speed from the default, and

if(distance < 10){
rotate_stepper( 20, 25.0);
rotate_stepper( -20, 25.0);
}

which rotates the motor forward and backwards to let the robot come forward and “fist bump” you.