The Trickster

With this open-ended prompt, we decided to create a mechanic arm-like system that would offer an object to it’s user. The catch, however, is that when the user would reach out to retrieve the object, an analog, ultrasonic sensor would be activated and in turn would cause the arm to move away from the person reaching. This deceptive game can play out in a continuous loop until the user figures out that they can retrieve the object by reaching behind the sensor’s range to sneak it out of the arm. A passive movement of a ticking rotation ensues when there is no sensed movement by the arm. As a fun extra gesture, the arm is made from white board mdf, allowing us to write “Take Me” on the bot to signal to unaware users that the arm is tempting them to grab the object, all-the-while knowing they won’t easily be able to.

 

Video: https://youtu.be/H3GOLYMy3Lk

Solidworks: Demo 5

Code: 

 #include <Servo.h> 
int trigPin = 11;   
int echoPin = 12;    
long duration, cm, inches;
long pre = 0;
int servoPin = 6; 
long velocity;
int direction = 5;
int destination = 0;
Servo Servo1; 
int count = 0;
 
void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Servo1.attach(servoPin); 
  Servo1.write(0); 
}
 
void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
 
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
 
  cm = (duration/2) / 29.1; 
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  if (pre != 0 && cm < 30){
    velocity = pre - cm;
    if (velocity > 8 && count > 10){
      direction = -direction;
      count = 0;
    }
    if (velocity < -8 && count > 10){
      direction = -direction;
      count = 0;
    }
  }
  Serial.print("velocity");
  Serial.println(velocity);
  pre = cm;
  if (destination > 180){
    direction = -5;
  }
  if (destination < 0){
    direction = 5;
  }
  destination = destination + direction;
  Servo1.write(destination);
  count = count + 1;
  
  delay(250);
}