On to my software comment. If you only want to turn one light on, then off, your approach works fine. But if you want to simultaneously control, say 15 lights, the use of delay() will not work. delay() basically stops all processing on the Arduino and you end up losing a HUGE amount of computing power. The solution is to create a class - name it LED - which supports a number of methods, and which monitors whether the LED is currently on or off. At the start of the loop() function, you must refresh the led state by calling, for example, Green.refresh(); where Green is a LED object and refresh() is a method provided by the LED class. Then the rest of the loop() function allows you to modify the state of the LEDs. This makes your sketch look like this (for a simple example): #include LED Red = LED(6); LED Green = LED(A0); LED Yellow = LED(13); void setup() { Green.blink(100,200); Red.blink(250,250); Yellow.blink(500,100); } void loop() { Green.refresh(); Red.refresh(); Yellow.refresh(); } In this example, a red LED is connected to digital pin 6, a green LED is connected to analog pin 0, and a yellow LED is connected to digital pin 13. The blink method (provided by the LED class) turns the LED on for the first specified interval, then off for the second specified interval, then repeats. Here is the important part: there are NO delay() function calls - not in the sketch above, nor in the LED class code in LED.h. Each LED object maintains its own timer, and decides whether the LED should be on or off. Every call to refresh causes the corresponding output pin to be set HIGH or LOW, as required. This frees the Arduino to do other tasks simultaneously. Bottom line: If I could give just one piece of advice to new Arduino programmers, it would be this: find a way NOT to use delay(). It is a very effective way to paint yourself into a corner!
@joec60548 ай бұрын
Thank you for your input!! I am one of those beginner programmers and this info was very helpful!
@TheSwitchList2 жыл бұрын
Hi Jimmy. Nice video - one comment. For the random lights project - the Arduino random(x,y) will return a value between x and y-1, so the sketch needs to be modified to use randomlight = random(3,7), instead of randomlight = random(3,6) - or the LED attached to DIO 6 will never come on. -Rick
@DIYDigitalRailroad2 жыл бұрын
good call.
@rwissbaum98492 жыл бұрын
Jimmy, this is a great intro and I hope that Arduino beginners are encouraged to start an Arduino project. I have two comments - one on the hardware and one on the software. Regarding the hardware, I use Nano clones for all of my light and sound effects. You can get Nano clones for about 10 bucks each; name brand Nanos are about 15 bucks if you buy in bulk. (These prices have gone up a LOT due to Covid supply chain issues!) By contrast, an Uno costs over $20, and an Uno clone is between 15 and 20. Since you'll be mounting the Arduino under your layout, each Arduino project becomes a significant cost - say, equal to a ready-to-run freight car. Once I've tested my circuit and software, I mount my Arduinos on a circuit board (or bread board) along with all resistors and connectors. You can get an assortment of 100 circuit boards for $15, and 60 2-pin screw terminals for another 15$ on Amazon. The completed board can be powered by a 15 VDC power bus; no USB cable required. BUT, be sure you can access the USB connector on your Arduino so you can modify the programming later!
@DIYDigitalRailroad2 жыл бұрын
I use Nanos too for nearly everything on my railroad. I typically only use UNOs for prototyping. If I need a ton of I/O, I step up to a Mega.
@kenshores99002 жыл бұрын
Jimmy: Very good presentation. My eyes didn’t roll back.
@DIYDigitalRailroad2 жыл бұрын
Always the goal haha!
@donaldkormos55292 жыл бұрын
Thanks for another nice Arduino video!! The Arduino ability to introduce randomness ... using Random(x,y) function calls ... for lighting, sound, and motion controls ... is it's highlight for model railroad applications in my opinion. As you pointed out, it can make a building look more realistic with random room lighting. It can make a city scene look more realistic with buildings being randomly or (semi-randomly) lit depending on the time of day you wish to simulate. I'd like to add this realism with a fast clock so that I can watch my city scene change from one day into another. While each day is similar to the previous day ... each day slightly different from each other as in real life. Suggestion. Maybe you could discuss fast clocks in a video. JMRI has some fast clock features but I don't know how to use them.
@darrellrisley2 жыл бұрын
Great job Jimmy! Love the new format of writing the code then explaining it. I must confess, I watch all your videos but sometimes got bogged down with the line by line explanations.
@thesheq50232 жыл бұрын
On the last example you should include a time off=rand() as well so they’re not on immediately after one goes off
@BaileyWeathers-m1l8 ай бұрын
Hi Jimmy, what do we need to use to power the arduino and can it be done with batteries for these projects?
@melkitson2 жыл бұрын
Another nice one Jimmy. Beautifully explained. I have used someone else's example for my Outland Models buildings which makes such a difference. I have more than a dozen lights with the randomness projected to allow more than one light on at any one time. The whole lot could therefore be on at once. I like the simplicity of your presentation and especially the police lights.
@DIYDigitalRailroad2 жыл бұрын
Thank you for the kind words!
@kend39002 жыл бұрын
Very illuminating video !!
@DIYDigitalRailroad2 жыл бұрын
I see what you did there.
@eugenedrees61638 ай бұрын
Thanks!
@chrispainter78942 жыл бұрын
Hi from the UK Jimmy and thank you for your great video. Could you please consider a follow up video explaing how you would get the lighting effects actually onto the layout and the wiring involved.... I am imagining a police car sitting on top of the breadboard on the layout! Cheers Chris P
@AlanReynolds2 жыл бұрын
I'm definitely saving this one to come back to!
@cmmagic622 жыл бұрын
FANTASTIC intro video!
@Cbtrainnut2 жыл бұрын
Nice tutorial! I can almost understand! How do you get the lights from the bread board to a police car?
@johnschutt91872 жыл бұрын
Do you need a separate Arduino for each of the programs or could they run together on one Arduino?
@markr53132 жыл бұрын
ok so i am new to this programming stuff, i just purchased my first arduino from amazon via your site. now in addition to this arduino down load do i need to also install the GITHUB you talk about or is that automatically installed when i down loaded arduino.
@vincenthuying982 жыл бұрын
Very cool 😎 vid Jimmy. Love how you make the Arduino Uno so intricately accessible. Thanks 🙏 for sharing!
@kurtludwig69628 ай бұрын
Just thinking past learning beginning arduino I have questions Stationary steam engine smoke in layout? Belt drive machines in saw mill?
@tubutubutubu57552 жыл бұрын
You can use a short connecters , we can see easy cuircuit
@clayton4115 Жыл бұрын
how does one put these projects in the actual model railway layout, you have shown us using the breadboard etc but how is this wired up in an actual place on the model layout?
@johncloar16922 жыл бұрын
Thanks for sharing!! Love Arduino projects!!
@moisesbursztein28302 жыл бұрын
Thank you very much, these arduino projects are exactly what the doctor ordered. BTW I don't need another mug but I have to get the one with the coffee and the train.
@Mike__B2 жыл бұрын
Out of curiosity, for the first one (police flashing lights) do you need to write the low state to an LED that is already in the low state from the prior iteration? Or is it more just for seeing what's going on in the code at each iteration?
@markr53132 жыл бұрын
hey jimmy; hope this message finds you well. so i purchased my first arduino kit and started playing with it. when i ran your chasing lights and random programs i found an issue with chasing lights #6. it comes on at the same time as #3 and does not seem to chase well, second, with the random light #6 does not work at all. now being i am extremely novice to this coding, i was wonder if there is a fix. please advise thank you
@joec60548 ай бұрын
I'm new at this and already I have problems!! I built the project but writing the code is the issue... The word "setup" , on my IDE console is RED . How do I get it to Black ? When I try to run the example on my Arduino UNO it gives me an error that pinmode is not defined? How do I correct this? Sorry for the rookie questions.
@gregguise21282 жыл бұрын
Hi Jimmy. I really enjoy your arduino videos (which I’ve purchased and have started trialling) - thanks for the great work. I question or suggestion for future videos. I have a load of RC plane parts in my garage from when my son was younger - esc, receivers, transmitters etc. This technology seems a lot simpler than dcc to use in rail modelling (for a start, no wiring), with all the same functionality. But there is so little uptake of RC In HO,OO, N gauge. I found a company called DelTang who made a start but seem to be out of business. Is there any chance RC could be an area for future videos?
@manshedrailroad2 жыл бұрын
Heck yeah, I love it!!!
@barryolson84282 жыл бұрын
Great video. Where r the schmatics and arduino code?
@DIYDigitalRailroad2 жыл бұрын
The code is linked in the description as well as the schematic. They are all available on github.
@RRWMFan2 жыл бұрын
I also do not see the link for the schematic and codes.
@garrettswoodworx18732 жыл бұрын
@@DIYDigitalRailroad Jimmy I just checked the description and I'm not seeing the github link for the sketches & schematics. Could you please check & confirm they got uploaded? Thanks!
@davelandry6462 жыл бұрын
I'm not seeing the code or any of the links mentioned in the video either. There's a lot of links, but none specific to this video. Like the video a lot, by the way.
@DIYDigitalRailroad2 жыл бұрын
@@davelandry646 Try it now, it should be fixed.
@qwincyq64122 жыл бұрын
Not so simple for those of us who don’t know an arduino from an aardvark. Is there an introduction to how to do all this? It looks cool but do you need a PC specifically to program one of these projects?
@garrettswoodworx18732 жыл бұрын
Quincy: If you would like to get a better overall understanding of all things Arduino may I suggest checking out Paul McWhorter's KZbin channel and looking for the playlist titled "New Arduino Tutorials". Paul's series has nothing specific to do with model railroading but deals directly with understanding and programming the Arduino and is very concise and aimed at pure beginners, like I was when I found his channel. I found it incredibly helpful and it helped me get the maximum benefit from Jimmy's model railroad specific videos.
@qwincyq64122 жыл бұрын
@@garrettswoodworx1873 thanks for the tip
@garrettswoodworx18732 жыл бұрын
@@qwincyq6412 You're welcome! I think it is a great series, it helped me a bunch.
@Steelerfan8202 жыл бұрын
Bread boards are just for testing right? All those wires etc. Id hate to have deal with that in a small space.
@DIYDigitalRailroad2 жыл бұрын
Yes breadboards are for testing. I will sometimes design a PCB for my permanent wiring.
@markr5313 Жыл бұрын
Hey Jimmy, I have watched this video countless times. I do have a very serious question. In the arduino, can you program it to power down a section of track right at the signal block so that if you are running multiple trains and don't have to scramble to your dcc to power down the locomotive entering that red block
@DIYDigitalRailroad Жыл бұрын
Yes you can isolate that section and use a relay to power it down.
@4everdc3022 жыл бұрын
I do like the insight ya bring to this aspect of the hobby. Who knows the dinosaur might evolve on a future shelf gig🚂🇨🇦🇺🇲
@zoeyzhang98662 жыл бұрын
Informative tutorial!
@yngsjo2 жыл бұрын
One thing. Take a look at the raspberry pi pico (rp2040) It's different but like arduino. Nano RP2040 for example.
@DJ_Andreas2 жыл бұрын
Thanks for the good explanation. I am not seeing the links you mentioned in the description.
@medwaymodelrailway71292 жыл бұрын
Jimmy enjoyed your latest video thanks for sharing DD.
@loispadgett63062 жыл бұрын
I get lost in the writing of programs. I would like to find some one in my local club who can teach me. I just need to join and go. Hahaha 😂 This time I think I learned a little bit from this. GOD BLESS 🚂💖🚂💖🚂💖
@bruceyoung13432 жыл бұрын
Thank you 🙏
@VictorianMaid992 жыл бұрын
How about that !
@danny117hd2 жыл бұрын
Nice video but again I don't like the code. Don't take that personally I don't like any arduino code. Always the same beginner mistakes. 1. You should never have to say think of this as that while explaining code you should make your code read ON | OFF by making constants for ON | OFF. 2. NOTICE HOW HIGH AND LOW ARE ALL CAPS THOSE ARE CORRECTLY DEFINED CONSTANTS ALL CAPS. Timedelay should be all caps because it is a constant. Constants are all caps.
@darrellrisley2 жыл бұрын
I support the code. Don't lose sight of the fact that this code is aimed at beginners. It is simple and easy to understand without the constraints placed on professional programmers. Having taught computer programming for 18 years, understanding the code is more important than industry imposed rules.
@danny117hd2 жыл бұрын
It's a good video. Would've been easier to understand with [ON|OFF]