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!

Using Arduino in model railroading

2408 views
19 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Using Arduino in model railroading
Posted by hon30critter on Saturday, August 31, 2024 11:26 PM

It wasn't too long ago that LEDs were one of the major subjects of discussion in the DCC and Electronics forum. These days there is barely a mention.

I suspect that the modeling community has learned how to work with LEDs and further detailed discussion and education is largely no longer required. My question is "why hasn't the modeling community adopted Arduino technology in the same way"?

Probably the major factor is that the Arduino circuitry and programming appears at first glance to be far more complicated than wiring up an LED. Also, I'm pretty sure that a lot of eyes glazed over once people realized that some basic programming was involved (I know mine did).

Is anyone interested in starting a thread that covers Arduino basics, and perhaps supplying a simple circuit,  for example, one that turns lights on and off in various rooms at different times in a simple house? I for one would be interested

Cheers!!

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 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Sunday, September 1, 2024 6:14 AM

hon30critter
Is anyone interested in starting a thread that covers Arduino basics, and perhaps supplying a simple circuit,  for example, one that turns lights on and off in various rooms at different times in a simple house?

A modeler's introduction to the Arduino by Geoff Bunza from 2016

hon30critter
I suspect that the modeling community has learned how to work with LEDs and further detailed discussion and education is largely no longer required. My question is "why hasn't the modeling community adopted Arduino technology in the same way"?

Besides driving LEDs, many modelers are using Arduinos to drive servos to control turnouts.  Joe Fugate just wrote a 4 part article on Electrical Impulses: Using servos to control turnouts.     I think Joe tried to present it simply for the typical modeler.

my understanding is that the vast majority of model RRs are just that modelers and not technically savy.   Those who do attempt to use an Arduino have to deal both with electronics and software and suffer from common novice issues.

signalling is another common application.    Randy Rinker posted code for implementing a C/MRI node compatible with JMRI.   But ESP-32 boards support WiFi and can be networked wirelessly.

hon30critter
Is anyone interested in starting a thread that covers Arduino basics, and perhaps supplying a simple circuit,  for example, one that turns lights on and off in various rooms at different times in a simple house?

things like this are common on the Arduino Programming Questions Forum

what did you have in mind?

greg - Philadelphia & Reading / Reading

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Sunday, September 1, 2024 6:44 AM

LED/resistor pairs can be wired between 5V and a pin.

The Arduino has 13 digital pins and 6 analog pins that can also be used to drive LEDs.  Pins 0 and 1 can't be used because they are the RX and TX pins used to download code and for prints

here's code to randomly turn LEDs on/off every second.   the delay is set small for testing and can easily be changed.

sorry, but the array index entryies, things inside brackets, are interpreted as

No
// randomly turn on/off LEDs

// define an array of LED pins (pins 0 and 1 used for RX and TX)
const byte PinLeds [] = { 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 };
const int  Nleds      = sizeof(PinLeds);    // determine # of pins in array

void
loop (void)
{
    // randomly (< 10%) toggle an LED on/off
    for (int n = 0; n < Nleds; n++)  {
        int r = random(10);
        int p = digitalRead (PinLedsNo); 
        if (r < 1)
            digitalWrite (PinLedsNo, ! p);

        // format a parameter string
        char s [90];
        sprintf (s, " %3d  %3d  %d", PinLedsNo, r, p);
        Serial.println (s);
    }
    Serial.println ();

    delay (1000);       // wait 1 sec, 1000 milliseconds
}

void
setup (void)
{
    Serial.begin (9600);        // initialize serial interface bit-rate

    // initialize each pin as an OUTPUT and randomly turn on
    for (int n = 0; n < Nleds; n++)  {
        pinMode (PinLeds No, OUTPUT);
        digitalWrite (PinLeds No, random(10) < 5);
    }
}

greg - Philadelphia & Reading / Reading

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Sunday, September 1, 2024 11:38 AM

Hi Greg,

Thanks for the link to the Arduino website. I will have to do some reading in order to sort through the table of contents.

I guess that there is no 'two minute' shortcut. Learning Arduino programming will require a bit of a commitment. 

Cheers!!

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 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Sunday, September 1, 2024 12:31 PM

