Animate Your Layout With Sound and Light
revised 04-02-08

Animation on your garden railroad can take many forms.  Most of us equate animation with movement but bringing things to life is not limited to movement alone.  One of the most interesting and attention getting animations that we have installed at the new Phipps Conservatory garden railroad has no moving parts at all!

A small gold mine entrance has been carved into the side of a mountain.  As the passenger train cruises past, a lone miner stands by the opening and yells out "Clear the area... Blasting in 10 seconds!"  A short while later he shouts "Fire in the hole!"  An instant passes before a bright flash emanates from the mine entrance to the accompaniment of a loud and thunderous explosion.

This animation has fascinated visitors as they try to figure out exactly what is happening.  Some just catch a bit of the dialog and a hint of the flash gives them pause.  More than a few wait for the train to come around again to trigger the event.  Children have been seen refusing to leave until they can see it "one more time, mommy!"

Design Objectives

When the members of the Pittsburgh Garden Railway Society brainstormed about the design of this layout we envisioned a number of vignettes that would bring interest to the layout.  Two of the animations, the outhouse and prairie dog town, were examined in an earlier article

Once we decided that we would like to add a small prospector's mine to the layout we brainstormed ways to bring it alive.  An explosion as the miner blasted deep within the mine was an obvious choice.  Smoke and debris coming from the mine entrance would have been nice but there is no practical way to create such an effect that would run over and over, day after day without maintenance.  We settled on having high quality sound effects coupled with a bright flash from within the mine.  Our next task was figuring out how to do it.

Inexpensive (how about free?) Flash Units

I have experimented with adding flashing lights to my home layout for years.  You may recall my article on building a solar powered Morse code beacon.  This has been running on a tower next to my model ham radio shack for years, flashing out my call, N3ENM, over and over.  A few years ago I took flashing lights to another level when I built a saloon & photo studio for the layout.  I wanted visitors to periodically see a flash coming from within the photographer's studio.  This was accomplished by placing a motion detector in one of the building's windows.  When a visitor came by it triggered a recycled photo flash unit from a single use camera.  The system worked like a charm for several months.  Then the inevitable happened during a heavy rain storm.  Water got into the circuitry and shorted some of the components.  It was, however, a most fortuitous event!  Afterwards the camera flash didn't go off when activated by motion but it flashed repeatedly every 3 seconds, over and over again.  I decided to leave it that way just to see how long the flashing would continue.  I didn't expect it to go on for too long, especially since I used the innards of a disposable unit.  Much to my surprise and amazement it continued for nearly three years.  In fact, it started flashing repeatedly in June of 2005 and is still going strong!  Now that I had evidence that the flash units could last for a long, long time I decided to use one for the Phipps layout.

Single Use Camera Anatomy 101

The flash unit that I used was removed from a standard single use flash camera like these.

You can probably get one for little or no money by asking the local drug store or other film developing establishment if you can have a few for use on your railroad.  Most are happy to oblige as they have lots of camera bodies left over after processing the film.  They do send them back for recycling but I don't think anyone keeps track of them.


 

If you don't want to disassemble a camera, All Electronics sells the flash units for a few dollars, item # FSH-12

DANGER!  High Voltage!

Whether you but a unit or decide to disassemble a camera to harvest its flash a few words of caution are in order.  These little flash devices generate, and can store almost indefinitely, a 300-400 volt charge in their capacitor.  I'll say that again... 300-400 volts!  That is enough to really, really ruin your day if you happen to discharge it through your body.  While it is not likely to kill you it will stimulate your nervous system and other body parts in ways that you are not apt to enjoy!  I strongly suggest that you wear rubber or dry work gloves as you disassemble the camera.  You also must discharge the capacitor, shown here, as soon as it is visible.

Disassembly

Follow these steps to disassemble the camera.  Note that the specifics will vary from brand to brand.

Once the board is free of the camera discharge the capacitor one more time just to be sure it is not holding a charge.  Only then is it safe to hold the flash board in your bare hands.

If you still doubt that such a small device that is powered by only one small battery can deliver such a jolt have a close look at the meter reading in the photo below.  It is showing 317 volts DC across the capacitor!

 

