Mechanical Design, Machine Design

This week will be full of challenges as we will build a machine.

The assignment Mechanical Design was:

Group assignment: Design a machine that includes mechanism+actuation+automation+application. Build the mechanical parts and operate it manually. Document the group project

Individual assignment: Document your individual contribution.

The assignment Machine Design was:

Group assigment: Actuate and automate your machine. Document the group project.

Individual assignment: Document your individual contribution.

Group assignment

After meeting and planning what we would do, here we present our final presentation sheet, where we show all the processes used in the assignment.

You can see the documentation on the group's web page

We present the video of the assignment, the musical background is a song by a well-known Peruvian singer-songwriter named Guiller and the song is titled El rey de las cantinas. This type of songs in Peru is called boleros cantineros.

Individual assignment

I was in charge of developing the code for the operation of the machine.

Write code for the first spin test of the nema 17 motor connected to the Shield V3. controlled by the Arduino Uno

                            
        #define x_paso 2    // Set the STEP Pin for X Axis Motor
        #define x_dire 5    // Set the DIR Pin for X Axis Motor
        #define x_habi 8    // Set the ENABLE Pin for X Axis Motor

        int retardo = 3000;   // Lower number the turn is faster
        int tiempo = 100;   // How long does the motor rotate (turns)

        void setup() {
        pinMode(x_paso, OUTPUT); pinMode(x_dire, OUTPUT); pinMode(x_habi, OUTPUT);     

        }    

        void loop() {
        giro(x_paso,x_dire,x_habi);
        
        }

        void giro(int paso_,int dire_,int habi_) {
        digitalWrite(habi_, LOW);  // Enable the Driver
        digitalWrite(dire_, LOW);   // turning direction 1
        for(int i=0;i<tiempo;i++){  // take steps for a while
            digitalWrite(paso_, HIGH);      
            delayMicroseconds(retardo);          
            digitalWrite(paso_, LOW);       
            delayMicroseconds(retardo); 
        }
        digitalWrite(dire_, HIGH);   // turning direction 2
        for(int i=0;i<tiempo;i++){   // take steps for a while
            digitalWrite(paso_, HIGH);      
            delayMicroseconds(retardo);          
            digitalWrite(paso_, LOW);       
            delayMicroseconds(retardo);  
        }
        digitalWrite(habi_, HIGH);   // remove driver enablement

        delay(1000);
        }
                        

Result of the first programming test.

