Skip to content

10. Mechanical design, machine design

Group assignment:

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

  • Build the mechanical parts and operate it manually.

  • Actuate and automate your machine.

  • Document the group project

To see our group assignment click here

Individual assignment:

  • Document your individual contribution.

For this week we’ve built a machine that is a kibble dispenser for animals. Everyone has to document their contrubition to the project. I worked on the code, so follow me for more details.

Section 1: Header

/**
* -->DATE : 15/04/2024
*
* -->AUTEURS : DROH ET ANNICK
*
******************-->CAT FEEDER<--*********************
*
**/
This section provides metadata on the code, such as date and authors. These are multi-line comments used for code documentation.

Section 2: Inclusion of libraries

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
This section includes the libraries needed for the project. The Wire library is used for I2C communication, while LiquidCrystal_I2C is used to control the LCD screen in I2C mode.

Section 3: Declaration of variables and constants

int latency_time, Dispenser, j;
int screenMessage = 0;
boolean system_activated = false;
boolean activate_system = false;
This section declares different variables and constants used in the program. Some are counters (latency_time, Dispenser, j), others are flags (screenMessage, system_activated, activate_system) used to control the program flow.

Section 4: Pins and Constants Definition

#define LCD_ADDR    0x27
#define COL         16
#define ROW         2

#define MOTOR_ENA   12
#define MOTOR_IN1   11
#define MOTOR_IN2   10

#define PIN_BUZZER  9
#define DelPin      4

const int buttonPins[] = {2, 3};
const char buttonChars[] = {'A', 'B'};

This section defines the I2C addresses of the LCD screen, as well as the pins used to control the motor, buzzer, LED, and buttons. Constants are also defined for the button pins and the characters associated with each button.

Section 5: Initialization in the setup() function

void setup() {
  Serial.begin(115200);   
  lcd.init();
  lcd.begin(16, 2);
  pinMode(MOTOR_ENA, OUTPUT);
  pinMode(MOTOR_IN1, OUTPUT);
  pinMode(MOTOR_IN2, OUTPUT);
  pinMode(PIN_BUZZER, OUTPUT);
  pinMode(DelPin, OUTPUT);
  for (int j = 0; j < 2; j++) {
    pinMode(buttonPins[j], INPUT_PULLUP);
  }
}
This section runs only once at the start of the microcontroller. It initializes the serial communication, the LCD screen, the motor pins, buzzer, LED, and buttons as either outputs or inputs, depending on the requirement.

Section 6: Main loop function in the loop() function

void loop() {
  if (activate_system) {
    //...
  }
  if (system_activated == true) {
    //...
  }
  if (!system_activated) {
    //...
  }
}
This section represents the main loop of the program. It checks if the system should be activated, if the system is already activated, or if the system is deactivated, and acts accordingly.

Each if(){} else if(){} else if(){} block contains different logic based on flags and button inputs.

Section 7: Additional Functions

void getTime() {
  //...
}
void actionA() {
  //...
}
void actionB() {
  //...
}
void flashLED() {
  //...
}

This section contains definitions of functions used in the main loop to perform specific tasks, such as food distribution, button management, and LED blinking.


Last update: May 14, 2024