I created a motorized tea bag dipper. I utilized a stepper motor and a sonar sensor to test when the tea cup was within 3 inches of the sonar sensor. The stand for the motor was laser cut along with the moving mechanism that drives the tea bag up and down. Joints were cut into the pieces so no additional screws or things of that nature were used (covering for acrylic was kept on to provide a tighter fit so no plastic weld was needed). I accommodated for the tea string looping back and forth by making the stepper motor move back and forth. Unfortunately, I was not able to set the surface mount potentiometer correctly (set too high, shorted out my computer), so the stepper motor is not able to move for longer than 15-20 seconds without pausing in order to cool down.


int vcc = 2; //attach pin 2 to vcc
int trig = 3; // attach pin 3 to Trig
int echo = 4; //attach pin 4 to Echo
int gnd = 5; //attach pin 5 to GND
#include <AccelStepper.h>
AccelStepper stepper(1,3,2); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
void setup() {
 pinMode (vcc,OUTPUT);
 pinMode (gnd,OUTPUT);
 Serial.begin(9600);
 stepper.setMaxSpeed(100);
 stepper.setAcceleration(20);
}

void loop()
{
 digitalWrite(vcc, HIGH);
 long duration, inches, cm;
 pinMode(trig, OUTPUT);
 digitalWrite(trig, LOW);
 delayMicroseconds(2);
 digitalWrite(trig, HIGH);
 delayMicroseconds(5);
 digitalWrite(trig, LOW);
 pinMode(echo,INPUT);
 duration = pulseIn(echo, HIGH);
 inches = microsecondsToInches(duration);
 Serial.print(inches);
 Serial.print("in, ");
 Serial.println();
 if (inches > 2)
 stepper.moveTo(500);
 stepper.moveTo(-500);
 if (inches < 3) stepper.stop();
 delay(100);
}
long microsecondsToInches(long microseconds)
{
 return microseconds / 74 / 2;
}

<code>