here's a simple program that blinks the builtin LED on/off.   All Arduino programs require a setup() function that is executed once and a loop() function that is executed repeatedly.

i don't know what you know so asking questions would save time

const byte PinLed =  13;

void
loop (void)
{
    digitalWrite (PinLed, ! digitalRead (PinLed)); 
    delay (1000);       // wait 1 sec, 1000 milliseconds
}

void
setup (void)
{
    pinMode (PinLed, OUTPUT);

greg - Philadelphia & Reading / Reading

  • Member since
    February 2008
  • 8,853 posts
Posted by maxman on Sunday, September 1, 2024 5:19 PM

Greg:

What you just posted is exactly what would make my head spin.

 

What I would be looking for is something that said:

here is the ardino.

here is the led.

connect leads of led to A and B

connect power (x volts) to C and D

to adjust flash rate turn Y.

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Sunday, September 1, 2024 7:00 PM

maxman
What I would be looking for is something that said:

you want a prep-programmed box with a knob on it.   Is that what Dave asked for?

greg - Philadelphia & Reading / Reading

  • Member since
    September 2003
  • 21,669 posts
Posted by Overmod on Sunday, September 1, 2024 7:20 PM

In my opinion, a lot of the 'action' with Arduinos in model railroading is going to involve shields and loadable code for the obvious things -- like adjustable lighting brightness control that humans familiar with dimmer knobs can actually use.

 

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Monday, September 2, 2024 5:44 AM

Overmod
In my opinion, a lot of the 'action' with Arduinos in model railroading is going to involve shields and loadable code for the obvious things -- like adjustable lighting brightness control that humans familiar with dimmer knobs can actually use.

that's more or less what i did for both of Daves queries above, I provided code to do what he asked.   Joe Fugates article provide a basic tutorial for programming.

And what shields are needed for driving LEDs?  the LED/resistor can be wired directly to the connectors on the Arduino.

it's up to the modeler to install the Arduino IDE, Integrated Development Environment, to compile and program the Arduino using a USB cable.

i recommend the mluti-function shield with the 7-segment display for experimenting with

glad to answer questions.  i'm awful at guessing what they might be

why is a knob is needed for something controlling brightness, that's what the resistors are for.

 

greg - Philadelphia & Reading / Reading

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Monday, September 2, 2024 11:18 AM

My initial goal using Arduino was to animate the lighting in residential structures and commercial structures so that the lights go on and off apparently in a random sequence. I plan on doing a fair bit of night running.

I say 'apparently' because I want the majority of the building lighting to come on over a relatively short period at 'dusk', and then slowly go off in a random pattern later at night.

Obviously that will be a much more complicated scenario than a simple flashing circuit, but I will start with the simpler circuit first.

Don't expect anything soon. First I have to finish the layout room, and next would be track and DCC, and then I have to run the snow plow train.

Cheers!!

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 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Monday, September 2, 2024 1:08 PM

hon30critter
Don't expect anything soon.

unlike when i got started programming embedded applications using an HP64000 Workstation you can do a lot from the comfort of your couch using the Multi-function shield which has 3 buttons, 4 LEDs, connectors that are servo compatible, a pot connected to an analog input, and the 7-segment displays.

greg - Philadelphia & Reading / Reading

  • Member since
    February 2008
  • 8,853 posts
Posted by maxman on Monday, September 2, 2024 9:32 PM

Hey HOCritter, was discussing this with a friend tonight and his comment was that using an arduino to control LEDs was akin to using a steam roller to kill an ant.

His suggestion was why not use something like thr Woodland Scenics Light Hub that can be had for about $17 list:

https://www.ebay.com/itm/384158920607?chn=ps&norover=1&mkevt=1&mkrid=711-213727-13078-0&mkcid=2&itemid=384158920607&targetid=4580909053911840&device=c&mktype=&googleloc=&poi=&campaignid=603247654&mkgroupid=1236951625700523&rlsatarget=pla-4580909053911840&abcId=9316139&merchantid=51291&msclkid=cf0f0bdc9cb91667794f6d0afa3bb735

His idea was to cut one output lead to each LED and run it to a small switch on the facia.  You can use the controls on the Light Hub to vary the intensity to each group of LEDs, and use the facia switches to turn each group of LEDs on/off.

He also suggested the Woodland Scenics Sequencing Light Hub:

https://www.ebay.com/itm/285999094292?chn=ps&_trkparms=ispr%3D1&amdata=enc%3A11iZfWnbpQY2sQqgJ-adAgg4&norover=1&mkevt=1&mkrid=711-213727-13078-0&mkcid=2&itemid=285999094292&targetid=4580909052765417&device=c&mktype=&googleloc=&poi=&campaignid=603247545&mkgroupid=1236951576251627&rlsatarget=pla-4580909052765417&abcId=9316119&merchantid=51291&msclkid=dc3282168ad3133b40b8e4c0ec510a8f

This device adds a sequencing effect to the LEDs, and can be varied.  And with the facia switches the different LED groups can also be manually turned on/off.

Sounds a lot less expensive than the arduino option, and no programming needs to be learned.  Sounds like something even I could do.

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Tuesday, September 3, 2024 2:01 AM

Hi maxman,

I looked into the Woodland Scenics lighting system when it first came out. I wanted to do a fairly large urban/commercial scene and the WS system would add up pretty quickly. I felt I could scratchbuild the same thing for less money. My system will involve 200+ LEDs. A smaller scene might be more cost effective with the WS products.

Cheers!!

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 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Tuesday, September 3, 2024 12:03 PM

hon30critter
Is anyone interested in starting a thread that covers Arduino basics, and perhaps supplying a simple circuit, 

of course one impedement is needing an Arduino and sufficient hardware to do something with it.

an option that requires neither is the web based wokwi.com simulator that allows you to graphically add and connect hardware, write and test the code using the simulated hardware.

doesn't require any $$ investment and no fear of damaging hardware connected incorrectly.   And there's the Arduino Programming Questions forum to get help.

greg - Philadelphia & Reading / Reading

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Tuesday, September 3, 2024 12:38 PM

Thanks Greg!

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
    November 2005
  • From: St. Paul
  • 823 posts
Posted by garya on Tuesday, September 3, 2024 4:18 PM

hon30critter
My initial goal using Arduino was to animate the lighting in residential structures and commercial structures so that the lights go on and off apparently in a random sequence. I plan on doing a fair bit of night running.

 

I believe the article by Geoff Bunza referred to earlier had a program to do exactly this.  p. 23, Random Building Lighting

Gary

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Tuesday, September 3, 2024 5:46 PM

garya
Random Building Lighting

after seeing some of the other comments, i think what's really wanted is something that randomly turns lights on when the room light is dimmed and then randomly turns them all off when the room lights come back on.

greg - Philadelphia & Reading / Reading

  • Member since
    July 2006
  • From: Bradford, Ontario
  • 15,797 posts
Posted by hon30critter on Tuesday, September 3, 2024 11:14 PM

Thanks Gary!

Cheers!!

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 Tuesday, September 3, 2024 11:44 PM

Hi Greg,

I really like the idea of having the structure lights come on when the light level in the room goes down.

This could get rather complex, especially in the residential buildings. Various lights could go on and off based on their locations. I believe I saw an article on this some years ago in Model Railroader.

The same idea could be applied to hotels and apartments. I'm going to have operating street lights. It would be ideal to have them controlled automatically too. Same with billboards and business signage, railroad repair shops and much more.

Doing all that wiring would be daunting but the effects would be excellent.

Cheers!!

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 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Wednesday, September 4, 2024 9:33 AM

hon30critter
I really like the idea of having the structure lights come on when the light level in the room goes down.

This could get rather complex,

when i started work in 1985, a colleague said how easy it is to implement a traffic light using a microprocessor.    He neglected to consider what else could be done once a processor was used, such at optimizing traffic flow by monitoring traffic and adjusting the timing of the lights

it's trivial for an Arduino to randomly turn LEDs on/off.   Adding an ambient light detector to recognize night/day isn't difficult.    Outputs can easily be identified as residential or business to determine whether lights come on during the day or night  or only in evening/morning.

greg - Philadelphia & Reading / Reading

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!