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 switching for structure lighting

8514 views
45 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Monday, October 17, 2016 3:51 PM

 You can use 13 LEDs if you use one of the Analog pins as your control input Big Smile

Or use all 5 of them for control over 5 zones, each with 1 or more LEDs

Digital input on an Alalog port works. For the ultimate in crazy features - use some pots on the analog lines to adjust the delay and random factors, then you can adjust things without uploading a new program each time.

But that is quite straightforward and about the only 'advanced' feature is the use of the array for the 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 Monday, October 17, 2016 11:07 AM

Ron
 
This is the Arduino Uno Sketch for my 12 port Random LED driver.
 
 
#define numleds  12                                                      
byte ledpins [ ] =  { 0,3,4,5,6,7,8,9,10,11,12,13 } ;
void setup( )  {                  
    for ( int  i=1; i <= numleds;  i++ )  {     
    pinMode ( ledpins [ i ], OUTPUT) ;
    digitalWrite ( ledpins [ i ] , HIGH) ;
   }
   pinMode (2,INPUT);      // Pin 2 will be the control pin for this lighting group
   digitalWrite (2,HIGH);    //This turns the Pull up ON
}
void loop ( )  {  
                digitalWrite ( ledpins [ random ( 0, numleds+1 ) ], lightsw ( ) ) ;
                delay ( 4000 ) ;                  
}
boolean lightsw ( )  {
 if (digitalRead(2)  == LOW) return LOW;  //If the group control pin is LOW ALL lights
                                                             // will eventually turn OFF
 if  ( random (0,100) > 60 ) return LOW ;
   else return HIGH ;
}
 
 
A simple copy and paste should work.  The output pins are:
 
0,3,4,5,6,7,8,9,10,11,12,13
 
The common is +5 volts
 
The timing is the numbers in red, changing the value changes the on/off timing . . . .  the timing doesn’t have any effect on the sequencing, it remains random.  I like long intervals.
 
Grounding pin two will eventually turn OFF the outputs.
 
 
  
 
 
I used 560Ω ⅛ watt resistors in series with each LED, the load at 5 volts is about .05 watts.
 
You can vary the series resistor from about 220Ω up for brightness.  I never run my LEDs higher than 12 ma, most are well under 5 ma.  Bright lights don't work for me on my layout, for me the realisum goes away rapidly with increased brightness.
 
Good Luck
 
 
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 Monday, October 17, 2016 10:01 AM

Ron!

Congratulations on taking the plunge!

Don't hesitate to ask questions if you run into a roadblock.

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
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Monday, October 17, 2016 6:53 AM

 The Arduino IDE includes all the sample coide to learn from. The very first one is pretty much all you'll need for 'random' lighting - it's called Blink because it makes an LED blink. You can access all the tutorials online at the Arduino site so you can get the explanations for each line of code. The default in blink is I think every second or every half second. It will be pretty obvious how you change that. Adding more output lines to control more LEDs is a later tutorial but it's really just a variation on the blink program.

 The language used in the Arduino IDE is mostly C++ but for what you are trying to do there is no reason to attempt to learn the entire language, you will only be using a minor subset of it to write the kind of Arduino programs you need to turn LEDs on and off.

 There are other ways to program Arduinos besides the Arduino IDE, but all of them are more complex than the standard IDE so those options are best left until you have some more experience. A true Arduino clone will have the Arduino bootloader already programmed and will plug in to your computer and the IDE will just work. Some of the ones I have came with the Blink sketch already loaded - as soon as I applied power, the LED started blinking. That almost requires you to adjust the delay times in the Blink sketch so you know you board successfully accepted the upload of code - if you just upload what's already there, nothing will change and the LED will blink away, but if you change the speed of the blinking, you will see it change when you upload.

 Unless you bought a starter kit that comes with a bunch of parts, you won;t be able to actually build the various demonstration circuits. Mostly you only need to work with the ones that control LEDs, because that it what you are trying to do, so if you don;t have them you might want to get some LEDs and resistors, a small breadboard, and some jumper wires so you cna play around with this while learning.

                             --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
    June 2016
  • 81 posts
Posted by Ron Hume on Sunday, October 16, 2016 7:51 PM

Thanks to Mel, Dave and Randy for your responses. After a litle research, I decided to, "have a go mate" and bought an Arduino clone on ebay. (Unable to buy the genuine article in Australia.) I've downloaded the program and wait for the delivery, hoping the program language is compatible. I believe it should be "C++" but some clones are advertising "java" as the lingo.

I copied a sketch from the web to get me started, hoping I can tweek it to meet my needs. Had a quick look at a C++ tutorial, but it's too much of a steep learning curve at my age. Once again, thanks for the advice.

