Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Random operating lights in structures?

10474 views
43 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    August 2003
  • From: Collinwood, Ohio, USA
  • 16,367 posts
Posted by gmpullman on Sunday, June 5, 2016 2:04 PM

RR_Mel
As usual Randy is right on the money with the ULN2003!  I checked into them and for $7.54 I have 10 boards on the way.

Excellent! Just the information I was looking for...

Thanks again to you both, Mel and Randy. (and Dave for starting the whole thread!)

Regards, Ed

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Friday, June 3, 2016 2:04 PM

As usual Randy is right on the money with the ULN2003!  I checked into them and for $7.54 I have 10 boards on the way.
 
I tested the one I have and it’s working from an Arduino Uno perfectly.  It was labeled Stepper Motor Driver in the Startup Kit so I didn’t go there.
 
Ed that board should work fine for what you want to do.  I know they will make my dinking around much easier.
 
Thanks again Randy!
 
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Friday, June 3, 2016 12:11 PM

 The ULN2003 isn't specifically a 'stepper motor driver' - they use it as oen in a lot of the starter kits. It's really just a package of 7 Darlington transistors with snubber diodes included (but when driving a relay you really should still add your own snubber diodes and not rely on the chip). So it can be used to turn anything on and off, up to the rated current and voltage (I think it's 40V). 4 of the outputs together can form an H bridge to drive a DC motor with PWM, like a DCC decoder's output stage, or pretty much anything else you can think of. The actual ULN2003 library in the Arduino IDE is probably geared towards using it to drive a stepper motor, for lights or other simple on/off operations you wouldn;t even need a library, just connect say D5 output to one of the UNL2003's inputs and turn it on and off with basic digitalWrite commands.

 There are other options as well, all you need is a buffer chip to allow the relatively low power Arduino output pin to drive a larger load. Even a basic transistor circuit would work - examples can be found on many of the relay boards. Much of that stuff is open source hardware so the schematics are freely available, instead of the relay coil and the snubber diode you would connect your LEDs there and that's it. All that transistor is doing is acting as a higher current switch to control teh relay coil since the Arduino can't do so directly. Whether it controls a relay coil or a string of LEDs really makes no difference. There are some technicalities that could affect how this works but experimenting is aprt of the fun and worst case with the transistor driver is you either can;t turn the LEDs off or they won't come on, it wouldnt fry anything. The ULN2003 and similar chips shouldn;t have any issues with this unless you exceed the maximum current

                       --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Friday, June 3, 2016 9:40 AM

I didn’t know the Arduino ULN2033 stepper motor driver could be used to drive switched outputs, my Arduino starter kit came with a ULN2003.
 
My current demand is very low, 35ma at 9½ volts for most ports with a max of 60ma.  I went with 2N3904 200ma transistors as a voltage interface from my 9½ volt lighting power supply.  200ma will handle almost all of the goodies on my layout, for high current things I use TIP-31 & TIP-3055.
 
You wiil have look too Randy for info on the ULN2033, the Arduino programming is a bit over my head.  I got the hang of programming the Uno to do what I needed by starting out with a Sketch from the Arduino library, it was close enough to get me going then I did some Mel mods to the timing to get it to do what I wanted.  Scratch Programming isn’t my thing.
 
I got hung up trying to build up a sketch to operate a mini stepping motor as a wig-wag, after way too much time involved I put everything in a bin box on the shelf.
 
 
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
  • Member since
    August 2003
  • From: Collinwood, Ohio, USA
  • 16,367 posts
Posted by gmpullman on Thursday, June 2, 2016 8:08 PM

This was the relay module I had in mind, Mel, but as Randy points out, there are better options.

http://www.allelectronics.com/make-a-store/item/rlm-4/4-channel-relay-module/1.html

I can't imagine the micro-relays are all that noisy but they do place a mechanical link into the chain and I surely don't need the 10 amps!

I'll stick with all solid-state.

[edit::] It didn't take long to find a neat 2A solid state relay.

http://www.ebay.com/itm/4-Channel-5V-Solid-State-Relay-2A-For-Arduino-UNO-MEGA-2560-R3-AVR-Raspberry-PI-/171923205134?hash=item28076bec0e:g:RM0AAOSwPhdVKSCd

 

Thanks Mel, Thanks Randy...

Ed

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Thursday, June 2, 2016 7:59 PM

ULN2003 drivers, 5 for $4 or less oon ebay - each of the 7 outputs on the ULN2003 can drive up to 500ma, about 2.5 amps total for the chip (so obvious all 7 can't run at 500ma). At 300ma per output, that's at least 30 LEDs at 10ma each. That should be sufficient for darn near anyone's town - 210 LEDs, plus you can use more than one per Arduino since there are more than 7 output pins. And there is a library for accessing the ULN2003 chip already in the Arduino IDE. I'm using one to drive the relays for my Test Track Switcher - though it turns out the relays I bought are such low current I can actually drive them direct from the Arduino pins.

                          --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, June 2, 2016 6:22 PM

gmpullman

 

As inexpensive as these processors are, it is worthwhile to have a dedicated one for each structure.

Thanks again, Ed

 

 

Ed you need to determine the LED load current for each output.  The Arduino Uno doesn’t have much current handling ability, I don’t remember off hand how much current the Uno will sink.  I wouldn’t go with relays . . . . the relay chatter would drive me crazier than I already am.
 
You might have to make a transistor driver board to handle the current.  The Arduino has more accessories available than you can imagine.  I went with a blank breadboard Shield, Arduino calls the add-on boards Shields.
 
You need to visit the Arduino site for more info.  I bought a Arduino book for $15 off eBay that was worthless, the site is full of info.
 
I have two Arduino Uno controlling two structures for a total of 24 lights.  I’m going to add a third to control several animated goodies.
 
 
 
 
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
  • Member since
    January 2008
  • From: Big Blackfoot River
  • 2,788 posts
Posted by Geared Steam on Thursday, June 2, 2016 5:51 PM

I'm glad I caught this thread the second time around, you guys have me wanting to pick this up and start playing.  Idea

Thanks!

"The true sign of intelligence is not knowledge but imagination."-Albert Einstein

http://gearedsteam.blogspot.com/

  • Member since
    August 2003
  • From: Collinwood, Ohio, USA
  • 16,367 posts
Posted by gmpullman on Thursday, June 2, 2016 5:46 PM

Thanks for that update, Mel!

Like your setup, I planned on having 12 outputs. I wasn't sure what the current was rated on the output that's why I was thinking of the relay board but it may not be necessary. 

I have been browsing the tutorials here:

https://www.arduino.cc/en/Guide/HomePage

As inexpensive as these processors are, it is worthwhile to have a dedicated one for each structure.

Thanks again, Ed

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, June 2, 2016 4:43 PM

High ED, good news!

 

Randy convinced me to try the Arduino so I bought an Arduino Uno and it works GREAT.  Because I use 12 volt bulbs in my structures I needed to make an interface on a Arduino expansion shield breadboard.  I dinked around with the programming and ended up with a super slow 12 lamp random cycle, it is fabulous!!!!
 
If you are using LEDs the Arduino will drive them direct, no other devices needed.  I already had several 5 volt power supplies, that’s all you need besides the Uno.
 
I bought a second Arduino Uno and made a second random light unit.  I may have $25 tied up in both lighting units so they are cheap to make and work better than any I’ve seen on the market!
 
Thanks Randy!!!!
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

  • Member since
    August 2003
  • From: Collinwood, Ohio, USA
  • 16,367 posts
Posted by gmpullman on Thursday, June 2, 2016 3:39 PM

hon30critter
I'm thinking of something like an apartment building or an office building where I want lights in various rooms to turn off and on on their own in a random pattern.

Dave, Mel, Randy—

It has been four months since this thread ran its course and I wondered what circuitry and program you settled on for your random lighting generator.

I'm at a stage where I'll be installing the lighting in several multi-story downtown buildings and I'm interested in jumping into the Arduino pool.

I recieved an All Electronics catalog yesterday showing relay modules that I believe would be needed for my use since I'll probably be driving several dozen LEDs on each output.

I'm just curious about which board you used and if you would do anything different. Did you modify an existing Arduino "sketch" or did you write your own for the random effect?

Thanks, Ed

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Friday, February 5, 2016 4:54 PM

 For the small ones, I just came across this. I don;t have one, so I am only going by the description, but it syas it has the Arduino bootloader in it so it programs from the Arduino IDE just like any other one. It's super tiny, there are 4 usable pins (6 total but 2 are for USB)

http://www.ebay.com/itm/2X-PCS-Digispark-Kickstarter-Attiny85-USB-Development-Board-for-arduino-/191722373418

I did just order other items from this seller so we shall see what sort of quality they offer. But for a small structure or whatever, this teeny little boards might be useful.

Edit: Same seller has them in 5 packs at $13.75 - $2.75 each! Insane.

 I'm finding all sorts of neat stuff to mess around with. I need to get working on my workbench design - I have room and an idea for an L shaped table made from a couple of solid core doors, one leg will be for my modeling stuff, the other for electronics, with a computer in the middle - I have some electronic test equipment that can be controlled/monitored from the computer plus the DCC programmers like PR3 and Lokprogrammer.

                            --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Friday, February 5, 2016 1:12 PM

Actually Randy 12 ports worked out perfect.  For some odd reason that’s the maximum number of rooms that I illuminated in my houses (two mansions), 10 lighted rooms and 2 porch lights the rest have either 4 or 5 lights per house.
 
I bought some 3.3mm diameter micro stepper motors to operate my wig wags so that’s next on my project list.  I installed some micro LEDs in the swing arms quite awhile back and I was planning on using a servo on a steel wire for movement but I should be able to drive a stepper motor to swing the pendulum.  The 3.3mm motor should be the about right size for HO.
 
 
 
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Friday, February 5, 2016 10:50 AM

 It's fun, and addictive, isn't it?

If you need to control more LEDs then there are ports, your starter kit probably came with a 74HC695 shift register - there are lessons in the learning material on using them. That lets 3 lines control 8 outputs. There are other more complex chips that can do even better - the code gets more complex as well, but you can control 64 or more individual outputs with just 3 of the Arduino's outputs.

                  --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Friday, February 5, 2016 8:51 AM

rrinker

 THat's why I suggested Arduino, boards can be had for not much more the PIC board, and no programmer needed, they have USB on them. Arduino was designed for non-engineers to work with. There are NMRA DCC, Loconet, and CMRI libraries already for Arduino.

 That's the key to a 'cheap' interface device for any bus, like LCC - someone, or you, needs to develop a library to access the protocol - not exactly an easy job but if someone does so and makes it freely available you can build on that.

                          --Randy

 

 

Thanks Randy!
 
I received my Arduino startup kit and you’re correct!  It is very easy to get it up and running.  On the second day I had a 12 light random light driver working on the breadboard.  I ordered some add-on Arduino perf-boards and used 2N3904 transistors to drive my 9½ volt incandescant house lighting.  Simple, very compact, low cost (under $10 total for the random light unit) and it works grate!
 
I’ve got two more projects under way using the Arduino Uno, one using micro stepper motors to operate my wig wag signal crossings.
 
Thanks again Randy
 
 
 
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Thursday, January 21, 2016 10:33 PM

No problem Mel. Appreciate your help.

Dave

I'm just a dude with a bad back having a lot of fun with model trains, and finally building a layout!

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, January 21, 2016 10:01 PM

hon30critter

Mel:

Thanks for the leads. Unfortunately that particular supplier doesn't ship to Canada but as I told Steve, the Canadian Amazon site has tons of listings for items available in Canada.

Dave

 

Sorry Dave, I forgot that you a Northerner.  When I placed my Buy it Now I bought from a US seller.  If your not selective there’s plenty of off shore sellers, most with better pricing too.
 
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Thursday, January 21, 2016 9:26 PM

Mel:

Thanks for the leads. Unfortunately that particular supplier doesn't ship to Canada but as I told Steve, the Canadian Amazon site has tons of listings for items available in Canada.

Dave

I'm just a dude with a bad back having a lot of fun with model trains, and finally building a layout!

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Thursday, January 21, 2016 9:23 PM

Randy:

Thanks for the explanation and for the offer of help. At the rate that I am getting information from you recently I'll have to put up a plaque with your name on it in the layout room.

I looked up the article related to the video that Steve referenced and it includes the 'sketch' needed to run multiple LEDs although the example only has one LED per output.

Here is the article for those who might be interested. If the link doesn't take you directly to the page, it starts on page 99:

http://mrhpub.com/2014-11-nov/land/#99

It would be amazing to have several dozen LEDs going on and off randomly with only one or two small inexpensive micro processors running the whole show. It looks entirely doable but I can just imagine the maze of wires under the layout!

Dave

 

I'm just a dude with a bad back having a lot of fun with model trains, and finally building a layout!

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Thursday, January 21, 2016 9:11 PM

Steve:

Thanks for the MicroCenter lead. I'm in Canada so that particular source is going to be expensive with the exchange rate and shipping.

I did a brief search on the Canadian Amazon site and the clones are actually available for only slightly higher amounts in Canadian $ and lots of the suppliers offer free shipping.

Dave

I'm just a dude with a bad back having a lot of fun with model trains, and finally building a layout!

  • Member since
    May 2011
  • 743 posts
Posted by Steven S on Thursday, January 21, 2016 8:52 PM

If you have a MicroCenter store near you, they have Uno clones on sale for $6, and Mega clones for $10.

http://www.microcenter.com/product/431997/Uno_R3_MainBoard

http://www.microcenter.com/product/431995/Arduino_Mega_2560

 

They only have 25 stores nationwide.  Here are the locations...

(scroll down)

http://www.microcenter.com/site/stores/default.aspx

 

Steve S

 

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Thursday, January 21, 2016 8:09 AM

 The most common Arduino, the Uno, has 20 outputs that can be used to switch LEDs on and off (the analog lines can be used for digital). They can only drive one or two LEDs directly, but you can find simple circuit examples that drive a transistor which can then drive a dozen LEDs per line or so, so you can run a whole town on a single Arduino and have multiple lights on multiple circuits in each building.

 The most basic beginner examples show you how to turn an LED on and off and make it blink. They will typicall just use one LED, often on pin 13 (because the Arduino has traditionally come with an LED already on the board, connected to pin 13, so you don;t even have to add external components). The key thing to take away from those examples to expand it to the concept of driving multiple LED circuits is the part of the code where you spcify which pin the LED is connected to. You can reference ANY pin number, so long as you hook the LED to it. Or many at the same time. In just a few minutes I had a Knight Rider thing going with 4 LEDs, and a simple change to the code made it just sweep in one direction instead of back and forth.

 It's really hard to actually damage anything by having your program incorrect, but when connecting things to the Arduino you do have to remember things like putting current limiting resistors on LEDs. Just like if you were powering them with a toggle switch instead of a miniature computer - concept as far as the LED circuit goes is exactly the same, the difference is with the Arduino, your program turns the LED on and off instead of your finger on the toggle. So the same wiring rules apply.

 ANd if you start playing around and need help with your sketch (see - Arduino was made for art students originally - it's not a 'program', it's a 'sketch'), I can help you out. I don;t need to have your exact circuit - you might have a transistor connected to the Arduino driving 10 LEDs, but the sketch is exactly the same even if all I do is hook 1 LED to mine. That is, of course, how you should start - one LED and resistor per output to test the program, then worry about the transistor driver later - the code would remain unchanged.

 There are other Arduino models better suited to building into a permanent circuit that are less expensive than the Uno - I also have a Nano, which basically looks like an overgrown IC chip but it runs the same code as the Uno and has the same outputs and I think the one I have cost $3.99. And if the 20 outputs aren;t enough, the Arduino Mega has over 60.

                      --Randy


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, January 21, 2016 8:04 AM

Hi Dave
 
I started out with experimenting with the PIC stuff and it didn’t go well.  A buddy, also ex electronics and model railroader, tried the PIC way but found it to complex and lacking in available information.
 
There seems to be a lot of information out there for Arduino and as advertised it’s made for dummies.  I bought two items off eBay, a Uno and a development kit.  I bought the Uno first then after rethinking about it I went for a development kit too.
 
 
 
Should be an interesting project.
 
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Wednesday, January 20, 2016 11:46 PM

Hi Ed:

I'm familiar with All Electronics but thanks for the links.

Dave

I'm just a dude with a bad back having a lot of fun with model trains, and finally building a layout!

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Wednesday, January 20, 2016 11:39 PM

Just ordered the book 'Arduinos for Dummys'. Sounds like its aimed right at my level!

Dave

I'm just a dude with a bad back having a lot of fun with model trains, and finally building a layout!

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Wednesday, January 20, 2016 10:10 PM

Wow - lots of possibilities!

For those who suggested the mechanical devices - thanks very much. I think I'm leaning towards the electronic options but I will keep the others in mind.

Neal:

The Random Lighting Control is a great product but I would need a bunch of them to do what I want because they will only drive 6 LEDs each. The low Canadian dollar is becoming a serious issue, and it is predicted to go even lower by the summer so buying 12 - 15 of the RLC units would get expensive.

Steve and Randy:

Arduino obviously addresses the issue about the number of LEDs that can be driven by a single unit, plus there is apparently greater flexibility in the timing settings.

Mel:

Where did you order your Arduino kit from? 

Thanks everyone!

Dave

I'm just a dude with a bad back having a lot of fun with model trains, and finally building a layout!

  • Member since
    December 2004
  • From: Bedford, MA, USA
  • 21,483 posts
Posted by MisterBeasley on Wednesday, January 20, 2016 7:47 PM

Take some pictures as you go, and keep good notes of how you program the Arduino unit.

This would make a great how-to article for a certain model railroading magazine.

It takes an iron man to play with a toy iron horse. 

  • Member since
    October 2014
  • 273 posts
Posted by LOCO_GUY on Wednesday, January 20, 2016 7:45 PM

Dave,

I don't have any answers to your question - but I can see how cool it would be to have a building have randon lights turning on and off.

Let us know if the Arduino kit works out.

In the old days we would have has a batch of switches to control the lighting - nowadays you can let a circuit board do it all for you. Is that progress?

Okay I'm a luddite that works in the computer industry - go figure.

Chris.

Loco Guy - is a state of mind - not an affinity to locomotives.

Sit back and enjoy your track...

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Wednesday, January 20, 2016 7:22 PM

rrinker

Arduino was designed for non-engineers to work with.

 

                          --Randy

 

You convinced me Randy, I have an Arduino Starter Kit on the way.  I’m hoping an old dog (ex 50 year electronics techie) can learn a few new tricks before he croaks.
 
 
Mel
 
Modeling the early to mid 1950s SP in HO scale since 1951
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!