Enthused with the recent Arduino control of the staging yard, I decided to strike while the iron was hot and try another Arduino project. I'm not very good at learning stuff for the sake of learning (like C programming) without an end goal, so I needed an idea and an arc welding simulator fits the bill.
Welding simulators are common, but I after a quick study of 'prototype' arc welding, I realized there was more to the project than first appeared.
The cycle consists of first "striking" an arc by stroking the welding rod (rather like striking a match), along the metal on the job to get an arc running. Trickier than it sounds, since the arc should fire up at the point the weld should begin. This can take a few attempts depending on how expert the operator is. Experts actually "tap" rather than "strike", but its easier to "freeze" the rod to the work using this method
Then the weld takes place with a lot of flashing in both the white and blue spectrums.
Finally when the welding rod is removed and the arc stops, the metal is red hot and cools rapidly.
I strapped 3 LEDs (white, blue and red) together and connected them to Pro Mini Arduino, before stuttering through the creation of a suitable sketch to make it work.
I needed a way to flash both white and blue LEDs simultaneously at different frequencies. I am an Arduino novice so this took a while, but I discovered the joy of a thing called a "finite state machine", which allows an Arduino to multitask. This is very much a first attempt and the experts among you may throw their hands up in horror at the code. But it works and it was great fun creating it and I have learned a lot.
Everything is randomly based, but fully configurable:
- Length of time between welding sessions
- Number of "strike" attempts
- Length of "strikes"
- Length of welding session
- Flash rate/intensity of white and blue components
- Rate of cooling glow
The finished product will find it's way into Paxman Engineering at Mortimer and once installed I'll post a video of the result.
Here's a very short video showing a couple of welding cycles (intervals shortened from that when installed for "real"):
The Sketch looks like this:
// These are the possible states that are used to control how the arc welding flows
#define S_IDLE 1
#define S_STRIKE_ARC 2
#define S_WHITE_ARC 3
#define S_BLUE_ARC 4
#define S_RED_GLOW 5
#define S_TURNOFF 6
static int state_main_control = S_IDLE; // initial state is idle.
static int state_blue_arc_control = S_IDLE; // initial state is idle.
static unsigned long ts; // To store the "current" time.
static unsigned long wait; // To store the wait time for delays.
void setup()
{ //Nothing to set up here!
}
void loop()
{
static int ledPin_white_arc = 04; // White LED on pin 4
pinMode(ledPin_white_arc, OUTPUT);
static int ledPin_blue_arc = 02; // Blue LED on pin 2
pinMode(ledPin_blue_arc, OUTPUT);
static int ledPin_red_glow = 03; // Red LED on pin 3
pinMode(ledPin_red_glow, OUTPUT);
switch (state_main_control)// Main control state manages the arc welding cycle
{
case S_IDLE:
ts = millis(); // Remember the current time
wait = random(1000, 5000); //Set a wait time before welding cycle starts.
state_main_control = S_STRIKE_ARC; // Move to the Arc "striking" state.
break;
case S_STRIKE_ARC: // Simulates the striking needed between welding rod and work to start an arc
if (millis()> ts + wait)//Start the arc strikes when the random delay is exceeded
{
int strikes = random (2,5);//random number of strikes to start the arc
for (int i = 0; i< strikes; i++)
{
digitalWrite(ledPin_white_arc, HIGH ); // Turn the white arc LED on for first attempt
delay(random (80,120)); // strike the arc
digitalWrite(ledPin_white_arc, LOW ); // Turn the white arc LED off
delay(random (200,600)); // delay before next attempt
}
digitalWrite(ledPin_white_arc, LOW ); // Turn the white arc LED off in preparation for full arc
ts = millis(); // Remember the current time
wait = random(5000, 10000); //Set a random time for now long the arc welding cycle to run
state_main_control = S_WHITE_ARC; // Move on to next state
state_blue_arc_control = S_BLUE_ARC; // start up a simultaneous blue arc with the white arc
}
break;
case S_WHITE_ARC: // main flashing of white arc.
if (ts + wait> millis())// provided random time not exceeded, then keep welding.
{
digitalWrite(ledPin_white_arc, HIGH); // set the Arc LED off
delay(random(60));
digitalWrite(ledPin_white_arc, LOW); // set the Arc LED on
delay(random(200));
break;
}
ts = millis(); // Remember current time
wait = random(5000, 10000); //Set a random time for the weld glow to run
state_main_control = S_RED_GLOW; // Move on to next state
state_blue_arc_control = S_IDLE; // Stop the blue element of the arc
break;
case S_RED_GLOW:// Simulates the cooling of the work from red hot after the arc is stopped using an analogue write
if (ts + wait> millis())
{
for (int i = 50; i> 0; i--) { //decrease i with 1
analogWrite(ledPin_red_glow, i);
delay(100);
}
state_main_control = S_TURNOFF;
break;
}
case S_TURNOFF:
digitalWrite(ledPin_red_glow, LOW); // Kill the last bit of analogue glow
state_main_control = S_IDLE;
break;
}
switch (state_blue_arc_control)// Separate state machine running blue arc alongside white arc at different flash frequency
{
case S_BLUE_ARC:
digitalWrite(ledPin_blue_arc, HIGH); // set the Arc LED on
delay(random(10));
digitalWrite(ledPin_blue_arc, LOW); // set the Arc LED off
delay(random(100));
break;
}
}
Rob Clark
Cornhill & Atherton RR