The best Arduino Arc Welder

February 21, 2017

You've no doubt seen the various arc welder simulation circuits available for model train layouts. They're available from companies like Circuitron, and basically consist of a circuit with screw terminals with which you power a lamp. The circuit randomly flashes the lamp to give the effect of an arc welder.

It's a fairly simple thing to do, especially with modern microcontrollers being so inexpensive (I got 3 Arduino Nanos for under $10 on Amazon Prime). There are already a few programs written for the Arduino to do it, with most being something like this:

void loop()
{
int i,count;
count=random(10,60);
for (i=0;i<count;i++)
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(random(60));
digitalWrite(ledPin, LOW); // set the LED off
delay(random(200));
}
delay(random(800,2000)); // wait a random bit of time
}

The Problem

This works great if your Arduino doesn't need to do anything else, but since it makes use of delay(), you'll basically need to rewrite the entire program if you need to control other things at the same time.

In my case, I've got an engine shop building with some white LEDs inside for the arc welder, but I've also installed gooseneck lamps on the outside of the building that I'd like to control. My layout is built around JMRI, so turning LEDs on and off is trivial with the ArduinoCMRI Library. It would be ridiculous to use separate microcontrollers for the lamps and the welder, but in order to combine them I had to rewrite the arc welder program to be "non-blocking," meaning it doesn't tie up the microcontroller CPU with those delay() statements.

If you're not familiar with what non-blocking means, you can take a look at the blinkWithoutDelay example code bundled with the Arduino IDE.

The Code

Here's my improved arc welder program. Not only is it totally non-blocking, but it also makes it very easy to turn the welder off, which is a feature I plan to add later once I complete the ArduinoCMRI control code.

Just adjust the const int ledPin variable to match where your LED is connected (be sure to use a resistor!) and you'll have yourself a highly customizable arc welder. Enjoy!

Calculating amperage (load) of a diesel locomotive

Fix chattering Cherry MX switches in Xubuntu

Backstory I own one mechanical keyboard: a cheap ThermalTake eSports Poseidon something-or-other with blue backlighting and blue switches. For the price it's a pretty awesome keyboard, except for one fatal...