3 Simple Model Railroad Arduino Projects for Beginners

preview_player
Показать описание
Parts

TRAIN SETS
3D PRINTERS
CAMERA
MICROPHONE
LIGHTS
MOTION CONTROL

Consider donating the PCOS Challenge to help women everywhere with PCOS

“The godly may trip seven times, but they will get up again.
But one disaster is enough to overthrow the wicked.
Don’t rejoice when your enemies fall;
don’t be happy when they stumble.
For the Lord will be displeased with you
and will turn his anger away from them.
Don’t fret because of evildoers;
don’t envy the wicked.”

Proverbs 24: 16-19 NLT
Рекомендации по теме
Комментарии
Автор

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.h>

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!

rwissbaum
Автор

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!

rwissbaum
Автор

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.

darrellrisley
Автор

Jimmy: Very good presentation. My eyes didn’t roll back.

kenshores
Автор

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.

donaldkormos
Автор

Very cool 😎 vid Jimmy. Love how you make the Arduino Uno so intricately accessible. Thanks 🙏 for sharing!

vincenthuying
Автор

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

TheSwitchList
Автор

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.

melkitson
Автор

I'm definitely saving this one to come back to!

AlanReynolds
Автор

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.

moisesbursztein
Автор

Thanks for sharing!! Love Arduino projects!!

johncloar
Автор

On the last example you should include a time off=rand() as well so they’re not on immediately after one goes off

thesheq
Автор

I do like the insight ya bring to this aspect of the hobby. Who knows the dinosaur might evolve on a future shelf gig🚂🇨🇦🇺🇲

everdc
Автор

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

chrispainter
Автор

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 🚂💖🚂💖🚂💖

loispadgett
Автор

You can use a short connecters, we can see easy cuircuit

tubutubutubu
Автор

Hi Jimmy, what do we need to use to power the arduino and can it be done with batteries for these projects?

BaileyWeathers-ml
Автор

Nice tutorial! I can almost understand! How do you get the lights from the bread board to a police car?

Cbtrainnut
Автор

Jimmy enjoyed your latest video thanks for sharing DD.

medwaymodelrailway
Автор

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?

gregguise
visit shbcf.ru