Full Featured Arc Welding Simulator w/Sound: Arduino Nano & DFPlayer

rray Apr 29, 2020

  1. rray

    rray Staff Member

    8,307
    9,425
    133
    I have found all kinds of welding simulators on the web, and wanted a full featured one, with sound, as cheap as possible. This one could be built for $8-15 depending on where you source your Arduino Mini, LED's Resistors, TF Chip, Speaker, and DFPlayer.

    The sound effects were recorded from YouTube videos using Audacity.
    The sound tracks were named 0001.mp3 through 0005.mp3, and must be loaded one at a time in order. If you copy all 5 at once using Windows, they will get loaded in jumbled order, like 5,1,2,3,4.

    My sketch plays old time radio music, looping until a trigger event, from a switch or motion sensor starts the sequence.
    Music continues for a while, then white and blue LED's flicker to simulate arc welding, and the arc welding sound file plays for a random time.
    When the welding stops, the red LED comes on and fades to simulate the hot metal afterglow, no sound. This time is enough for the welder to pick up his hammer.
    Next the slag chipping sound file plays, stops, and plays again.
    Then the wire brush sound file plays to simulate cleaning up the slag, and stops.
    After time enough for the guy to put down the wire brush and pick up the grinder, the 2 yellow LED's start to flicker grinder sparks, and the grinder sound file plays for a random time.
    The whole sequence repeats once more, then stops, and everything goes silent.
    After a short time, the old time radio music starts playing again, and loops until the next trigger event.

    Here is a YouTube video of the sequence:


    Schematic:
    View attachment 216955

    Sketch:
    /*
    Script for Full Featured Welding Simulator w/Sound:
    MP3 File 5 for 41 seconds of old time radio music after trigger event
    Welding (white and blue leds flashing with MP3 File 1 welding sounds)
    Hot Metal Afterglow (red led fading no sound)
    MP3 File 2 slag chipping 2 times
    MP3 File 3 wire brushing 1 time
    Grinding the weld smooth (2 yellow leds flashing with MP3 File 4 grinding sounds)
    XX seconds after cycles is shutdown, the MP3 File 5 loops 41 seconds until next trigger


    Interrupt driven sensor should only play on a RISING edge single. I.E, when a light sensor
    is covered.
    Adapted from code by Ben (thewag on Trainboard) pieced together from multiple sources, including Toms Trains and Things, original idea by fernpoint on Model Railroad Hobbiest, and suggestions from Marc, an actual career professional welder. Thanks to you all!
    Last Modified 04/27/2020, needs comments for each line so I can understand what is happening
    */

    #include <SoftwareSerial.h>
    #include <DFRobotDFPlayerMini.h>
    //Digital Pins
    int TRIGGER = 2; // Interput 0 -- Sensor
    int RLED = 3; // 330 Ohm / Red LED for slag glow on pin D3 PWM
    int BLED = 4; // 330 Ohm / Blue LED for arc strike on pin D4
    int WLED = 5; // 330 Ohm / White LED for welder flash on pin D5
    int ALED = 6; // 330 Ohm / Amber LED for grinder sparks on pin D6
    int YLED = 7; // 330 Ohm / Yellow LED for grinder sparks on pin D7
    int PLAYER_RX = 10; // Player Recieve pin D10.
    int PLAYER_TX = 11; // Player Transmit pin D11.
    int PLAYER_BUSY = 12; // MP3 player status pin. LOW means busy playing.
    int RUN = 0; // Running status
    int CYCLE_COUNT = 2; // Cycles to run the welder per trigger event
    int SHUTDOWN_SOUND_TRACK_NUMBER = 5;
    SoftwareSerial mySoftwareSerial(PLAYER_RX, PLAYER_TX);
    DFRobotDFPlayerMini MP3;
    void setup() {
    attachInterrupt(digitalPinToInterrupt(TRIGGER), sensorTiggered, RISING); //May be RISING, FALLING, or CHANGE
    pinMode (WLED, OUTPUT);
    pinMode (BLED, OUTPUT);
    pinMode (RLED, OUTPUT);
    pinMode (PLAYER_BUSY, INPUT);
    pinMode (ALED, OUTPUT);
    pinMode (YLED, OUTPUT);

    mySoftwareSerial.begin(9600);
    MP3.begin(mySoftwareSerial);
    MP3.setTimeOut(500);
    MP3.volume(25);
    MP3.EQ(DFPLAYER_EQ_BASS);
    MP3.outputDevice(DFPLAYER_DEVICE_SD);
    }
    void loop() {
    MP3.play(5);
    delay(41000);
    // Test condition again to start the weld procedure
    if (RUN) {
    for (int x = 1; x <= CYCLE_COUNT; x++) {
    welder(); // White/Blue flicker and MP3 track 1
    afterglow(); // Red weld afterglow 2 to 3 seconds, no sound
    grinder();
    }
    }
    RUN = 0; //After CycleCount reaches limit
    shut_down(); //Sets all LED's off
    }
    void sensorTiggered()
    {
    RUN = 1;
    }
    void welder() {
    delay(3000);
    MP3.play(1); // Random White/Blue flashing with track 1 playing
    int cycle = random(80, 160); // Randomly sets the cycle time of the LEDs
    for (int i = 0; i < cycle; i++)
    {
    digitalWrite(WLED, HIGH);
    delay(random(10));
    digitalWrite(WLED, LOW);
    delay(random(200));
    digitalWrite(BLED, HIGH);
    delay(random(10));
    digitalWrite(BLED, LOW);
    delay(random(100));
    if (digitalRead(PLAYER_BUSY) == HIGH) { // HIGH not playing
    MP3.play(1); // Restart if sound has stopped
    }
    }
    MP3.stop();
    }
    void afterglow() { // Weld afterglow starts after weld stops and then dims no sound
    for (int j = 80; j > 1; j--) { // Variable int=j sets afterglow intensity, j > 1 sets ending glow, j-- decreases intensity
    analogWrite(RLED, j); // Sets RLED to current value of j
    delay(80); // Sets delay between each RLED intensity decrease

    }
    }
    void grinder() {
    MP3.play(2);
    delay(5000);
    MP3.play(2);
    delay(2000);
    MP3.play(3);
    delay(12000);
    MP3.play(4);
    // Randomly sets the cycle time of the LEDs
    int cycle = random(100, 200);
    for (int i = 0; i < cycle; i++)
    {
    digitalWrite(ALED, HIGH);
    delay(random(20));
    digitalWrite(ALED, LOW);
    delay(random(200));
    digitalWrite(YLED, HIGH);
    delay(random(10));
    digitalWrite(YLED, LOW);
    delay(random(100));
    if (digitalRead(PLAYER_BUSY) == HIGH) { // HIGH not playing
    // Restart if sound has stopped
    MP3.play(4);
    }
    }
    MP3.stop();
    }
    void shut_down() {
    // Turn off all LEDs
    digitalWrite(WLED, LOW);
    digitalWrite(BLED, LOW);
    digitalWrite(RLED, LOW);
    digitalWrite(ALED, LOW);
    digitalWrite(ALED, LOW);
    }



    I got the welding sound, slag chipping sound, and wire brushing sound starting at around the 7 minute mark from this video for files 0001-0003.mp3:


    And I got the grinding sound starting near 5min 30sec from this video for files 0004.mp3:


    And last, I got the old time radio music from this video for file 0005.mp3:


    Alternately, you can use any sound files you want, and the code is easy to modify. The welding and grinding sound will trigger a replay of those sound files if the random timer continues past the MP3 file length, so don't record any silence at the beginning or end of those tracks.

    My disclaimer, this is not my code or original idea, I pieced together lots of other peoples code and ideas to get what I though was a full featured arc welding simulator with sound using minimal parts and cost, and I wanted to share it with all of Trainboard's members to use and modify as desired.
     
  2. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Really wonderful. It will create a certain home town feel, won't it? I wonder if you could to get the same effect with one or two RGB leds. I have so many extra from putting up strip lights they are basically free. The big thing would be if you need physical distance to have the shadows change shape in which case you would have to have at least 2. And of course the code would have to change to handle a different protocol. Everything about your project is just great. Thanks for sharing it.
     
    rray likes this.
  3. IronMan1963

    IronMan1963 TrainBoard Member

    161
    173
    9
    Do you have the sound files available for this project. Nice Work. Thanks
    Richard
     
    rray likes this.
  4. rray

    rray Staff Member

    8,307
    9,425
    133
    I copied the sound files from YouTube videos so I can't distribute them due to copywrite infringement, but they are extremely easy to make. All you do is download the freeware Audacity program linked above, then go to the starting points listed above and press the record button, highlight just the sound you are targeting, and "Save Selected" as an mp3 file.
     
  5. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    That's great you are careful to honor the copyrights. I did something similar. My singing pumpkins for Halloween came from a fellow haunter who did the computer graphics to the songs I wanted. Then I purchased the songs. One was "Grim Grinning Ghosts" from Disney''s Haunted Mansion. There are lots of versions of this now and they license the songs so you don't have to do what I did and use video editing software to put it all together. But I already had all that stuff from a previous life in L.A. I use Audacity all the time, like for my most sophisticated prop, a haunted mineshaft with an infinity mirror. When my daughter was 8, she did all the voice acting. I added echo and snipped them all onto a SDcard based sound board kit sitting on an Arduino Duemilanove from around 2012. It senses people, knows if people are moving towards it, moving away after starting to move towards it, , how far they are, etc. So all the prompting is surprisingly real. People think someone is controlling it from somewhere with all the different prompts like, "No! Please, come back!". The scare when they look down in it and it switches relays, triggers a strobe and shows a face 2 feet away from theirs is something I never get tired of ;) I make it look like an old western setup, train tracks for the gold car, a rusted wheelbarrow, shovel and old lantern. Maybe I should try to duplicate it to N scale! I keep looking for a way to make an N scale version of the bates mansion for my layout. You and Geoff Bunza go all out on your amazing animations!

    Oh, one question, have you ever felt the need for something like the Halloween "Four Banger" prop? It is a trigger device also based on a microcontroller. It really works great for timing. The software is out there so you can modify it and make your own. Basically, when programming, you can hit buttons to sync things to sounds or to control actions. So you basically act it out in realtime to get the exact timing of multiple things and then play it back. If you like it, you are done. There are more sophisticated timeline based software solutions, much like video editing software too, but this has no learning curve and gets rid of the tedious trial and error method.
     
  6. rray

    rray Staff Member

    8,307
    9,425
    133
    Yeah, I seen the video where it triggers a pneumatic piston, light bulb, soundtrack. I was thinking I can have that in my sawmill, and it is playing sawing sounds, then if someone looks inside, it triggers a band saw blade snap sounds, someone screaming, sparks flashing, and shoots a small nerf disc at them shaped like a saw blade. It could be good for a laugh or 2.
     
  7. gmorider

    gmorider TrainBoard Member

    2,113
    6,366
    65
    rray, you have the mind of a devil....:eek:
     
    BNSF FAN likes this.
  8. Larry Sebelley

    Larry Sebelley New Member

    2
    3
    1
    rray:
    I have been working on your arc welder project.
    On your schematic drawing, I think the two connections between the arduino and the rfplayer for the RX and TX are reversed. I switched them and my player came to life. I think RX should connect to D10 and TX should connect to D11. Also, the BUSY on the rfplayer should connect to D12.
     
    BNSF FAN and rray like this.
  9. rray

    rray Staff Member

    8,307
    9,425
    133

    Thanks for the correction, I must have not paid enough attention.

    Diagram.jpg
     
    BNSF FAN and tjdreams like this.
  10. HemiAdda2d

    HemiAdda2d Staff Member TrainBoard Supporter

    22,051
    27,658
    253
    That is slicker than a greased door knob! So cool!!!!!
     
    BNSF FAN and rray like this.
  11. johnhb

    johnhb New Member

    6
    1
    4
    I have put together the parts for your arc welder and found some sound files. The files are on the DFPlayer and named 0001.mp3 ... 0005.mp3. If I pull ADKEY1 to ground, 0001.mp3 plays. I can cycle through the sounds using pin IO_1 as a 'next' function.
    However, I cannot get the arduino to play any sounds. I definitely have RX to D10, TX to D11 and BUSY to D12. Read somewhere to have a 10K resistor in the RX and TX lines to remove the clicking sound coming from the DFPlayer. I am using a Mega 2560 and the LEDS operate as they should. I have tried a second DFPlayer unit and still no sounds triggered by the arduino.
    Am I the only one having some issues with this project?
     
    BNSF FAN likes this.
  12. rray

    rray Staff Member

    8,307
    9,425
    133
    Could it be the 10K RX resistor? Try a lower value, because your DFplayer might not be receiving. Alternately, the DFplayer "#include <DFRobotDFPlayerMini.h>" might not match your DFplayer, and you need a different library to match?
     
    MichaelMac, BNSF FAN and Sumner like this.
  13. Larry Sebelley

    Larry Sebelley New Member

    2
    3
    1
    Johnhb:

    I have used an Arduino Nano with the DFPlayer connected as per the diagram above. It worked fine until I shorted out the DFPlayer -- waiting for a replacement.
     
    BNSF FAN likes this.
  14. MichaelMac

    MichaelMac New Member

    2
    1
    1
    I have everything connected correctly and checked numerous times. I am trying to use an IR sensor to activate it and am struggling here. Any assistance would be appreciated.
     
    BNSF FAN likes this.
  15. MichaelMac

    MichaelMac New Member

    2
    1
    1
    Hey Larry, Did you ever get it working? My DF Player doesn't seem to have power (blue light not on the player) but everything is connected as per the instructions.
     

Share This Page