Wiring the Flash

Four wires need to be soldered to the flash board and one jumper needs to be added. 

First we have to short out the contacts for the button that is used to charge the flash.  The photo below shows where to jumper the Kodak camera I was working on.  The yellow wire is the jumper that was added.  It bridges the button, the large silver item in the center of the photo.  If you are working with a different style of board just trace the contacts under the charge button and solder a jumper between them.  Making this modification causes the flash to begin charging the capacitor as soon as power is connected.

Next we need to solder wires to the two battery contacts so that we can use an external power supply.  Hopefully you made note of the way the battery was inserted in your camera when you disassembled it.  Solder a length of red wire to the positive terminal and a length of black wire to the negative.

The last connection is to the trigger contacts. Solder a length of wire to each contact.

 

Here is one of the Kodak boards with all of the wiring done. 

Power for the Flash

The biggest hurdle in using these recycled flash units is supplying them with power.  You will recall that the only power supply for the camera is a single AA or AAA battery that delivers 1.5 volts.  These boards are designed for this low voltage supply and using anything much above 2 volts tends to fry them.  Since we want the flash to operate for a long time we need to find a way to supply power from a continuous source rather than from a battery.  I thought this would not be a big deal until I put an ammeter on the flash and examined its power requirements.  When the flash begins to charge it draws more than two amps!  That is a remarkable amount of power to pull from a small battery.  More significantly I discovered that it is no mean feat to make a 1.5 volt / 2 amp power supply.

My first attempt was to use a variable voltage regulator.  An LM317 can provide voltages ranging from 1.2 to 25 or more volts.  The problem is not the voltage but the current that the flash needs.  If you are supplying the LM317 with 12 volts and are only using 1.5 volts for the flash the rest of the energy that goes into the regulator has to be dissipated as heat.  Even with a large heat sink and a fan the LM317 quickly overheated.  If you feed the LM317 with a 5 volt source it will work as there is much less of a voltage drop and less energy to dispose of.  Unfortunately that was not an option for me.

At the Phipps layout I only had one source of power.  This was from a connection that was used for lighting and other animations and it provided nearly13 volts.  I had to come up with a way to get rid of quite a bit of excess energy.  I tried a large wattage resistor but it, too, got way too hot to be safe.  A voltage divider consumer too much energy after the flash charged.  I finally settled on a using a string of sixteen 3 amp diodes wired in series.  As you may know diodes will drop the voltage that passes through them by approximately 0.7 volts per diode.  A series of 16 diodes drops the voltage by 16 x 0.7 = 11.2 volts.  The input voltage is close to 13 volts giving me a consistent 1.8 volts to the flash unit.  The diodes get hot just like the resistor and voltage regulator but the number of diodes and their large combined surface area seem better suited to radiating the excess heat.

Here the flash unit is being tested.  The red and black clips are connected to a 5 volt power supply.  Since we only need to drop the voltage from 5 volts to 1.5 volts a string of just five diodes is needed for this test.  One more word of caution.  When testing avoid touching any part of the board including the trigger wires!   The trigger wires don't carry the full voltage but there is enough there to give you a tickle!  Continue to work with insulated tools and gloves when the capacitor is charged.  If in doubt don't touch anything!  Disconnect power and short the capacitor before touching any part of the unit.

 

This close-up shows the Kodak board's "ready light".  It glows when the capacitor is charged and the flash is ready to go.  Some boards use a LED.  This one uses a small neon bulb.

The last step in preparing the board is to remove some of the parts that extend from the board to make it more compact.

 I also carefully bent the capacitor over so that it no longer stuck straight out.

A quick run through the band saw to cut the camera case in half gave me an enclosure for the flash unit.  A bit of black tape to seal up the side and it was ready for use!

Firing the Flash

The flash is triggered by briefly connecting the two wires that we soldered to the trigger contacts.  These wires carry a fairly high voltage so we can't use a normal transistor as a switch to set off the flash.  I have successfully used triacs to fire these units but the type of triac that is needed varies from board to board so I have settled on using a small relay that will work with virtually any of the boards.  This is easily incorporated into the microcontroller based circuit that will be the brains of the animation.

