The objective of the machine is to indicate whether or not your friend is at their desk at the same time as you are at yours. If you and your friend are both at your desks, the motor will rotate so that the face is smiling. If either or both of you leave, the face will frown again. When both you and your friend are at your desk, you can FaceTime or Zoom each other and keep each other company while you work. We changed our idea because we felt that the smile or frown was more expressive and personable. To make our design less sporadic, we filtered the data using the median method. This ruled out some of the outliers that the sensor would produce. Overall, we think this was more effective than our original idea, and the filter makes our motor less twitchy and distracting.
// initialize pins const int TRIG = 8; const int ECHO = 7; // distance variables int dur; int dis; int amal; const int MAX_DISTANCE = 450; const long SOUND_SPEED = 34000; const long TIMEOUT = (2 * MAX_DISTANCE * 1000000) / SOUND_SPEED; // for median filter int old = 0; int curr = 0; #include <Servo.h> Servo srv; void setup() { Serial.begin(115200); pinMode(TRIG, OUTPUT); digitalWrite(TRIG, LOW); pinMode(ECHO, INPUT); srv.attach(3); srv.write(0); } void loop() { digitalWrite(TRIG, HIGH); delayMicroseconds(10); digitalWrite(TRIG, LOW); dur = pulseIn(ECHO, HIGH, TIMEOUT); if (dur > 0) { int next = (dur * .034) / 2; Serial.print("next:"); Serial.println(next); dis = filter(old, curr, next); old = curr; curr = next; Serial.print("med:"); Serial.println(dis); if (Serial.available()) { amal = Serial.parseInt(); Serial.find('\n'); } // both people are at their desks if (dis <= 20 && dis >= 0 && amal <= 20 && amal >= 0) { // face smiles srv.write(180); } // someone leaves/both leave else { // face frowns srv.write(0); } } else { srv.write(0); } delay(100); } // filters outliers by taking the median value of the 3 most recent values // compares the current value with the last value and next value // checks which value is in the middle int filter(int old, int curr, int next) { int med; if ((old <= curr && old >= next) || (old >= curr && old <= next)) { med = old; } else if ((curr <= old && curr >= next) || (curr >= old && curr <= next)) { med = curr; } else { med = next; } return med; }
Leave a Reply
You must be logged in to post a comment.