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.
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.
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!
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.
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.
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.
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 http://melvineperry.blogspot.com/ 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.
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
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.
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.
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.
Ron!
Congratulations on taking the plunge!
Don't hesitate to ask questions if you run into a roadblock.
You can use 13 LEDs if you use one of the Analog pins as your control input
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.
Description: This is Arduino Uno R3. In addition to all the features of the previous board, the Uno now uses an ATmega16U2 instead of the 8U2 found on the Uno (or the FTDI found on previous generations). This allows for faster transfer rates and more memory. No drivers needed for Linux or Mac (inf file for Windows is needed and included in the Arduino IDE), and the ability to have the Uno show up as a keyboard, mouse, joystick, etc.
The Uno R3 also adds SDA and SCL pins next to the AREF. In addition, there are two new pins placed near the RESET pin. One is the IOREF that allow the shields to adapt to the voltage provided from the board. The other is a not connected and is reserved for future purposes. The Uno R3 works with all existing shields but can adapt to new shields which use these additional pins.
Note: The Arduino Uno R3 requires the Arduino 1.0 (or any other recent version)drivers folder in order to install properly on some computers. We have tested and confirmed that the R3 can be programmed in older versions of the IDE. However, the first time using the R3 on a new computer, you will need to have Arduino 1.0(or any other versions) installed on that machine.
Features:
These are the specs for my Arduino Uno clone. It appears I can use my 12 volt 500 ma power source to fire it up. That being so, what size resistors do I need for a low light effect? Modelling in the Civil War era, candles, gas lights etc. And maybe a variable resistance on the main to control overall brightness.
Ron Hume from down under.
Well sir, you certainly seem to have jumped in both feet first!
Seriously, for that level of lighting you will want to experiment with some fairly high value resistors.
I used 10,000 ohm resistors for the light over the conductor's desk in these cabooses (middle window). They look fine in daylight but they are a bit too bright at night:
I used 30,000 ohm resistors in this McKeen Motor Car and the LEDs are still too bright at night:
This picture was taken in a pitch black room but the LEDs are still a bit too bright when viewed in a night scene with normal lighting levels:
For your purposes I would suggest trying something around 48,000 ohms and maybe higher.
Mike Lehman is an expert in LED lighting. Hopefully he will chime in.
The nice thing about getting your resistance right is that resistors are cheap.
Good luck! Please show us your results.
The Arduino can use up to 12V because there is a 5V regulator on board. If you are going to low current gas light effects witht he LEDs, you should be fine with 10-12 LEDs connected to the Arduino. The voltage on the Arduino lines will be approximately 5V when on so Dave's resistor selection may be a little too high, since those are operating at 12V+. It's a good starting point though.
Another example to look at is the one that dims the LED using one of the PWM outputs on the Arduino. Get the parameters right and instead of just a dim LED you get perceptable flickering - just the thing to simulator oil lamps and candles. Keep in mind that while a 10K resistor may be fine for the nicely glowing LED at a full 5V, it may be too mig for the LED to light under PWM especially when set for very low duty cycles for the dim/flickering appearance - what's happening is that when PWM is enabled, the voltage is varying between 0 and 5V at a rate you can control with the program, and the ratio betrween the on and off times determines the average voltage the LED sees. So some experimentation is in order before you wire things to your layout for good. If you get no resistors less than 1K, you won;t be able to blow any of the LEDs up/ They might be too bright for your application but even if connected to 12V instead of 5V, 1K limits the current to well within what the LED can handle. Go up from there to get the brightness level that works for you. And remember that LEDs are polarity sensitive, so if you hook one up and your program doesn't turn it on, check that the LED is connected the right way as well as checking for a mistake in the program.
Wow! lots of info to take in. The PWM (what is that?) effect sounds ideal for some of the lighting. I,m going to need help with THAT sketch when the time comes.
I have some 1k ohm 1/2 watt resistors left from my LED toggle swiches on the control panel, I could try a couple of those in series to see what happens, but at present I'm wrestling with turnout positions for motors to avoid the framework lurking beneath. As to the request to post any outcome with pictures, I can't seem to find the instructions to post pictures. Saw them when I first joined, but they are now lost in the ether somewhere...
Ron from down under.
Simplistic explanation: PWM, at least in digital circuits like the Arduino, is usually based on a square wave. As opposed to the sine wave in your household AC power. Squar wave is exactly what it sounds like, looks like a series of squares (leaving off some highly technical stuff that causes the edges to never be nice perfect right angles like a square you would draw because, it doesn;t really matter here)
So, if you have a square wave that is on 50% of the time and off 50% of the time, you have a 50% duty cycle (how long it's on). In the case of an Arduino output, off is 0V and on is 5V. The peak voltage is 5V. But the AVERAGE voltage is determines by the peak and the duty cycle. This is the voltage 'seen' by most types of loads would in this case be 50% of the peak, or 2.5 volts. The duty cycle can vary from 0% (off) to 100% (full on - 5V). All the crazy timing stuff to generate this is taken care of by the Arduino. In place of the digitalWrite command (which just has 2 states, HIGH or LOW for on or off), there is the analogWrite command which takes a value from 0 to 255, where 0 is 0 % duty cycle and 255 is 100% duty cycle. There's yet another technical explanation for why the range is 0-255 and not 0-100 but suffice to say having more than 100 steps means each increment is less than 1%, so the control is fairly fine. Like the difference between one throttle that goes from stop to full speed in 90 degreees vs one that has a range of 320 degress.
And the cool thing about Arduino being so popular - if you search you can probably find that someone has already written a setch that makes an LED behave like a gas light.
The 'How To Post a Photo to the Forums' thread is the very first thread in the General Discussion category.
You just have a link to trains.com in front of the picture URL. If I take that out I can get to your pictures - so when you paste the link in your message make sure you erase the cs.trains.com/ part in the URL and it should work.
You have: http://cs.trains.com/i44.photobucket.com/albums/f34/ronhume79/Alice%20Rocks_zpsc2fjqhc1.jpg
SHould be:
http://i44.photobucket.com/albums/f34/ronhume79/Alice%20Rocks_zpsc2fjqhc1.jpg
In the meantime Randy, a more pressing problem.
I connected the Uno to my computer and it began blinking right away. I copied a sketch ok without errors, but had a problem when the sketch wouldn't download to the board. Computer shows it's connected to COM3 but I don' think it knows that, because when I request board details, it asks to specify a COM port. Any clues?
Tried changing port from 3 to 2 as suggested in troubleshooting but no go.
Also, "This device is working properly".
Get "Can't work with USB 3.0"
How do you know it's connected to COM3? Are you seeing COM3 appear and disappear in Device Manage when you plug and unplug the Arduino? If so, then COM3 it is. Next, with the Arduino plugged in, go into the Arduino IDE and under Tools you need to select the proper board and the port, If the board is the one you pictured, select Arduino/Genuino Uno for the board type. And under port it should list COM3 is that's the one being used. Just checking here on my laptop, which with nothing plugged in has a COM1 (it has a real serial porton it, not just USB) and that's all that shows up until I plug an Arduino into one of the USB ports. I don't have one with me but whatever port it gets shows up there along with the COM1 that is always there. Most of the cheap clones use a USB chip that doesn't register with the computer in any way, so if you plug it in to a different USB port it will likely be a different COM port - so always use the same USB port if possible so you don't have to keep changing the settings in the IDE.
COM3 is fairly common. My workbench computer has a bunch of USB cables plugged in (my Uno and Mega use the big 'B' plug, the Nano uses a microUSB) so depending on which Arduino I plug in I have to swap the com port in the IDE, one gets COM4 and the other gets COM5 (I have a whole bunch of stuff connected to this computer - I think my oscilloscope gets COM3)
Randy,
It appears the Arduino library was misplaced, fixed that and hey presto! My sketch works. Haven't found how to place the sketch into the library yet, but I guess I will eventually work it out. Time to purchase lots of LEDs!
EBay is a great source for LEDs of all kinds. If you want some pointers on what types are suited to structure lighting let us know.
By the way, congratulations on your rapid advancement in Arduino technology!
DOn't worry too much about libraries. If you buy some add-on hardware that is not supported by one of the buitl in libraries, you will need to download and install the library for that hardware, but your own stuff you generally won't be building libraries at this point, just creating sketches that use existing libraries. Those get saved seperately from libraries. Unless there is something non-standard on your computer, best to let the IDE save things hwere it wants to, at least at first. Mine's a little more complicated, I save my stuff on my OneDrive so I can open them on any of my computers but for just one computer I'd let the IDE save sketches where it wants to when you click save. Once you get more comfortable you can experiment with saving files in different places. The IDE is very picky about everything having a folder though, and libraries in particular are expected to conform to a specific layout of folders where each of the files lives.