Any 5 volt relay can be used to trigger the flash.  Here are two examples.  I used relays that will fit into IC sockets as they are the one component of the system that could fail and I wanted to make them easy to replace.

High Quality Sound

Once the flash had been identified and made ready the next hurdle was finding a way to supply high quality sound that didn't distort at high volume.  This would be for the two mine announcements and the explosion.  I have used inexpensive digital recorders for a number of projects including the squeaking door on the layout's outhouse.  Some experiments showed that trying to reproduce highly intelligible voice at high volume was beyond the capabilities of these boards.

I knew that an MP3 player had the capacity to produce quality sound but I needed one that I could easily interface to the microcontroller so that it could accurately synchronize the sound with the flash that was to accompany the explosion. 

Rather than hacking a consumer MP3 player I decided to use a device that is designed to be controlled by microcontroller such as the PICAXE..  The board I chose to use is called VMUSIC2 and is available from a number of sources for less than $50.00.  

The VMUSIC2 module is less than 3" wide.  The interface cable (only a few of the wires are used) and a standard USB memory stick that stores the MP3 sound files are also shown in this photo.  A set of speakers plugs into the connection on the left side of the VMUSIC2.

Removing the cover shows the electronics inside.

 

This board has a number of characteristics that make it ideal for this and other railway projects:

Commands to Operate the Sound Module

The operation of the VMUSIC2 module is quite simple.  Once it is connected to the microcontroller, a PIC 16F684 in this case, all the microcontroller has to do is send serial commands to play a particular clip.  To simplify the programming I saved all of the MP3 files with very short names.  The file that says "Clear the area... blasting in 10 seconds" is called 3.mp3.  The file that says "Fire in the hole!" is called 1.mp3, and the explosion is 2.mp3.  To play the first file the command
SEROUT Serial_out, 2, ["vpf 3.mp3", 13]
is executed.  This program line sends the command "vpf 3.mp3" to the VMUSIC2 via the serial cable at a speed of 9600 baud.  The "2" in the command sets the speed to 9600 and the "13" sends a carriage return at the end of the command to indicate that the command is complete.

The "vpf" command tells the VMUSIC2 to play the file that follows the command.  Other commands include:    

Visit the Vinculum web site for more information on using this device.

Connecting the VMUSIC2 module to the PIC or PICAXE is very straightforward.  The schematic shows the PIC16F684 microcontroller connecting to the flash relay, the VMUSIC2 sound module and a reed switch that triggers the mine animation.  The PICAXE 14M works equally well in this application.

Schematic Notes
  • The jumper that connects to pin 2 is used to skip the first audio clip.  This was done to shorten the time that visitors would have to wait before seeing the explosion.  It is not currently being used as the visitors appear to enjoy hearing all of the audio clips.
  • The audio amplifier and flash diodes both connect directly to the 12-13 volt DC power supply
  • A 5 volt power supply (not shown in the schematic) provides filtered power to the PIC and the VMUSIC2
  • The LED that connects to pin 8 is for testing
     

Software

INCLUDE "modedefs.bas"
ansel=0                 'allows you to use pins as digital rather than analog
DEFINE OSC 8
OSCCON = $70

Serial_out          VAR PORTA.4     ' pin 3 to vmusic2
sw1                 VAR portc.3     ' pin 7 
LED                 VAR portc.2     ' pin 8
Relay               VAR porta.2     ' pin 11
SkipPin             VAR porta.5     ' pin 2 - jumper to skip first audio clip
delay               CON 2000
trisa.4=0
trisc.2=0
trisc.3=1  
trisa.2=0
trisc.5=1

top:
HIGH LED
PAUSE 50
LOW LED

PAUSE 100
stayhere:
HIGH LED
IF sw1=1 THEN stayhere:	'wait till switch is closed

LOW LED
IF SkipPin=1 THEN SkipThis: 'skip first sound if jumper on
' play "Blasting in 10 seconds"
SEROUT Serial_out, 2, ["vpf 3.mp3", 13]
PAUSE 5000 'wait 5 seconds

