Skip to content

VII - ELECTRONIC AND CODE

Components.

Component Application
Esp32 of 38 pines Microcontroller, this will be the brain of the entire system, with which we can run the graphical interface in one core and the control and activation area in another core.
LCD 20x4 I2C With this screen you can view the control interface
Electric Motor 220v Single phase This will rotate and with the pulleys we will multiply the speed to 6000 rpm to perform the centrifugal effect with the PET resin.
Encoder This allows us to select machine actions and move through the interface
Max6675 temperature reader
Nema23 This will push on the extrusion area.
Leds Visual Indicator.
7805 Voltage regulator to 5v.
PCB terminal blocks Useful for connecting cables to the pcb

General Electronic connection

PCB Desing

Programs

Using proteus design the component connections as follows.

Proteus - Connections

Then dealing with the pcb design options import the components to a fiberglass copper board.

It's time to organize the components and start routing the connections, there is an option in Proteus which is AUTOROUTE, this helps the program find the most efficient way to route the connection tracks, it is not perfect so you have to do some manual adjustments.

Important information is that the tracks cannot be bent at 90 degrees, we must maintain a range of 45.

Proteus - PCB

As you can see the plate measures 92mm x 85 mm


Burn circuit on copper board

There are many methods to make PCB circuits.

  • Using a CNC with arrowhead milling cutters
  • Ironing method and ferric acid
  • Using the laser and painting the copper card with black paint

On this occasion I used the iron and ferric acid method because I had all the materials to do it.

Materials

Be careful when working with ferric acid, always wear gloves.

Materials

We print the circuit on photographic paper and use isopropyl alcohol to clean the surface of the copper plate to make it as shiny as possible.

Here is a very good video guide on how to burn plates with ferric acid.

After passing the plate through the acid, it does not deliver well-defined tracks.

On the top part, the guides were transferred with the iron to know where to place each component.

You can add tin to all the tracks to prevent them from rusting.

Both sides of the PCB

I loved the final result.


Solder components.

In this section we must solder the jumpers and terminal blocks to connect the sensors and screen.

Something important is also to solder the voltage regulators with the relay circuit.

Soldering

After soldering and burning my fingers a little, the final result was this:


Connect it to the machine.

Something important to mention is the data of the single-phase motor that is being used and the pulley coupling with which the revolutions will be multiplied up to 6000 rpm.

Component
Voltage 220
Frecuence 50 Hz
Power 0.75 Kw
RPM 3000
Current 4.78 A

The motor consumes almost 5 Ampere, that is why to activate it we use a 10 Ampere relay.

Motor

This is the motor with the pulley coupling, this coupling has 3 levels.

  • 1st level: 1500 rpm

  • 2nd Level: 3000 rpm

  • 3rd Level 6000 rpm

This way was chosen to be able to experiment with different speeds since the fiber changes depending on those values.

The faster you go, the thinner it will be and the slower you can find drops of resin in the fiber..

Then we proceed to connect the components in the control chassis, if the connections are short we can add more cables.

This is the output of the control interface.

And this is what the activation of the single-phase motor looks like from the control screen.

With 6000 rpm we can create the centrifugal effect in the resin that will allow us to create a fine fiber.


Details.

To improve the aesthetics, add a sign with LCD strip lights and it is controlled with a Xiao RP2040. This is purely aesthetic.

sign with lights

Code

This is the code I used.

It contains:

  • Interface
  • Motor control
  • Nema 23 control
  • Read temperature
#include <AccelStepper.h>
#include <ezButton.h>
#include <PID_v1.h>
#include <max6675.h>
#include <LiquidCrystal_I2C.h>

////////// Led de Prueba para ESP32 //////////
int led = 12;

////////// Pilotos LEDs indicadores //////////
int led_rojo = 15;
int led_naranja = 2;
int led_verde = 0;

////////// Pantalla LCD 20x4 //////////
LiquidCrystal_I2C lcd(0x27, 20, 4);

////////// Motor Paso a Paso //////////
const int stepPin = 27;
const int dirPin = 26;
#define motorInterfaceType 1
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);

////////// Modulo Encoder //////////
#define CLK_PIN 5
#define DT_PIN  18
#define SW_PIN  19

#define DIRECTION_CW  0   // clockwise direction
#define DIRECTION_CCW 1  // counter-clockwise direction

int counter = 0;
int direction = DIRECTION_CW;
int CLK_state;
int prev_CLK_state;

ezButton button(SW_PIN);

////////// Rele//////////
int rele = 32;

////////// Sensor de Temperatura MAX6675 //////////
const int thermoDO = 4;
const int thermoCS = 16;
const int thermoCLK = 17;

const int SSR = 33; // Definir pin de salida para el control de la extrusora

// Variables PID
double Setpoint = 200.0;  // Temperatura deseada en grados Celsius
double Input, Output;

