Thunder & Lightning Animation

13,306

109

31

Introduction: Thunder & Lightning Animation

Introduction
Children's Hospital of Pittsburgh has a wonderful O-scale train layout that represents scenes from the Harry Potter movies. There is a large castle at one end of the layout and I wanted to add an animation to the castle that would flash bright LEDs in concert with an audio track of claps of thunder.

I have a good deal of experience with micro-controller controlled MP3 players including the VMUSIC2 and the DFPlayer. I opted to use the DFPlayer for this project as it works very well with an Arduino and is quite inexpensive. More importantly it is easy to control and can power a speaker without an additional amplifier.

This project can be built on a piece of prototype board with point to point wiring. Add a bright LED bulb or three and a speaker to the Arduino and DFPlayer and you are ready to go!

Step 1: The Circuit

In addition to the DFPlayer and an Arduino I needed a Mosfet (an IRL520) to drive a group of LED lights that operate from 12 volts and can draw a good bit of current. I have tested the unit with as many as 4 six LED spotlight bulbs wired in parallel.

The DFPlayer's RX pin is connected to the Arduino's TX pin. Be sure to include the 1000 ohm current limiting resistor. Pin 16 on the DFPlayer (busy) goes to pin 10 on the Arduino - that allows the Arduino to know if the MP3 file is playing or not.

The bright LED spotlight bulbs are connected to the Arduino through a Mosfet, Q1, which turns the lights on and off. This behavior is made possible by the connection between speaker pin 8 on the DFPlayer and analog pin 0 (zero) on the Arduino. The sound is sampled continuously and, when a loud sound is detected, the bulbs light brightly. When the sound subsides the LEDs go off.

Step 2: Parts

This group of parts is placed near their location on the schematic. While the Arduino and DFPlayer could be soldered directly to the circuit board I like to put such devices in sockets. The black socket pins are cut from a longer strip of contacts.

Parts:

  • Arduino Pro Mini - the Arduino Uno will work, too.
  • DF-Player (must be labeled DF Player - there are many similar units that will not work)
  • micro SD card - 1 gig is plenty
  • 7805 voltage regulator
  • heat sink for regulator
  • IRL520 Mosfet
  • 10 uf / 25 volt tantalum capacitor (anything from 1 to 10 uf will work)
  • 470 uf / 25 volt electrolytic capacitor (anything from 220 - 1000 uf will work)
  • 8 ohm speaker (junk box or old computer speakers -If you use a 4 ohm speaker R5 is needed - see schematic)
  • 1 or more LED spotlight bulbs - the ones I used have six LEDs in each bulb and are VERY bright!
  • sockets for the LED bulbs
  • pushbutton "start" switch (any momentary SPST switch will work)
  • female 2.54mm header (to cut up for the Arduino and DFPlayer sockets)
  • miscellaneous connectors, wire, etc
  • 10 K resistor (1)
  • 1 K resistor (3)
  • 12 volt 2 amp power supply
  • Circuit board for prototype construction (approx 2" x3")

