MIG Welding Torch Adapter for a CNC Machine

Team 2: Junior Design Project Fall 2017 is presented here.

IntermediateShowcase (no instructions)1 hour626
MIG Welding Torch Adapter for a CNC Machine

Things used in this project

Story

Read more

Schematics

Circuit

Circuit 2

Code

Team 2 Sequence Code

Arduino
Some additional features are commented out. There is also a line of code for increasing the speed of the I2 clock communication. This increased the performance of the stepper motors but decreased the accuracy while under full load.
#include <Servo.h> // servo motor library
#include "Arduino.h" // arduino library
#include <AccelStepper.h> // stepper motor library
#include <Adafruit_MotorShield.h> // motor shield library
#include <Wire.h>

#define STEP_TYPE_1   SINGLE // Defines the step type
#define STEP_TYPE_2    SINGLE // Defines the step type
#define STEPS_1    200 //Steps per rev
#define STEPS_2    200 //Steps per rev

int buttonPin = 3; //pin for full sequence button
boolean BSQ = LOW; // Initial state for button for sequence
int SeqEnabled = 0; //Initial state for Sequence 
boolean PrevBSQ = LOW; //Initital state for Previous buttonPin digitalRead
int buttonPinH = 5; //pin for homing sequence button
boolean BSQH = LOW; // Initial state for button for homing
int SeqEnabledH = 0; //Initial state for comparison variable for homing sequence button
boolean PrevBSQH = LOW; //Initial state of the previous button pin for homing digitalRead
const int buttonPin180 = 4; // pin for 180 degree axis microswitch
int buttonState180 = 0; // variable for reading the 180 microswitch
const int buttonPin45 = 2; // pin for 45 degree axis microswitch
int buttonState45 = 0; // variable for reading the 45 microswitch
 
Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(STEPS_1, 1);
// creates a stepper motor object located at M1 and M2
Adafruit_StepperMotor *myStepper2 = AFMS.getStepper(STEPS_2, 2);
// creates a stepper motor object located at M3 and M4

void forwardstep1() {
  myStepper1->onestep(FORWARD, STEP_TYPE_1);
}
void backwardstep1() {
  myStepper1->onestep(BACKWARD, STEP_TYPE_1);
}
void forwardstep2() {
  myStepper2->onestep(FORWARD, STEP_TYPE_2);
}
void backwardstep2() {
  myStepper2->onestep(BACKWARD, STEP_TYPE_2);
}

AccelStepper Motor1(forwardstep1, backwardstep1); // use functions to step
AccelStepper Motor2(forwardstep2, backwardstep2); // use functions to step

Servo Servo1; //Creates a servo object that is connected to pin 10

void moveToPos(float distance, float speed, int motor) {

  if (motor == 1) {
    Motor1.moveTo(distance);

    if (Motor1.distanceToGo() < 0) {
      speed = -speed;
    }

    Motor1.setSpeed(speed);
  } 
    
    else {
    Motor2.moveTo(distance);

    if (Motor2.distanceToGo() < 0) {
      speed = -speed;
    }
    Motor2.setSpeed(speed);
  }
    while (Motor1.targetPosition() != Motor1.currentPosition() || Motor2.targetPosition() != Motor2.currentPosition()) {
    if (motor == 1) {
      Motor1.run();
    } else {
      Motor2.run();
    }
  }
}

void releaseMotors()
{
  AFMS.begin();
}

