Spotwelder using Arduino UNO

I have built a Spotwelder to make battery tabs. I used a microwave transformer and took out the secondary winding. I then replaced it with 5 turns of 25mm^2 welding cable.

Now I want to control the spotwelder using arduino and a solid state reley and a solenoid . I would like to controll the current, weldtime and holdtime using potmeters.

I have tried to make a arduino sketch for it: I use two LED to indicate welding and holding(solenoid). When I adjust pots the led respond to show weld and hold time. I use interrupt to activate welding by a footswitch. I can make dual welds by pressing another switch. When the timer pot is at maximum i would like to make the footswitch manual and hold the weld until i remove the foot. This part is not working. I have a problem if a interupt signal comes when the loop program is interupted and the weld current is activated before the hold solenoid. Are there someone out there who can help me?

Knut Einar

// Spotwelder int PinWeld=9; int PinWeldLed=6; int PinHold=10; int PinHoldLed=5; int PotCurrent=A0; int PotWeldTime=A1; int PotHoldTime=A2; int PinFootSwitch=3; int PinSwitch=2; volatile int Mode = LOW; volatile int Foot = HIGH;

int Current=0; int WeldTime=0; int HoldTime=0; int FootSwitch= HIGH;

void setup() {

pinMode(PinWeldLed, OUTPUT); pinMode(PinHold, OUTPUT); pinMode(PinFootSwitch, INPUT); digitalWrite(PinFootSwitch, HIGH); pinMode(PinSwitch, INPUT); digitalWrite(PinSwitch, HIGH); attachInterrupt(0, Dual , FALLING); attachInterrupt(1,Weld, FALLING);

} void loop() { analogWrite(9,0); analogWrite(10,0); Current=analogRead(PotCurrent)/4; WeldTime=analogRead(PotWeldTime)/4; HoldTime=analogRead(PotHoldTime)/4;

if(WeldTime>220){ if(Foot == LOW ){analogWrite(10,255);} delay(400); analogWrite(5,255);

while(PinFootSwitch == LOW ){analogWrite(9,Current);}

analogWrite(9,0); analogWrite(5,0); delay((HoldTime*6)+500); analogWrite(10,0); analogWrite(6,0);}

else{ analogWrite(5,(Current)+10); if(Foot == LOW ){analogWrite(10,255);} delay(400); analogWrite(6,255); if(Foot == LOW ){analogWrite(9,Current);} if(Mode == HIGH) { delay((WeldTime*4)+10); analogWrite(6,0); analogWrite(9,0); delay((HoldTime)+100); analogWrite (6,255);} if(Foot == LOW ){analogWrite(9,Current);} Foot=HIGH; delay((WeldTime*4)+10); analogWrite(6,0); analogWrite(9,0); delay((HoldTime*6)+500); analogWrite(5,0); analogWrite(10,0);

} delay(1000);

} void Dual() { Mode = !Mode; }

void Weld() { Foot = LOW;

}

I have been making some advance with the code. And since no one has responded, I made some comments in the code. Now the manuel welding is working and i have used two flags to make the interupt work . Had to make a lot of if-sentences..... I guess there are better ways to do this. The olny problem now is that if i press the footswitch and let it stay in the program make several weldings. I want it to just make one weld. Here is the new code:

// Spotwelder //Knut Einar int PinWeld=9; int PinWeldLed=6; int PinHold=10; int PinHoldLed=5; int PotCurrent=A0; int PotWeldTime=A1; int PotHoldTime=A2; int PinFootSwitch=3; int PinSwitch=2; volatile int Mode = LOW; volatile int Foot = HIGH; volatile int InLoop = HIGH;

int Current=0; int WeldTime=0; int HoldTime=0; int FootSwitch= HIGH;