Visit my web page ( http://www.trainelectronics.com/Animation-thunder-lightning/ ) for links to the places I ordered parts.

Step 3: Construction

The unit was built on a small piece of prototype board. The solder pad side of the circuit board faces down and the components are inserted from the other side.Step 1 - solder the Arduino and DFPlayer to the board using female header sections.

Be careful that there are no solder bridges connecting adjoining pins.

Step 4: Power Supply

The 7805 voltage regulator and the two capacitors are added next - the tantalum capacitor cannot be seen in this photo - it is on the other side of the 7805.

Step 5: Power Supply 2

Next add the wires that supply +5 volts (the red wires) and ground (black wires) - the two wires that are not connected will be used for the "start" switch.

Step 6: Add the Start Switch

To accommodate the switch that I used two 1/8" holes were drilled in the board. The 10 K resistor holds the Arduino pin that connects to the switch low until it is pressed.

Step 7: Add the Light Control Mosfet

There is a two pin female header next to it that the LEDs plug into - if you prefer they can be wired directly.

The two heavier red and black wires deliver power directly to the Mosfet and the plug for the LED bulbs. Using thinner wire would limit the amount of current available to the LEDs.

Step 8: Final Connections

Don't forget the jumper between Arduino pin 10 & DFPlayer pin 16 and the wire (blue in the photos) that connects speaker pin 8 on the DFPlayer and pin A0 on the Arduino. The 5 ohm resistor between the speaker and pin 6 on the DFPlayer is only needed if you use a 4 ohm speaker - if you don't use the resistor with a 4 ohm speaker the voltage regulator will get quite hot. An 8 ohm speaker works without the resistor.

The wires on the top of the board were placed that way to more clearly illustrate the circuit wiring. If you prefer you could put those wires on the bottom of the board.

Step 9: Sound Files

You can download the thunder sound files by clicking here. On your Micro SD card place them in a folder called mp3 The sound files themselves are numbered 0001.mp3, 0002.mp3 and so on. I only use 0001.mp3 in the video.

Step 10: Software

The Arduino code is shown below . There are two variables ( if (sensorValue >= 750) { and if (sensorValue <= 666) { ) that can be adjusted based on your sound files - 750 is the analog reading that triggers the LED strip light on and 666 is the level where the LEDs are turned off. Since this happens at a very fast rate it does a remarkable job of simulating lightning flashes that are synchronized with the claps of thunder. Watch the video to see how the program works.

The only library ( #include ) that is used can be downloaded here: https://github.com/DFRobot/DFPlayer-Mini-mp3/blob...

/*
d. bodnar - 9-06-2016

Lightning & thunder for CHP castle

*/

#include

const int buttonPin = 3; // the number of the pushbutton pin

int buttonState = 0; // variable for reading the pushbutton status

int buusyPin = 10;// buusyPin = 10; // sound player busy

int bsy = 0;

int LEDstripLight = 12; // IRL520 to LED strip light

int sensorPin = A0; // Audio level samples

int sensorValue = 0; // variable to store the value coming from the sensor

int buttn = 0;

//***************************************SETUP*************************************

void setup () {

pinMode(buttonPin, INPUT);

pinMode(LEDstripLight, OUTPUT);

pinMode(buusyPin, INPUT);

pinMode(buttonPin, INPUT);

Serial.begin (9600);

mp3_set_serial (Serial); //set Serial for DFPlayer-mini mp3 module

mp3_set_volume (30); // must remove mp3_reset(); to get this to work

}

//.......................................LOOP................................................

void loop () {

Serial.println("");

Serial.println("Waiting for Button Push");

do {

buttn = digitalRead(buttonPin); // pins closest to power pins

} while (buttn == 0);

Serial.println("Button Hit");

mp3_play(1);

delay(100);

do {

sensorValue = analogRead(sensorPin);

Serial.print(sensorValue);

Serial.print(" ");

if (sensorValue >= 750) {

Serial.println("large number! ");

digitalWrite(LEDstripLight, HIGH);

}

if (sensorValue <= 666) {

digitalWrite(LEDstripLight, LOW);

}

bsy = digitalRead(buusyPin);

} while (bsy == 0); // zero when sound active

}

//...................................... END LOOP ........................................

Step 11: Conclusion

The videos show quite clearly how well the sound and light flashes are synchronized. This same circuit could easily be adapted for a mine explosion (see the third video for an example of this), a fireworks display and many other lighting effects.
Please let me know how you use it!

1 Person Made This Project!

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Automation Contest

    Automation Contest
  • Make it Glow Contest

    Make it Glow Contest

31 Comments

0
orlando.fernandez.eci
orlando.fernandez.eci

11 months ago

Thank you for sharing this project. I built it and plan to modify it for my train set too. I appreciate your hard work and your skills. Thanks.

0
Va_Tech_EE
Va_Tech_EE

Tip 1 year ago

DFRobot's library for the DFPlayerMini is a terrible and inefficient library. If anyone want's a faster and simpler library to use with this module, I suggest using this one: https://github.com/PowerBroker2/DFPlayerMini_Fast. You can also download and install through the Arduino IDE's Libraries Manager (search "DFPlayerMini Fast").

0
davebodnar
davebodnar

Reply 1 year ago

Thanks for the tip. Will check it out.
Dave

0
PierreV16
PierreV16

Question 1 year ago

I work with SRF05 ultrasonic sensor.
Instead of IRL520 I use IRFZ44N.
DFplayer and ampifier have separate 5V 3A
Sound is fine with 8 ohm 3w, sound stereo.

Everything works except the LEDs.
The LED lights are like the picture, 5mm white LEDs, 3 LEDs and resistor in series , this fourth time and in parallel connected.

Have I somewhere a mistake in my schedule, or is there another solution?

PCB voor Ketel.jpgLED.JPG
0
davebodnar
davebodnar

Reply 1 year ago

Not sure what the issue may be - have you checked pin # 12 to see if it is going on/off with the sound? You can check that with an oscilloscope, a logic probe or even a volt meter.

Also, have you pulled pin 12 high to see if that lights the LEDs?

dave

0
PierreV16
PierreV16

Reply 1 year ago

I have not measured yet by the voltmeter.
Go do this do now.

What do you mean with: pulled pin 12 high

0
davebodnar
davebodnar

Reply 1 year ago

If you disconnect pin 12 from the Arduino and connect it to +5 volts the LEDs should light
dave

0
PierreV16
PierreV16

Reply 1 year ago

If I turn over "digitalWrite(LEDstripLight, HIGH);" the LEDs light.
Do not immediately how to solve.

Perhaps I should once again try to write the program.

0
davebodnar
davebodnar

Reply 1 year ago

That is certainly worth a try - good luck!
dave

0
PierreV16
PierreV16

Reply 1 year ago

Hello Dave,
Everything works as it should, thanks for ahead of time.

0
davebodnar
davebodnar

Reply 1 year ago

That is super news - thanks for letting me know
dave

0
PierreV16
PierreV16

Question 1 year ago

I would like to use the full code of the page
http://www.trainelectronics.com/Animation-thunder-lightning/delay.htm, but with
a slight adjustment.

For a cauldron on coal (have a fixed lighting).
Am an amateur of 75 years young, and do my best
to understand English. 'Ve only 1 ½ years in electronics.

Now comes my problem, programming.
With good examples and setups I start to understand
it, just to keep things to make it work.

Instead of push buttons, I would like to work
with HU-SRF05 ultrasonic sensor (HC-SR04). Both the DFPlayer and the sensor are
totally new to me, I do not know how to make the combination.

The idea:
2 to 15 cm violent storm file 0001
15 to 40 cm violent bubbles file 0002
41 to 80 cm bubbles file 0003 //max distance I want to use
81 cm en Out of range bubbles file 0004 //more than 81 and Out of range

The file 0001 can only replay after 5 to 10 seconds
The files 0002 to 0004 should continuous to we get another distance.

This is at the pin numbers
int trig = 8; int
echo = 9;

In the void loop () I do not know how to solve it, go somewhere with "if and else if"
I think, but can't find any adequate example.

2nd question:
The files 0002 to 0004 I would also save as but
with a blank stereo left channel. No lights come here, this are bubbles from
the couldron, is this correct?

My idea is good, but I can't get it to a good end.
If you want to help me I would be very grateful.
If you prefer to reply by mail:
p.vanovermeire@gmail.com

1.gif
0
davebodnar
davebodnar

Answer 1 year ago

Good day - I believe that you could interface the ultrasonic sensor as you describe. There are sure to be samples on the Internet that can help.
I will leave the actual coding and hardware changes to you as I do not have time to devote to your ideas right now.
Good luck and have fun!

dave

0
PierreV16
PierreV16

Question 1 year ago

Am a bit confused.
At the Mosfet we have the G D and S. The G to the Arduino, the S to the negative of LEDs and the D to GND, or am I wrong?

Knipsel.JPG
0
davebodnar
davebodnar

Answer 1 year ago

I believe you have it right - the source goes to ground, the drain to the LED and the gate to the Arduino
dave

0
PierreV16
PierreV16

Reply 1 year ago

Thank you very much for the quick reply

0
idahojoe
idahojoe

Question 1 year ago on Step 11

I'm just learning Arduino, made a few sketches and would like to try your sketch, but, I get a error message on the line that reads "mp3_set_serial(Serial)" error message reads "not declared in this scope"
Tried a few things without success. Can you be of assistance
Joe

0
davebodnar
davebodnar

Reply 1 year ago

Joe - the only thing that I can think of is that you have not installed the library -

The only library ( #include ) that is used can be downloaded here: https://github.com/DFRobot/DFPlayer-Mini-mp3/blob...

If you have not give that a try.

If you are not familar with adding libraries just Google arduino library install for help

Good luck!

dave

0
CDG144
CDG144

Question 3 years ago on Step 10

I'm new to this so can you please tell me how to download the library module. If I click on your link it takes me to a page showing the code but I can't see a "download" feature anywhere.
Thanks,
Colin.

0
RANDOM KNOWLEDGE
RANDOM KNOWLEDGE

3 years ago

amazing it works great,

www.wannaduino.com under ARDUINO topic named THUNDER