Ron Hume.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Sunday, October 16, 2016 1:03 PM

 And if you are afreaid of ripoffs on eBay, there are similar priced Arduino options on Amazon, even ones with Prime shipping. I have a stack of them now, an Uno, a Megas, about a dozen Nanos, and a half dozen ATTiny85's that I've installed the Arduino bootloader on so they can be programmed like any other Arduino, just less pins.

 For one or two LEDs per pin, no, no additional driver circuitry would be needed. I guess I just think bog - even on our temporary 4x8 we built each year, every structure had a light in it. If instead of one central light, that same small layout and same number of buildings, but with multiple LEDs to be lights in different rooms plus exterior lights, it would have been 40 or more LEDs. Lots of outputs especially in the Old West town if I wanted to have the lights flicker like candles and oil lamps. I don't even want to think how many I will have in my still planning basement size layout. Although I'm thinking in many cases, each structure would have its own small chip, like the Tiny85 (there are others witht he same 8 pins, same outputs, just less RAM and Flash, which should be fine for simple light on/off programs, but they aren't always cheaper). That way there's never be any synchronization between lights going on and off in different buildings close enough to make it obvious they are ont he same circuit. Plus each structure would just need a power supply connection, not multiple wires coming from the centralized controller to the individual LEDs. The thing is, it is super easy to crank these things out by the dozens - once you have one program that works, you edit a couple of numbers to change the cycle time, making some stay on longer and others run for shorter times, and just keep blasting the otherwise same program to each chip. A mini experimenter board (you used to get them at Radio Shack, they should be available at other places) with an 8 pin socket and pads around the outside to connect wires for the LEDs in another thing you cna mass produce with an hour at the workbench, and then install in every structure that will get lights.

                                 --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, October 14, 2016 11:34 AM

rrinker

 

 

 Oh, LEDs, I was trying to figure out what that was on the right. If you really are using anywhere near the current limit of the ULN2003's, you probbaly wany yto feed the whole thing with a 5V power supply - the regulator on the Arduino (not to mention the USB port) can;t really supply that much current. If you put a barrel connector on your shield connected to the +5 and gnd lines, it will also power the Arduino. I'd also put something like a 10uF electrolytic across the pins of it for some decoupling. Use a 5V 500ma wall wart to run the whole thing - or if you already have a higher voltage power bus on your layout, build a simple 7805 regulator circuit on your board (a small heatsink might be needed on the regulator) and power that with your power bus, connecting the 5V and ground outputs to the proper pins.

 

                                --Randy

 

 

Randy
 
I rarely ever drive my LEDs more than 10 ma, they probably average in the vicinity of 5 to 7 ma.  The LEDs on the expansion shield are running under 3 ma.  They only need to be visible for testing the Uno.
 
I built up three driver shields using ULN2003 chips to drive my incandescent structure lighting.  I use 12 volt 40 to 70 ma bulbs operating from a 9½ volt regulated power supply for realism and longer bulb life.  I feed the expansion shield with the 9½ volts and the drop through the 2003s is about .7 volts, the lighting looks great at just under 9 volts.
 
Ron won’t need the high current driver for single LED per port operation. The Arduino Uno spec is 20 ma per port.   
 
I made a USB power strip that plugs into the 2 amp USB wall wart, it’s powering all three Unos for my random lighting, the 36 ports run my entire layout.
 
By the way, Thanks Randy for pointing me to the Arduino and the ULN2003!  The 2003a sure beats using a dozen transistors.
 
 
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 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Friday, October 14, 2016 11:01 AM

Ron
 
I bought an Arduino Kit to get started but that wasn’t necessary, I bought a second Arduino Uno from a USA seller on eBay for $6.89 free shipping.  His price has increased to $7.25 free shipping.
 
 
The Uno comes with a short USB cable ready for programming.
 
I bought a USB wallwart power supply like the ones to charge cell phones and tablets to power the Uno for operation.
 
 
I will either post the program or I can send it to you, it’s a simple copy and paste to the Arduino (free) software and point and click to upload to the Uno.  Piece of cake!
 
Total investment, $13.74 for a 12 port LED driver . . . . not bad, $1.15 per LED driver port.  
 
 
 
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, October 14, 2016 10:34 AM

RR_Mel

Piece of cake Ron, Arduino Uno.  You can direct drive 12 LEDs from the UNO with a random sequence.  You can pick up a UNO for under $6, they run off 5 volts DC.
 
The Uno has a max current of 20 ma per output, if you’re not using LEDs you can make a 500 ma driver for about $6.
 
Edit:
This is a picture of my 12 port 500 ma driver
 
 
The 13 pin micro connector next to the ULN2003 chips is the high current output connector to my buildings.  The 13 pin connector next to the LEDs is the LED output connector.  The LEDs on the board are for testing the Uno, they plug in to sockets and are removable.
 
 
 
I haven’t tried to post an Arduino sketch before but I’ll figure out how to do it if you need one.
 
 
 
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.

 

 

 Oh, LEDs, I was trying to figure out what that was on the right. If you really are using anywhere near the current limit of the ULN2003's, you probbaly wany yto feed the whole thing with a 5V power supply - the regulator on the Arduino (not to mention the USB port) can;t really supply that much current. If you put a barrel connector on your shield connected to the +5 and gnd lines, it will also power the Arduino. I'd also put something like a 10uF electrolytic across the pins of it for some decoupling. Use a 5V 500ma wall wart to run the whole thing - or if you already have a higher voltage power bus on your layout, build a simple 7805 regulator circuit on your board (a small heatsink might be needed on the regulator) and power that with your power bus, connecting the 5V and ground outputs to the proper pins.

 You should be able to copy and paste an Arduino skecth - however it will not have line feeds so it will appear as one big line until you go back and insert aa return at the end of each lines. Most of it you can get by doing a search and repalce and replace every ; with ;<cr><lf> since all code lines end with ;, and then fix up the function definitions and comments which won;t have ; in them. Otherwise the .ino files are plain text and can be opened in Notepad as well as the Arduino IDE. You can copy/paste right out of the Arduino IDE.

                                --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
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Friday, October 14, 2016 10:22 AM

 There was an item in the new products section of last month's MRH that mentioned a 6 line device from NJ International but I don't see it on their web site. About the only sure thing is it will cost a lot more than an Arduino Uno board and a few hours poking through the standard LED blinking tutorials to see how you turn the lines on and off and set delays.

 Keep in mind the drive behind the Arduino was to enable ART STUDENTS to include high tech interactive stuff in their works - there are some that are designed to be sewn into clothing, for example. It's why what everyone else in the world calls a 'program', the Arduino world calls a 'sketch' Art students - not engineers.

                         --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
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Friday, October 14, 2016 12:47 AM

Ron:

I think you would find that setting up an Arduino would be simpler than what you are picturing in your mind. If you can use a computer keyboard, which you obviously can, all you would need to do is plug a USB cable into your computer and copy some text. You don't have to understand computer programming with its "foreign language".

Wiring the system would be no different from what you would have to do to use a timer switch.

You will need to get a different power supply. The Arduinos operate on either 3.3 volts or 5 volts IIRC.

 

There are devices that will do what you want without any need for programming. Ngineering is one source that offers structure lighting animation systems. Unfortunately they will only drive three LEDs each so the cost will add up if you need to use a bunch of them. Go to the Lighting Effects Products page. If the website view is messed up try using Firefox:

http://ngineering.com/lighting%20effects%20for%20structures.htm

Your power supply will work with the Ngineering components.

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 Friday, October 14, 2016 12:18 AM

Randy convinced me to go Arduino, I’m sure he can convince you too.  Unless you can find a cheap used mechanical cam/micro switch assembly anything else will be in triple digits.
 
Going fancy with an Arduino Uno is by far the cheapest way to go.  This forum is loaded with Arduino help.
 
You can use an Arduino Uno to drive 12 LEDs without even having to solder anything, everything plugs in.  The software is a freebee and the Uno will plug into a USB port on your computer for easy programming.  The Uno will run on a 5 volt wallwart, we are talking less than $15 to your door for all the components for 12 random 20 ma outputs.
 
Guys, jump in and convince Ron that he can do it.
 
 
 
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
    June 2016
  • 81 posts
Posted by Ron Hume on Thursday, October 13, 2016 11:32 PM

Thanks Mel,

Sadly I don't understand foreign languages or programming. I have a 12 volt 500 ma power source and I'm just looking for an off the shelf gizmo to do the job. A timer switch with half a dozen outputs? Something like that.

Ron Hume.

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Thursday, October 13, 2016 8:21 PM

Ron:

I'll second Mel's recommendation to use Arduinos. I'm just in the process of learning how to program them, but code for your purposes can be found on the internet already written for you. Model Railroad Hobbiest has had a series of articles on the Arduinos, at least one of which addresses random lighting.

http://model-railroad-hobbyist.com/

The on-line magazine is free and you can reference back issues.

 

One suggestion I read about house lighting is to set lights up in adjoining rooms so that one goes off and the other comes on after a very slight pause. That mimics the effect of a person turning the lights off as they leave a room and turning the lights on as they enter the next room.

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
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Thursday, October 13, 2016 4:34 PM

 Or make the driver anyway, and run a bunch of LEDs off each port. a bedroom in this house, an office window in that building over there, etc. all on one channel, then say another room in the house, a store, etc on the second channel. Just not multiple ones next to each other so it's obvious they are going on and off together.

                       --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, October 13, 2016 10:12 AM

Piece of cake Ron, Arduino Uno.  You can direct drive 12 LEDs from the UNO with a random sequence.  You can pick up a UNO for under $6, they run off 5 volts DC.
 
The Uno has a max current of 20 ma per output, if you’re not using LEDs you can make a 500 ma driver for about $6.
 
Edit:
This is a picture of my 12 port 500 ma driver
 
 
The 13 pin micro connector next to the ULN2003 chips is the high current output connector to my buildings.  The 13 pin connector next to the LEDs is the LED output connector.  The LEDs on the board are for testing the Uno, they plug in to sockets and are removable.
 
 
 
I haven’t tried to post an Arduino sketch before but I’ll figure out how to do it if you need one.
 
 
 
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
    June 2016
  • 81 posts
Random switching for structure lighting
Posted by Ron Hume on Thursday, October 13, 2016 9:53 AM

I'd like to switch about a dozen individual structure lights on and off randomley at about a minute duration to simulate people movement. Any ideas as to how to go about it?

Ron Hume.

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!