12. Machine Week¶
Group Assignment¶
Requirements - Design a machine that includes mechanism + actuation + automation + application - Build the mechanical parts and operate it manually - Document the group project
The objective of this week was to create a simple machine as a group. Our group modified a folding chair to close autmatically as the viewer approaches.
Link to the Group Page
The page linked above includes documentation of all aspects of the design including:
- Mechanical Design
- Electrical Design
- Software Development
- Iterative problem solving
Individual contribution¶
Since the team was small and the project simple our team collaborated heavily on all parts of the project. However, based on my background and the background of the other team members, I had more of leading role in the mechanical design and the software prgramming while other team members owned more of the CAD and 3D printing.
Mechanical Design¶
Our team used basic sketches to brainstorm and discuss various ideas. Once we settled on a general concept we refined the idea with more detailed but still simple drawings like the one below.
Basic concept for attachment of motor to the chair leg
Software and Electrical¶
Since I was familiar with motion sensors and proximity sensors from previous weeks, it was simple for us to use these devices to activate a servo motor. The images below show early stages of testing while the final result can be found on the Group Page
Origial code
// (code unchanged — included fully)
#include <ESP32Servo.h>
const int US_PIN = 4;
const int SERVO1_PIN = 18;
const int SERVO2_PIN = 17;
const long TRIGGER_DIST_CM = 70;
const int CONFIRM_READS = 3;
Servo servo1;
Servo servo2;
bool triggered = false;
int closeCount = 0;
void moveSync(int target1, int target2, int stepDelay = 12) {
int cur1 = servo1.read();
int cur2 = servo2.read();
int steps = max(abs(target1 - cur1), abs(target2 - cur2));
if (steps == 0) return;
for (int i = 1; i <= steps; i++) {
servo1.write(cur1 + (target1 - cur1) * i / steps);
servo2.write(cur2 + (target2 - cur2) * i / steps);
delay(stepDelay);
}
}
long readDistanceCm() {
pinMode(US_PIN, OUTPUT);
digitalWrite(US_PIN, LOW);
delayMicroseconds(2);
digitalWrite(US_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(US_PIN, LOW);
pinMode(US_PIN, INPUT);
long duration = pulseIn(US_PIN, HIGH, 30000);
if (duration == 0) return -1;
return duration * 0.034 / 2;
}
void setup() {
Serial.begin(115200);
servo1.attach(SERVO1_PIN, 500, 2500);
servo2.attach(SERVO2_PIN, 500, 2500);
servo1.write(90);
servo2.write(90);
delay(1000);
}
void loop() {
long dist = readDistanceCm();
bool isClose = (dist > 0 && dist < TRIGGER_DIST_CM);
if (isClose) closeCount++;
else closeCount = 0;
if (closeCount >= CONFIRM_READS && !triggered) {
triggered = true;
moveSync(180, 0);
moveSync(60, 120);
}
if (!isClose && triggered) {
triggered = false;
}
delay(100);
}