# A Talking Defect Detector - my latest Arduino Project



## dbodnar (Jan 2, 2008)

Good day - My wife and I have traveled across the country on Amtrak a number of times and I always take along a scanner to monitor the train's radio communications. The defect detector reports were always of interest. 
This inspired me to try my hand at creating one for model railroads. After a few weeks of work I finally have it (mostly) working and thought it might be of interest to some of you.
The detector uses two small lasers and two phototransistors that sit across the track from one another. A passing train breaks the beams allowing the Arduino to compute the train's speed, length and number of axles. It also has a temperature sensor. 
Once a train has passed the Arduino uses a small MP3 player to speak its report just as the real ones do!
I have placed a short video on YouTube here:




 Photos, code and details of its construction are on my web page here:
http://www.trainelectronics.com/Arduino/DefectDetector/

You will note that the video and web page photos are of an HO implementation but there is no reason that this unit would not work equally well with G-scale. In fact I plan on bringing one along to the ECLSTS in March and to demonstrate it during my seminar.

Please let me know if you have any questions or ideas for enhancements beyond the ones I have listed.
thanks!
dave


----------



## ewarhol (Mar 3, 2014)

That's really neat Dave. I've seen other track detectors out there, but they don't actually count axles, take temp, etc. Can your unit be customized to have a defect every now and then?


----------



## dbodnar (Jan 2, 2008)

ewarhol said:


> That's really neat Dave. I've seen other track detectors out there, but they don't actually count axles, take temp, etc. Can your unit be customized to have a defect every now and then?


Eric - that is on my TODO list - I have to add a menu first that allows the end-user to choose a ratio of error reports vs no defect reports.

I also want to have it trigger a radio so that the report is broadcast to a radio as it does in the real world.

great fun!

dave


----------



## JackM (Jul 29, 2008)

Pardon my drooling. I didn't have any big project planned for the end of 2015, after the RR gets put away for the winter. I think I have one now.

Beyond cool.

JackM

Do you know what time/day your seminar will be at ECLSTS?


----------



## dbodnar (Jan 2, 2008)

JackM said:


> Pardon my drooling. I didn't have any big project planned for the end of 2015, after the RR gets put away for the winter. I think I have one now.
> 
> Beyond cool.
> 
> ...


Glad you liked it, Jack - my seminar is scheduled for Friday morning - probably at 9:30 or 10:00 or thereabouts - hope to see you there.
dave


----------



## dbodnar (Jan 2, 2008)

JackM said:


> Pardon my drooling. I didn't have any big project planned for the end of 2015, after the RR gets put away for the winter. I think I have one now.
> 
> Beyond cool.
> 
> ...


Glad you liked it, Jack - my seminar is scheduled for Friday morning - probably at 9:30 or 10:00 or thereabouts - hope to see you there.
dave


----------



## JackM (Jul 29, 2008)

Definitely!

JackM


----------



## Dave Crocker (Jan 2, 2008)

Another great project, I learn something new overtime I visit your website.
That's a peculiar way of connecting the 7805


----------



## dbodnar (Jan 2, 2008)

Dave Crocker said:


> Another great project, I learn something new overtime I visit your website.
> That's a peculiar way of connecting the 7805


Peculiar, indeed, Dave! I have no idea of how that error crept in but it has been corrected - thanks!

dave


----------



## dbodnar (Jan 2, 2008)

*The Defect Detector now has menus & random defect announcements*

Good day, all - I have been working on the software for the Defect Detector and the code has grown from less than 500 lines to well over 1000! This is almost all due to adding menus so that more than a dozen options can be changed from the LCD screen.
You can now individually activate or deactivate each of the reports (like temperature, speed and length) and you can set the mile marker number (000.1 through 999.9), the scale and the probability that defects will be detected.
I currently only allow for one defect report at a time. This report identifies a randomly selected axle in the range of what was counted and a randomly selected North, South, East or West side of the track. For those of you who don't want all four directions it is simple to rename files so that you only get East & West or North and South.
I tried to break the program up into many, small routines so that others can more easily figure out what is going on. I know that there are much more efficient ways to write this code but what I have done works and is fairly easy to understand.
I have added the new code and a number of photos to my web page here:
http://www.trainelectronics.com/Arduino/DefectDetector/
I plan on adding another video once I finish up a few other things.
The next step is to add a small radio transmitter to the detector so that you actually pick up the report on a scanner, just like the real thing!
Stay tuned!
dave


----------



## San Juan (Jan 3, 2008)

That's pretty cool.

Too bad we can't get a hold of the real railroad audio files to create a very authentic sounding detector. At least I doubt they would make these available.

I use my scanner every time I take the train and the BNSF and Metrolink digitized voices I'm familiar with are so ingrained in my mind. 

I can almost hear in my mind now, "BNSF detector, milepost xxx.x, no defects, repeat no defects, total axles 44, out" (44 being the typical axle count on the Southwest Chief...the train I travel the most on).

