Skip to content

12. Mechanical design, machine design

Mechanical Design (part 1 of 2)

Group assignment:

Design a machine that includes mechanism + actuation + automation + application

Build the mechanical parts and operate it manually.

Document the group project and your individual contribution

Machine Design (part 2 of 2)

Group assignment:

Actuate and automate your machine.

Document the group project your individual contribution.

Control Code

#include <Servo.h>

Servo servoMetal;
Servo servoNoMetal;

int pos01 = 0;
int pos02 = 0;
int espera = 20;

// push button number
int ButtonStepForward = 2;
int ButtonStepReverse = 3;
int ButtonServoMetal = 4;
int ButtonServoNoMetal = 5;

// Stepper Motor Coil
int Coil01 = 6;
int Coil02 = 7;
int Coil03 = 8;
int Coil04 = 9;
// Servomotor Control
int ServoMetal = 10;
int ServoNoMetal = 11;


void setup() {
  // put your setup code here, to run once:

  pinMode(ButtonStepForward,INPUT);
  pinMode(ButtonStepReverse,INPUT);
  pinMode(ButtonServoMetal,INPUT);
  pinMode(ButtonServoNoMetal,INPUT);
  pinMode(Coil01,OUTPUT);
  pinMode(Coil02,OUTPUT);
  pinMode(Coil03,OUTPUT);
  pinMode(Coil04,OUTPUT);
  servoMetal.attach(ServoMetal);
  servoNoMetal.attach(ServoNoMetal); 
}

void loop() {
  // put your main code here, to run repeatedly:
  if(!digitalRead(ButtonStepForward)){
    digitalWrite(Coil01,LOW);
    digitalWrite(Coil02,HIGH);
    digitalWrite(Coil03,HIGH);
    digitalWrite(Coil04,LOW);
    delay(espera);
    digitalWrite(Coil01,LOW);
    digitalWrite(Coil02,LOW);
    digitalWrite(Coil03,HIGH);
    digitalWrite(Coil04,HIGH);
    delay(espera);
    digitalWrite(Coil01,HIGH);
    digitalWrite(Coil02,LOW);
    digitalWrite(Coil03,LOW);
    digitalWrite(Coil04,HIGH);
    delay(espera);
    digitalWrite(Coil01,HIGH);
    digitalWrite(Coil02,HIGH);
    digitalWrite(Coil03,LOW);
    digitalWrite(Coil04,LOW);
    delay(espera);
  }
  if(!digitalRead(ButtonStepReverse)){
    digitalWrite(Coil01,HIGH);
    digitalWrite(Coil02,HIGH);
    digitalWrite(Coil03,LOW);
    digitalWrite(Coil04,LOW);
    delay(espera);    
    digitalWrite(Coil01,HIGH);
    digitalWrite(Coil02,LOW);
    digitalWrite(Coil03,LOW);
    digitalWrite(Coil04,HIGH);
    delay(espera);
    digitalWrite(Coil01,LOW);
    digitalWrite(Coil02,LOW);
    digitalWrite(Coil03,HIGH);
    digitalWrite(Coil04,HIGH);
    delay(espera);
    digitalWrite(Coil01,LOW);
    digitalWrite(Coil02,HIGH);
    digitalWrite(Coil03,HIGH);
    digitalWrite(Coil04,LOW);
    delay(espera);
  }
  if(digitalRead(ButtonServoMetal)){
    for (pos01 = 90; pos01 >= 0; pos01 -= 1) {
      servoMetal.write(pos01);
      delay(15);
    }
    for (pos01 = 0; pos01 <= 90; pos01 += 1) {
      servoMetal.write(pos01);
      delay(15);
    }
  }
  if(digitalRead(ButtonServoNoMetal)){
    for (pos02 = 80; pos02 >= 0; pos02 -= 1) {
      servoNoMetal.write(pos02);
      delay(15);
    }   
    for (pos02 = 0; pos02 <= 80; pos02 += 1) {
      servoNoMetal.write(pos02);
      delay(15);
    }
  }
}