Write code for the movement of the platform in the X axis that will carry the glass to serve the drinks.

    #define x_paso 2 // Set the STEP Pin for X Axis Motor
    #define x_dire 5 // Set the DIR Pin for X Axis Motor
    #define x_habi 8 // Set the ENABLE Pin for X Axis Motor
    #define x_limite 9 // Set the Movement Limit Pin
    
    int retardo = 1000; // Delay between steps in microseconds
    int pasos_por_segundo = 500; // Number of steps per second (motor speed)
    unsigned long tiempo_avance_1 = 6000; // Initial advance time in milliseconds
    unsigned long tiempo_parada_1 = 5000; // Initial wait time in milliseconds
    unsigned long tiempo_avance_2 = 12000; // Second advance time in milliseconds
    unsigned long tiempo_parada_2 = 5000; // Second wait time in milliseconds
    unsigned long tiempo_avance_3 = 11000; // Third advance time in milliseconds
    unsigned long tiempo_parada_3 = 5000; // Third hold time in milliseconds
    unsigned long tiempo_avance_4 = 2000; // Quarter advance time in milliseconds
    unsigned long tiempo_parada_4 = 10000; // Fourth wait time in milliseconds
    unsigned long tiempo_retroceso = 31000; // Rollback time in milliseconds
    
    void setup() {
        pinMode(x_paso, OUTPUT);
        pinMode(x_dire, OUTPUT);
        pinMode(x_habi, OUTPUT);
        pinMode(x_limite, INPUT_PULLUP); // Configure move limit pin as input with pull-up resistor
        Serial.begin(9600); // Initialize serial communication
        Serial.println("Use the 's' command to start the movement.");
    }
    
    void loop() {
        if (Serial.available() > 0) {
        char comando = Serial.read();
        if (comando == 's') {
            iniciarMovimiento();
        }
        }
    }
    
    void iniciarMovimiento() {
        // Advance for 6 seconds
        avanzar(tiempo_avance_1);
        
        // Wait for 5 seconds
        delay(tiempo_parada_1);
        
        // Advance for 12 seconds
        avanzar(tiempo_avance_2);
        
        // Wait for 5 seconds
        delay(tiempo_parada_2);
        
        // Advance for 11 seconds
        avanzar(tiempo_avance_3);
        
        // Wait for 5 seconds
        delay(tiempo_parada_3);
        
        // Advance for 2 seconds
        avanzar(tiempo_avance_4);
        
        // Wait for 10 seconds
        delay(tiempo_parada_4);
        
        // Rollback for 31 secondss
        retroceder(tiempo_retroceso);
    }
    
    void avanzar(unsigned long tiempo) {
        digitalWrite(x_dire, LOW); // Set forward direction
        digitalWrite(x_habi, LOW); // Enable the engine
        unsigned long tiempo_inicio = millis();
        while (millis() - tiempo_inicio < tiempo) {
        digitalWrite(x_paso, HIGH);
        delayMicroseconds(1000000 / pasos_por_segundo);
        digitalWrite(x_paso, LOW);
        delayMicroseconds(1000000 / pasos_por_segundo);
        }
        digitalWrite(x_habi, HIGH); // Disable the engine
    }
    
    void retroceder(unsigned long tiempo){
        digitalWrite(x_dire, HIGH); // Set backward direction
        digitalWrite(x_habi, LOW); // Enable the engine
        unsigned long tiempo_inicio = millis();
        while (millis() - tiempo_inicio < tiempo) {
        digitalWrite(x_paso, HIGH);
        delayMicroseconds(1000000 / pasos_por_segundo);
        digitalWrite(x_paso, LOW);
        delayMicroseconds(1000000 / pasos_por_segundo);
        }
        digitalWrite(x_habi, HIGH); // Disable the engine
                            
                        

Result of the movement of the platform will carry the glass to serve the drinks.

Write code so that the ultrasound sensor detects the glass, activates the water pump for a set time and stops.

We use the Xiao RP2040 microcontroller and manufacture a custom PCB board for each of our components.

    #define TRIG_PIN_2 7 // Trig pin definition for ultrasound sensor 2
    #define ECHO_PIN_2 0 // Echo pin definition for ultrasound sensor 2
    #define TRIG_PIN_3 2 // Trig pin definition for ultrasound sensor 3
    #define ECHO_PIN_3 1 // Echo pin definition for ultrasound sensor 3
    #define TRIG_PIN_1 29 // Trig pin definition for ultrasound sensor 1
    #define ECHO_PIN_1 6 // Echo pin definition for ultrasound sensor 1

    void setup() {
    Serial.begin(9600);           // Initialize serial communication at 9600 baud
    pinMode(TRIG_PIN_1, OUTPUT);  // Set sensor 1 trig pin as output
    pinMode(ECHO_PIN_1, INPUT);   // Set sensor 1 echo pin as input
    pinMode(TRIG_PIN_2, OUTPUT);  // Set sensor 2 trig pin as output
    pinMode(ECHO_PIN_2, INPUT);   // Set sensor 2 echo pin as input
    pinMode(TRIG_PIN_3, OUTPUT);  // Set sensor 3 trig pin as output
    pinMode(ECHO_PIN_3, INPUT);   // Set sensor 3 echo pin as input
    }

    void loop() {
    // Read the first ultrasound sensor
    long duration_1, distance_1;
    digitalWrite(TRIG_PIN_1, LOW);
    delayMicroseconds(2);
    digitalWrite(TRIG_PIN_1, HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG_PIN_1, LOW);
    duration_1 = pulseIn(ECHO_PIN_1, HIGH);
    distance_1 = duration_1 * 0.034 / 2;

    // Read the second ultrasound sensor
    long duration_2, distance_2;
    digitalWrite(TRIG_PIN_2, LOW);
    delayMicroseconds(2);
    digitalWrite(TRIG_PIN_2, HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG_PIN_2, LOW);
    duration_2 = pulseIn(ECHO_PIN_2, HIGH);
    distance_2 = duration_2 * 0.034 / 2;

    // Read the third ultrasound sensor
    long duration_3, distance_3;
    digitalWrite(TRIG_PIN_3, LOW);
    delayMicroseconds(2);
    digitalWrite(TRIG_PIN_3, HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIG_PIN_3, LOW);
    duration_3 = pulseIn(ECHO_PIN_3, HIGH);
    distance_3 = duration_3 * 0.034 / 2;

    // Print the distances measured on the serial port
    Serial.print("Sensor distance 1: ");
    Serial.print(distance_1);
    Serial.println(" cm");
    Serial.print("Sensor distance 2: ");
    Serial.print(distance_2);
    Serial.println(" cm");
    Serial.print("Sensor distancer 3: ");
    Serial.print(distance_3);
    Serial.println(" cm");

    // Wait 1 second before taking another reading
    delay(1000);
    }

                        

This is the result seen when the ultrasound sensor is activated and the water pump is activated.

Download files

Here we can find and download the design original files