// Sintonizar estos valores segĂșn sea necesario
double Kp = 2.0;
double Ki = 0.1;
double Kd = 1.0;

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO); // Objeto para el sensor MAX6675

////////////////////////////////////
TaskHandle_t Tarea0; 

bool est = true;
int t = 1000;

void setup() {

  Serial.begin(9600);
  //xTaskCreatePinnedToCore(loop0,"Tarea_0",1000,NULL,1,&Tarea0,0); // Core 0

  // Motor de 220 V
  pinMode(rele, OUTPUT);
  digitalWrite(rele, HIGH);
  delay(100);
  // Led de Prueba
  pinMode(led, OUTPUT);

  // Motor paso a paso
  stepper.setMaxSpeed(1000);
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  stepper.setSpeed(100);

  // Modulo Encoder
  pinMode(CLK_PIN, INPUT);
  pinMode(DT_PIN, INPUT);
  button.setDebounceTime(50);  // set debounce time to 50 milliseconds

  // read the initial state of the rotary encoder's CLK pin
  prev_CLK_state = digitalRead(CLK_PIN);

  // Sensor de Temperatura
  pinMode(SSR, OUTPUT);
  // Inicializar el PID
  myPID.SetMode(AUTOMATIC);

  // Pilotos leds indicadores
  pinMode(led_rojo, OUTPUT);
  pinMode(led_naranja, OUTPUT);
  pinMode(led_verde, OUTPUT);

  // Pantalla LCD 20x4
  lcd.begin();
  lcd.backlight();

  lcd.setCursor (0, 0);
  lcd.print(" FABRICADEMY  ");
  lcd.setCursor (0, 1);
  lcd.print("       ARAKUAA      ");
  lcd.clear();

}

void loop(){
  //Prueba_Esp32();
  //Prueba_Pilotos();
  //Prueba_Rele_SSR();
  //Prueba_motorPAP();
  //Prueba_Encoder();
  //Prueba_MAX6675();
  //core();
  //Prueba_1_Motor_220V();
  Prueba_2_Motor_220V();
}
void core(){
  Serial.println("Core #" + String(xPortGetCoreID()));
  delay(1000);
}
// Probar si el ESP 32 a usar, Funiciona
void Prueba_Esp32() {
  digitalWrite(led, HIGH);
  delay(200);
  digitalWrite(led, LOW);
  delay(200);
}
// Probar los leds Indicadores de estados
void Prueba_Pilotos() {
  digitalWrite(led_rojo, HIGH);
  digitalWrite(led_naranja, HIGH);
  digitalWrite(led_verde, HIGH);
  delay(200);
  digitalWrite(led_rojo, LOW);
  digitalWrite(led_naranja, LOW);
  digitalWrite(led_verde, LOW);
  delay(200);
}
// Probar si el rele y SSR funcionan
void Prueba_Rele_SSR() {
  digitalWrite(rele, HIGH);
  digitalWrite(SSR, HIGH);
  delay(1000);
  digitalWrite(rele, LOW);
  digitalWrite(SSR, LOW);
  delay(1000);
}
// Prueba de Motor Paso a Paso
void Prueba_motorPAP() {
  stepper.setSpeed(800);
  stepper.runSpeed();
}
// Prueba de Encoder
void Prueba_Encoder() {
  button.loop();  
  CLK_state = digitalRead(CLK_PIN);

  if (CLK_state != prev_CLK_state && CLK_state == HIGH) {
    if (digitalRead(DT_PIN) == HIGH) {
      counter--;
      direction = DIRECTION_CCW;
    } else {
      counter++;
      direction = DIRECTION_CW;
    }

    Serial.print("Codificador rotatorio:: direccion: ");

    if (direction == DIRECTION_CW)
      Serial.print("Sentido Horario");
    else
      Serial.print("Sentido Antihhorario");

    Serial.print(" - contador: ");
    Serial.println(counter);
  }

  prev_CLK_state = CLK_state;

  if (button.isPressed()) {
    Serial.println("El Boton ha sido presionado");
  }
}
// Prueba del Sensor de Temperatura MAX6675
void Prueba_MAX6675() {
  // Leer la temperatura del sensor MAX6675
  Input = thermocouple.readCelsius();
  Serial.println("  Temperatura: " + String(Input) + " C");
  delay(200);


}

void Prueba_1_Motor_220V(){
  button.loop();  
  if (button.isPressed()) {
    delay(1500);
    Serial.println("El Boton ha sido presionado");
    digitalWrite(rele, LOW);
    delay(2500);
  }
  else{
    digitalWrite(rele, HIGH);
  }
  digitalWrite(SSR, HIGH);
}

void Prueba_2_Motor_220V(){
  button.loop();  
  // Boton presionado
  if (button.isPressed()) {
    //delay(2000);
    est = !est;
    digitalWrite(rele, est);

    Serial.println("Boton presionado    estado: " + String(est));
  }
  delay(10);
  digitalWrite(SSR, HIGH);
}