void setup() {

pinMode(PinWeldLed, OUTPUT); pinMode(PinHold, OUTPUT); pinMode(PinFootSwitch, INPUT); digitalWrite(PinFootSwitch, HIGH); pinMode(PinSwitch, INPUT); digitalWrite(PinSwitch, HIGH); attachInterrupt(0, Dual , FALLING); attachInterrupt(1, Weld , FALLING); // When footswitch(pin3) is pressed, the void Weld is activated

} void loop() { InLoop = HIGH; // set flag for interupt when FootSwitch is activated to bypass loop analogWrite(9,0); // Turn off Solid state relay analogWrite(10,0); // Turn off solenoid to hold weld Current=analogRead(PotCurrent)/4; // Read input from potmeter for current WeldTime=analogRead(PotWeldTime)/4; // Read input from potmeter for welding time HoldTime=analogRead(PotHoldTime)/4; // Read input from potmeter for holding time after welding

if(WeldTime>250){ // Set manual timing if timing pot is max InLoop = HIGH; if(InLoop == HIGH)analogWrite(5,100); // set hold LED ON with PWM value 100 if((Foot == LOW) && (InLoop == HIGH)){analogWrite(10,255);} // Activates the hold solenoid full power (relay) if(InLoop == HIGH){delay(400);} //wait 0.4 sec before activating welding current if(InLoop == HIGH){analogWrite(6,100);} // Turn on Weld LED (PWM 100) if((InLoop == HIGH)&&(Foot == LOW)){ analogWrite(9,Current);} // Turn on Solid State reley with PWM value of current if foot and Inloop flag is right

if(InLoop == HIGH) {while(digitalRead(PinFootSwitch) == LOW ){}} // A loop to wait for footswitsh to go high

analogWrite(6,0); // Turn off weldLED analogWrite(9,0); // Turn off solid State for welding if (InLoop == HIGH){delay((HoldTime*6)+500); // wait for weld to cool down before power off solenoid depending on hold time analogWrite(5,0); // Turn off holdLED analogWrite(10,0);} // Turn off hold solenoid if(InLoop == HIGH){delay(1000);} if (InLoop == HIGH ){ Foot = HIGH;} // Turn flag Foot HIGH to prevent another weld }

else { // In this mode (time is not max) The welding prosess is automated InLoop = HIGH; if(InLoop== HIGH)analogWrite(5,100); if((Foot == LOW) && (InLoop == HIGH)){analogWrite(10,255);} if(InLoop == HIGH){delay(400);} if(InLoop == HIGH){analogWrite(6,100);} if((Foot == LOW) && (InLoop == HIGH)){analogWrite(9,Current);} if(Mode == HIGH) // If Mode is HIGH the switch is toggeled to make a dual weld { if (InLoop == HIGH){delay((WeldTime*8)+5);} analogWrite(6,0); analogWrite(9,0); if(InLoop == HIGH){delay((HoldTime)+100);} if(InLoop == HIGH){analogWrite (6,100);} if((Foot == LOW)&&(InLoop == HIGH)){analogWrite(9,Current);} }

if(InLoop == HIGH){delay((WeldTime*8)+5);} analogWrite(6,0); analogWrite(9,0); if (InLoop == HIGH){delay((HoldTime*6)+500); analogWrite(5,0); analogWrite(10,0);}

if(InLoop == HIGH) {delay(1000);} if(InLoop == HIGH ){ Foot = HIGH;} } } void Dual() // This interupt toggles the mode for single or dual weld { Mode = !Mode; }

void Weld() // This interupt changes two flags to activate welding. InLoop is to bypass loop when interupt is activated to make loop start from beginning { Foot = LOW; InLoop = LOW; }

Here is a photo of the microwave transformer .

And the solenoid i am using: http://www.ebay.com/itm/300819883966?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1438.l2649
The solenoid is activated by a relay: http://www.ebay.com/itm/1-Channel-Opto-Isolated-Relay-Module-Low-Trigger-5V-Arduino-With-Screw-Terminals-/221207236878?pt=LH_DefaultDomain_0&hash=item3380fa910e

The plan is to control the trafo with this solid state relay: http://www.ebay.com/itm/370812003082?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
I will use a Varistor to protect the solid state relay: http://www.ebay.com/itm/251055887685?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

This is the footswitch: http://www.ebay.com/itm/181124166319?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

The trafo and the electronics wil be put in a UPS case that has two leds and one pushbutton.

trafo.PNG

Your code is quite difficult to read. A couple things here to clean it up:

Don’t do this:

int PinWeld=9;

Do this:

#define WELD_PIN 9

Then make sure you actually use it:

  analogWrite(WELD_PIN,0); // Turn off Solid state relay

When using a #define, when you compile your program the compiler basically does a “search and replace” for all instances of “WELD_PIN” with “9”. It saves memory and ensures you don’t accidentally modify the value.

You’ve got a lot of messy constructs like:

    if(InLoop == HIGH){delay(400);}    //wait 0.4 sec before activating welding current
    if(InLoop == HIGH){analogWrite(6,100);} // Turn on Weld LED (PWM 100)
    if((InLoop == HIGH)&&(Foot == LOW)){ analogWrite(9,Current);} // Turn on Solid State reley with PWM value of current if foot and Inloop flag is right

You need to clean these up:

    if(InLoop == HIGH){
      delay(400);    //wait 0.4 sec before activating welding current
      analogWrite(WELD_LED_PIN,100); // Turn on Weld LED (PWM 100)
      if(Foot == LOW){ 
        analogWrite(WELD_PIN,Current); // <-- this doesn't work; see my later comment.
      } // Turn on Solid State reley with PWM value of current if foot and Inloop flag is right
    }

When posting code make sure you use code tags like I have above. To do this, when editing your post, just highlight the code and then hit the “#” button above the editor.

You can’t control current using a solid state relay and PWM. Your solid state relay only turns on/off up to 120 times/second (60Hz AC) when the AC voltage crosses zero volts. When you use PWM to control that relay you’re sending signals that don’t at all match with that 120 times/second and you get an undefined result.

Interrupts aren’t necessary here; they’re just making the code more complex. Assuming your code isn’t stuck in a delay() your main() loop will be looping many thousands of times per second which is plenty responsive to catch when your pedal switch is pressed.

Chagrin: Don't do this:

int PinWeld=9;

Do this:

#define WELD_PIN 9

Best practice when writing in C++ (as in the Arduino IDE) is to use:

const int PinWeld=9;

because it is type-safe and just as efficient.

Chagrin: You can't control current using a solid state relay and PWM. Your solid state relay only turns on/off up to 120 times/second (60Hz AC) when the AC voltage crosses zero volts. When you use PWM to control that relay you're sending signals that don't at all match with that 120 times/second and you get an undefined result.

While that is largely true, it is possible to PWM an AC SSR at very low frequencies, for example 1 to 10Hz. This is too low for a lamp or a motor, but OK for heating. Maybe 10Hz would be OK for welding. However, as the SSR is feeding a transformer, unless you are very careful, for some PWM values there may be a DC component in the voltage seen by the transformer, and you risk burning it out.

Thanks for the response. Yes I can do some better structure in the code. I have to considering not using PWM on the Solid State. Maybe make a PWM with 10 HZ. How do I make this?

What you are trying to do is not that easy, and quite dangerous if you get it wrong. You have to synchronise the pwm drive to the solid state switch , with the zero crossing points in the AC waveform so that the switch gets turned on for equal amounts of time in both the positive and negative directions. Most applications like this that are used in heating ,use what is called zero cycle switching which simply turns on or off complete AC cycles into the transformer. This way there is no chance of a DC component through the transformers primary. If you are not familiar with working with mains voltages , I would not be doing this sort of project.