A quick YouTube search found the exact voice and detector info I'm familiar with in my region:


----------



## dbodnar (Jan 2, 2008)

San Juan said:


> That's pretty cool.
> 
> Too bad we can't get a hold of the real railroad audio files to create a very authentic sounding detector. At least I doubt they would make these available.
> 
> ...



It wouldn't be all that hard to edit the clips that are on YouTube and elsewhere - The challenge would be to get every sound that you needed, like all of the digits 0--9!
The good news is that the detector uses MP3 files that are easily changed should anyone want to go that route.

dave


----------



## Semper Vaporo (Jan 2, 2008)

If you want the 'electronic' vocalization, use the Windows Narrator function.

It is the same very poor annunciation and timing as a real defector... I mean Detector. (Narrator is LOUSY at understanding the timing of syllables, spaces between words, commas, periods and other punctuation.)

If'n I had muh druthers, I'd use the old ATARI "S.A.M." (Software Automatic Mouth) program... don't bother trying the PC versions of S.A.M., they all use the same text to speech software that Narrator does. The old Atari version paid attention to punctuation and could even be made to SING!


If you want to do it in Windows, here is how...

1 Run "Sound Recorder" 

Click the "Start" button and type "Sound" in the search box... "Sound Recorder" will appear at the top, click on it.

2. Run the "Text to speech" setup dialog:

Click the "Start" button and type "Narrator" in the search box... then click on "Change text to speech settings" in the list that appears at the top.

3. Type what you want the computer to say into the text box in the middle of the Text to Speech dialog box.

4. Click the "Start Recording" button on the Sound Recorder box.

5. Click the "Preview Voice" button on the Text to Speech dialog.

6. Click the "Stop Recording" button on the Sound Recorder box and type a file name in the dialog box that shows up.

Change the text in the text box and do it all again to save more files.

I know there is a way to change the Narrator's voice, but my system won't let me right now and I don't know why.


----------



## dbodnar (Jan 2, 2008)

*Text to Speech in Windows*



Semper Vaporo said:


> If you want the 'electronic' vocalization, use the Windows Narrator function.
> 
> It is the same very poor annunciation and timing as a real defector... I mean Detector. (Narrator is LOUSY at understanding the timing of syllables, spaces between words, commas, periods and other punctuation.)
> 
> ...


Great suggestion! I just fooled with it and it may be a better way to generate the sound files for the detector.

FYI, under Windows 8.1 I just typed 

*change text to speech settings*

in the search box (comes up when you hit the Windows key)

Thanks!

dave


----------



## dbodnar (Jan 2, 2008)

*New voice, radio transmitter & menus video*

The suggestion to use Microsoft's "text to speech" function has turned out to add more realism to the defect detector. I redid the system with Microsoft's voice and made a new video. This also includes a demonstration of the setup menus and the radio transmitter.
The new video is here:






the original video is here:






Details are on my web page here:

http://www.trainelectronics.com/Arduino/DefectDetector/ 

Enjoy!

dave


----------



## Burl (Jan 2, 2008)

Very cool. How much range do you get from the radio transmitter?


----------



## dbodnar (Jan 2, 2008)

Burl said:


> Very cool. How much range do you get from the radio transmitter?


The transmitter reached my scanner across the basement, about 35'.

Not bad for a $5.00 investment!

dave


----------



## Burl (Jan 2, 2008)

Pardon me if this has already been asked, but have you thought about using infrared LEDs for the detector?


----------



## dbodnar (Jan 2, 2008)

Burl said:


> Pardon me if this has already been asked, but have you thought about using infrared LEDs for the detector?


I considered it but the tolerances involved in getting accurate axle counts (especially at smaller scales) makes it difficult. The lasers are quite easy to align as you can see the beam and be assured that it is just above the rail.

I use a pulsed IR LED on my speedometer (see: http://www.trainelectronics.com/speedometer/speedometer_manual.htm ) but opted for lasers here.

Could it be done with IR sensors? Probably. Does it work with lasers? Absolutely!

dave


----------



## Burl (Jan 2, 2008)

How do the IR sensors work outside? Any interference from natural light?


----------



## dbodnar (Jan 2, 2008)

Burl - if you use pulsed IR (which I do on the speedometer and other projects) and place the detectors so that they never see direct sunlight they work very nicely

dave


----------



## backyardRR (Aug 14, 2012)

Quote:
*"Could it be done with IR sensors? Probably. Does it work with lasers? Absolutely!"*

From today's NY Times.

_Charles H. Townes, Who Paved Way for the Laser in Daily Life, Dies at 99_

_Charles H. Townes, a visionary physicist whose research led to the development of the laser, making it possible to play CDs, scan prices at the supermarket, measure time precisely, survey planets and galaxies, and even witness the birth of stars, died on Tuesday in Oakland, Calif._
_He was 99._


----------