void setup() 
{
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);//Sets buttonPin for full sequence as an input
  pinMode(buttonPinH, INPUT);//Sets buttonPinH for homing as an input
  pinMode(buttonPin180, INPUT); //Sets the 180 microswitch pin as an input
  pinMode(buttonPin45, INPUT); //Sets the 45 microswitch pin as an input
  AFMS.begin(); //Initializes the motorshield board default frequency 1.6KHz
  //TWBR = ((F_CPU /400000l) - 16) / 2; // Change the i2c clock to 400KHz (Increases the rate of communication between the board and steppers)
  Servo1.attach(10); //Connects Servo1 to pin 10 (Labeled Servo1 on the Motor Shield)
  Servo1.write(1);//Sets the servo to the initial starting position

  Motor1.setCurrentPosition(0); //sets the current position of motor 1 to zero
  Motor2.setCurrentPosition(0); //sets the current position of motor 2 to zero

}
  
 
void homing() //1) Finding home position
{
  myStepper1->setSpeed(7);  //Sets 180 degree axis stepper RPM
  myStepper2->setSpeed(5);  //Sets 45 degree axis stepper RPM
  buttonState180 = digitalRead(buttonPin180); //sets buttonState180 as a digitalRead of the 180 microswitch
  int n=1; //Sets the inital value of the step iteration 
  
  while (buttonState180 == HIGH) { //Loop until the 180 microswitch reads a HIGH
    myStepper1->step(n,BACKWARD, INTERLEAVE); //moves n steps, direction, step style (used INTERLEAVE for more resolution)
    delay (250); //Delay for accurately locating the microswitch
    n=n+1; //increases the iteration by 1 
    buttonState180 = digitalRead(buttonPin180); //Reads the digital pin again
 }
 
//releaseMotors();//code for releasing both stepper motors (not used)
  delay(1000);//delay bewteen 180 degree axis and 45 degree axis homing
 //myStepper1->release();//releases 180 degree stepper to conserve power for the 45 degree stepper (not used)

 
  buttonState45 = digitalRead(buttonPin45);//sets buttonState45 as a digitalRead of the 45 microswitch
  int m=1; //Sets the inital value of the step iteration 
  
  while (buttonState45 == HIGH) { //Loop until the 45 microswitch reads a HIGH
    myStepper2->step(m,BACKWARD, INTERLEAVE); //moves n steps, direction, step style (used INTERLEAVE for more resolution)
    delay (250); //Delay for accurately locating the microswitch
    m=m+1; //increases the iteration by 1 
    buttonState45 = digitalRead(buttonPin45); //Reads the digital pin again
  }
 
  Servo1.write(0);  //homes servo to 0 position
  
}


  void servoMoveUp1() //2) depressing and  holding the  switch;
  //move servo motor to press trigger (about 60 degrees)// goes from 0 degrees to 60 degrees
{
  Servo1.write(60); //Moves servo to press the trigger
  delay(50); //Delay for holding the trigger (not used)
}


   void movingToSpot1() // 3)  rotating down 45  degrees; 
   //rotate stepermotor2 45 degrees down
{
    //myStepper1->release();//releases 180 degree stepper to conserve power for the 45 degree stepper 
    myStepper2->setSpeed(20);  // Sets 45 degree axis stepper RPM
    //myStepper2->step(70,BACKWARD, INTERLEAVE); //moves n steps, direction, step style (used INTERLEAVE for more resolution)
    myStepper2->step(45,BACKWARD, DOUBLE); //moves n steps, direction, step style (used INTERLEAVE for more resolution
   //moveToPos(60, 100, 2); //Move the Stepper motor connected to port 2, 26 steps in the positive direction at a speed of 100 steps/second (Absolute)
    delay (50); 


}

  void servoDrop1() //4)  releasing the  switch; 
  //move servo motor to release trigger (about -60 degrees)
{
  Servo1.write(1); //Moves servo back to home position
  delay(50);
}


 void movingBack1() //5) rotating up 45 degrees to return to horizontal;
 //return to home
 {
    myStepper2->setSpeed(30);  // Sets 45 degree axis stepper RPM
    //myStepper2->step(70,FORWARD, INTERLEAVE); //moves n steps, direction, step style (used INTERLEAVE for more resolution)
    myStepper2->step(45,FORWARD, DOUBLE); //moves n steps, direction, step style (used INTERLEAVE for more resolution
    //moveToPos(1, 100, 2);//Move the Stepper motor connected to port 2, 1 step in the positive direction at a speed of 100 steps/second (Absolute)
   delay (50);

}

 void servoMoveUp2() //6) depressing and holding the switch; 
  //move servo motor to press trigger (about 60 degrees)// goes from 0 degrees to 60 degrees
{
  Servo1.write(60); //writes the servo to 60 degrees to press the trigger
  delay(50);
 
}


  void movingToSpot2() // 7) rotating 180  degrees  about  the  spindle  axis 
  //rotate stepermotor1 180 degrees clockwise
{
    myStepper1->setSpeed(65);  // Sets 180 degree axis stepper RPM
    //myStepper1->step(405,FORWARD, INTERLEAVE); //moves n steps, direction, step style (used INTERLEAVE for more resolution)
    myStepper1->step(202,FORWARD, DOUBLE); //moves n steps, direction, step style (used INTERLEAVE for more resolution)
    //moveToPos(205, 100, 1);//Move the Stepper motor connected to port 1, 100 steps in the positive direction at a speed of 100 steps/second (Absolute)
    //myStepper1->release(); //Releases stepper 1 to conserve power for stepper 2 (not used)
    delay(50);

}


 void servoDrop2() // 8)  releasing the  switch;  