SkipThis:
PAUSE 5000 'wait 5 seconds
' play "Fire in the hole!"
SEROUT Serial_out, 2, ["vpf 1.mp3", 13]
PAUSE delay
HIGH LED
PAUSE 2000
LOW LED
' play "explosion"
SEROUT Serial_out, 2, ["vpf 2.mp3", 13]
PAUSE 200
HIGH Relay:PAUSE 50:LOW Relay  'trigger flash
PAUSE delay
HIGH LED
GOTO top
Program Notes
The version of BASIC used by the PIC is very similar to that used by the PICAXE. 
  • The first 15 lines initialize the chip and set up the input and output pins
  • The program stays at "stayhere:" until the reed switch on the track is hit by a passing train
  • If the jumper (J1) is closed the first audio clip is skipped
  • Once the voice announcements are done the program starts playing the explosion clip (2.mp3) as the relay triggers the flash

Making It Loud!

The VMUSIC2 module is not designed to drive a speaker directly.  The output that normally goes to headphones can be sent to an amplifier from a recycled set of computer speakers.  This provides more than enough volume to be heard when used with an outside layout. 

In this photo you can see the amplifier board (bottom center) and one of the two speakers. The other speaker is still in the plastic enclosure on the right.  The AC transformer at the top is not needed as we will supply the amplifier with DC power.

 

Putting It All Together

The flash unit is placed a few inches back inside the entrance to the mine.  The other components are inside of a miner's shack next to the mine portal.  A four wire cable connects the two.

This photograph is of a prototype of the mine explosion that I put together for testing.  The flash unit can be seen inside of the mine entrance to the right.  The trigger button is in the foreground.

The audio amplifier is at the top next to the VMUSIC2 module.  The USB memory stick is labeled "64" as it has a 64 meg capacity.   

Here you see the two speakers facing downward.  The microcontroller board is mounted on the side of the speakers.  The entire unit easily fits within a small building.

The 16 diodes that are used to supply 1.5 volts to the flash unit are attached to the inside of the building's roof.  This gets them out of the way and allows them to radiate heat through the roof.

A reed switch is placed between the rails of the track by the mine.  A magnet is glued to the bottom of the locomotive so that the animation starts when the train passes.  The first sound clip "Clear the area, blasting in 10 seconds" gives the train time to get completely past before the explosion.

This video shows what happens when the unit is triggered.

Right click on the image below and select "Play"

 

Other Applications

The flash unit could be used in a number of places.  As noted earlier it is a natural to include in a photo studio.  I am sure that there are other places, such as industrial buildings or a mad scientist's laboratory, that you would find its flash to be appropriate.

The VMUSIC2 module can supply high quality sound for any number of applications.  Because it can store literally hundreds of different audio files the microcontroller can easily be programmed to deliver random or sequential clips.  This would allow you to have a variety of announcements and/or sounds coming from a station or other building. 

That fact that it supports two stereo audio tracks means that you can use one VMUSIC2 board to supply different sounds to two different buildings.  This can be done by putting one speaker from a stereo sound system in one building and the other speaker in a different one.  You can create sound files for one building that only use one of the stereo channels and those for the other building on the other channel.  The possibilities are endless!

I showed a variation on the VMUSIC2 module control system a the East Coast Large Scale Train Show that allows you to trigger sounds with a small hand held remote control unit.  Sounds can also be activated by strategically placed reed or push button switches.  This may become the focus of a new controller and yet another article.  Please let me know if this is something that might interest you.

Speaking of editing sound there is an excellent audio editing program that is available at a great price, free!  The audio editing program that I use is called Audacity and can be downloaded from http://audacity.sourceforge.net/download/.  Giving instruction in the program's use is beyond the scope of this article but suffice it to say that Audacity is able to do just about anything you might need to do with audio files. 

You can find thousands of free sound files on the Internet.  My favorite site is the Free Sound Project.  You need to register to download sounds but it is painless and there is no cost.  Train sounds abound!

This animation project was great fun to put together.  It is also great fun to see the smiles come to visitors' faces when they see it in action.  Give it a try, I think you'll like it!

Please let me know if I can help.