// move servo motor to release trigger (about -60 degrees)
// goes from 60 degrees to 0 degrees
{
  Servo1.write(1); //Writes the servo back to home position and relaeses the trigger
  delay(50);
}


  void movingBack2() //9) rotating back 180 degrees (counterclockwise if the first direction was clockwise) to the original orientation (
 //return to home
 {
    myStepper1->setSpeed(65);  // Sets 180 degree axis stepper RPM
    //myStepper1->step(405,BACKWARD, INTERLEAVE); //moves n steps, direction, step style (used INTERLEAVE for more resolution)
    myStepper1->step(202,BACKWARD, DOUBLE); //moves n steps, direction, step style (used INTERLEAVE for more resolution)
    //moveToPos(-13, 100, 1);//Move the Stepper motor connected to port 1, 100 steps in the positive direction at a speed of 100 steps/second (Absolute)
    //delay(250);
    
}

void loop() {
 
  BSQH = digitalRead(buttonPinH); //Establishes variable for homing sequence button digitalRead

  //Conditional statement,if two digitalReads are not equal and is a HIGH
  if(PrevBSQH != BSQH && BSQH == HIGH) {
    SeqEnabledH = !SeqEnabledH; //Takes inverse of previous SeqEnabled or initial (0 or 1)
  }
  //Conditional Statement, if it equals 1 call homing function
  if(SeqEnabledH== 1){
  homing();
  }

  PrevBSQH = BSQH; //Re-reads the homing button state for conitional statement
  
  BSQ = digitalRead(buttonPin);
  
  //Conditional statement,if two digitalReads are not equal and is a HIGH
  if(PrevBSQ != BSQ && BSQ == HIGH) {
    SeqEnabled = !SeqEnabled; //Takes inverse of previous SeqEnabled or initial (0 or 1)
  }

  //Conditional Statement, if SeqEnabled is 1 (button pushed) call the full sequence.
  if(SeqEnabled == 1){

  servoMoveUp1(); //Press trigger
  
  movingToSpot1(); //rotate torch tip down 45 degrees
   
  servoDrop1(); //release trigger
 
  movingBack1(); //return torch to home 45 degree axis
 
  servoMoveUp2(); //Press trigger
  
  movingToSpot2(); //Rotate 180 degrees
  
  servoDrop2(); //Release trigger

  movingBack2(); //Return 180 degree axis to home position
  
  delay(600000); //Delays sequence for 10 minutes. Cutpower before it begins again.
  }

else{}
  PrevBSQ = BSQ; //Re-reads the sequence button state
}

Credits

Joshua Hypes

Joshua Hypes

3 projects • 2 followers
Waleed Algamdi

Waleed Algamdi

2 projects • 1 follower
Abdulrahman Alghamdi

Abdulrahman Alghamdi

2 projects • 1 follower
Mohran Al Jurdi

Mohran Al Jurdi

1 project • 1 follower
Erik Dumas

Erik Dumas

2 projects • 0 followers
Physics and Mechanical Engineering Student UNC Charlotte
Ali Alsaihati

Ali Alsaihati

1 project • 0 followers

Comments