Model Railroad LEDs and Arduino

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
modeller
 
Posts: 118
Joined: Sat Jan 19, 2013 11:12 am

Re: Model Railroad LEDs and Arduino

Post by modeller »

adafruit wrote: feel free to post stuff up in general though!

thanks!
adafruit suppor,t phil
OK, here's a shot of the small voltmeter and ammeter I got the other day from your store. I tested them using a 100 ohm 10W power resistor. As you can see in the pic, the voltmeter is spot-on, but the ammeter is not quite there. It should be reading 270 mA. It doesn't start to register a current at all until it has 10V (below that the display is on bright but shows 0.00) which would cause a current of 100 mA, but it displays .01 A (should be 0.1 A). Any current less than an actual 100 mA is not registered on the display. Your spec says it has a range of 0 - 9.99A so it should display a current of 0.01 A as it has that digit available. Is something a little amiss on the specs?

Edit: Added specs from product page -

Power specifications:

4.5V to 30V DC power
0-9.99 Amp DC current sensing
Attachments
IMG_0141.JPG
IMG_0141.JPG (92.16 KiB) Viewed 5716 times

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Model Railroad LEDs and Arduino

Post by adafruit_support_bill »

It looks like you have the ammeter wired in parallel with the load. In order to measure the load current, you would have to wire it in series with the load. Since the supply ground and black sensing wire are common, you will want to insert this into the low-side of the load circuit.

User avatar
modeller
 
Posts: 118
Joined: Sat Jan 19, 2013 11:12 am

Re: Model Railroad LEDs and Arduino

Post by modeller »

adafruit_support wrote:It looks like you have the ammeter wired in parallel with the load. In order to measure the load current, you would have to wire it in series with the load. Since the supply ground and black sensing wire are common, you will want to insert this into the low-side of the load circuit.
First, you might want to split this off into a new topic, I didn't think of it at first so sorry about that.

Second - no, it's wired in properly - don't go by the way the wires look like they are laying on the bench. I do have an EET degree and worked in a lab for about 24 years, so I'm sorta good with electronics myself. :D I just don't have experience with an Arduino (yet).

No, it's wired in properly. It's simply a lab power supply going to a 100 ohm, 10W resistor, then into the ammeter (low side) then to ground. That's about as simple as it gets. I just got up but I am going to go to my junque box and get a load that will draw more current, I think I have a halogen lamp. But the fact is it isn't accurate at low currents. When I first hooked it up I put it in a LED circuit that draws a known 20 mA and it showed 0.00. It gets "better" as the current goes up but as of yet it always displays a current that is lower than what is really being drawn.

The second thing is that the digits would only allow it to display a lowest current of 0.01A. The specs say it ranges from 0 to 9.99 A. It really should say it ranges from 0.01 - 9.99 A. :?

I'll be back ...

User avatar
modeller
 
Posts: 118
Joined: Sat Jan 19, 2013 11:12 am

Re: Model Railroad LEDs and Arduino

Post by modeller »

I started a new thread about this, since this topic has veered way off ...

http://forums.adafruit.com/viewtopic.php?f=19&t=36683

User avatar
mrex
 
Posts: 15
Joined: Mon Jan 21, 2013 1:48 pm

Re: Model Railroad LEDs and Arduino

Post by mrex »

Hey Modeller,

I've added you as a friend on adafruit's forums, I was hoping to PM you so as not to clog up the main support threads. You can also email me at [email protected].

Everyone, Arduino holds promise as a way to build custom sensors that fit exact issues in a model railroad. For example, when a train crosses a point, make a signal turn red, and a crossing gate close, *and* activate a sound board, *and* make the tail lights on a car at the crossing gate turn on.

Right now, this can be done by combining off-the-shelf stuff for model railroad layouts, but its not easy, and its not intuitive. And you can't easily write code for it without getting into PIC programming and building your own circuits.

Modeller, I see you're using Digitrax stuff on your layout. I think Loconet is the way to go, and I've been thinking about building a Loconet Shield for Arduino. Imagine you can address your Arduino from your CAB. Or imagine that it can send occupancy info like a BDL-168, but with custom effects. Note that Adafruit already offers Hall sensors...

I don't want to overstep my bounds on this thread, I appreciate that this forum is for support of Adafruit products. And I certainly don't want to descend into some political discussion of why BLAH BLAN is BLAH! (Godwin's Law!).

I hope I've gotten any other model railroaders here thinking, and Modeller, contact me if you want to carry on this discussion outside of the forums.

Adafruit, I promise to post any positive results back here (in General) as open source. We all need good circuits...

Signed,
Open Source Hardware Rulez

User avatar
modeller
 
Posts: 118
Joined: Sat Jan 19, 2013 11:12 am

Re: Model Railroad LEDs and Arduino

Post by modeller »

mrex wrote:Hey Modeller,

I've added you as a friend on adafruit's forums, I was hoping to PM you so as not to clog up the main support threads. You can also email me at [email protected].
OK thanks. I saw people can be added as foes too - LOL, glad you chose the former.

I can't PM you because apparently they have the function disabled :? . If you want to contract me I'm a member of the Nscale.net forum -

http://www.nscale.net/forums/forum.php

My membername is nskale (no I didn't mis-spell it).
Everyone, Arduino holds promise as a way to build custom sensors that fit exact issues in a model railroad. For example, when a train crosses a point, make a signal turn red, and a crossing gate close, *and* activate a sound board, *and* make the tail lights on a car at the crossing gate turn on.

Right now, this can be done by combining off-the-shelf stuff for model railroad layouts, but its not easy, and its not intuitive. And you can't easily write code for it without getting into PIC programming and building your own circuits.

Modeller, I see you're using Digitrax stuff on your layout. I think Loconet is the way to go, and I've been thinking about building a Loconet Shield for Arduino. Imagine you can address your Arduino from your CAB. Or imagine that it can send occupancy info like a BDL-168, but with custom effects. Note that Adafruit already offers Hall sensors...

I don't want to overstep my bounds on this thread, I appreciate that this forum is for support of Adafruit products. And I certainly don't want to descend into some political discussion of why BLAH BLAN is BLAH! (Godwin's Law!).
I don't see why this discussion would be out of bounds, as the Arduino itself is a product they sell. My experimenter's kit is arriving today so I should be getting up to speed pretty quickly. Any discussion of the Arduino for model railroads could possibly spur interest in a completely different area by casual readers, you can't predict what ideas people will garner from any discussion.
I hope I've gotten any other model railroaders here thinking, and Modeller, contact me if you want to carry on this discussion outside of the forums.

Adafruit, I promise to post any positive results back here (in General) as open source. We all need good circuits...

Signed,
Open Source Hardware Rulez
I'll be talking with you here or there ... 8)

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Model Railroad LEDs and Arduino

Post by adafruit_support_bill »

I don't see why this discussion would be out of bounds
Arduino applications of all kinds are welcome here. :D

User avatar
mrex
 
Posts: 15
Joined: Mon Jan 21, 2013 1:48 pm

Re: Model Railroad LEDs and Arduino

Post by mrex »

Arduino applications of all kinds are welcome here
Kewl. Thanks for that Adafruit_Support.

Nskale/Modeller, I signed up on your forums, but I haven't gotten back the confirm email. I'll chase it down tomorrow.

Meanwhile, see here for open source hardware for Loconet interfaces:

http://wiki.rocrail.net/doku.php?id=english#hardware

I can't say enough about Rocrail. Run by Rob Versluis, a Dutchman, he's got seriously good open source hardware and software to run model railroads. He's widely accepted in Europe, but strangely enough is kind of ignored in the U.S.

It works, its kewl and you can control your trainset from your iphone, your droid, or from anywhere in the world via the internet. The software is excellent, and it basically works with all the hardware from all the major train manufacturers. I've had Rob run my trains here in my NYC apartment live via the internet from Germany.

I found him because I'm (*GASP*) three-rail HO!

But again, when it comes to making it for yourself, instead of buying from Marklin or Walthers or Digitrax, its all kits and soldering, and you can't easily create your own hardware. You either have to start making your own boards, or buy kits from a small guy who can't make enough (but wants to!).

These guys are trying so hard, and succeeding, sort of *outside* the maker revolution that is happening here in the US. Again, check out their projects, its just what Adafruit is doing, all their stuff is open source too. In fact, they are probably part of the Maker Revolution, they just don't know it (Go Brooklyn Aerodrome! I WANNA FLY MY TOWEL!).

I think a Loconet shield for Arduino would change things. Now I could easily test and prove circuits before I put them "on the line". You could easily breadboard the circuit, test it on the layout, confirm it works, and then just use it or put it into production by making boards.

Or maybe I'm just working too hard, and should go run some trains. ;)

-- Mrex

P.S. I'm gonna talk to Rob in the next day or so, I swear some members have begun experimenting with Arduino on Rocrail layouts. I'll post any hard links I find back here.

P.P.S. This is an old web, but a popular one -- this is analog 3 rail on the floors of my NYC apartment over the years: http://www.nakedmarklin.com/

User avatar
dmpyron
 
Posts: 75
Joined: Mon Dec 10, 2012 11:14 am

Re: Model Railroad LEDs and Arduino

Post by dmpyron »

adafruit_support wrote:That is basically the same concept as TWC's as used in 1:1 rail operations. If you program the route code on the tag at the yard, it can be used to request the switch alignment as it enters the interlocking.
I'm reading this and thinking "wow. Hump yard!!!" But N might not have the weight to do it. HO maybe but O would really rock.

I've moved from N to garden (live steam). Working on RC for the loco(s). There are a couple of really neat looking products here that I'd giving some serious thought to using.

And to think I got here from an article in Garden BANNED last year. :)

User avatar
modeller
 
Posts: 118
Joined: Sat Jan 19, 2013 11:12 am

Re: Model Railroad LEDs and Arduino

Post by modeller »

mrex wrote:
Nskale/Modeller, I signed up on your forums, but I haven't gotten back the confirm email. I'll chase it down tomorrow.
Awe-sum. Thanks for the other info too.

I have implemented some circuits on my layout that I could have used the Arduino for, but I wasn't clued-in at the time.

I have a lot of signals. I bought some IR signal boards from a Chinese supplier to sense when a train goes over a certain point and then change the signal aspect <-- could have done that with the Arduino.

I also hacked up a traffic light kit with a 555 timer to control some other signal aspects (just for some changing scenery not related to any active train) <-- could have done that with the Arduino too.

I have had the Adafruit kit for several days and I'm getting up to speed pretty quick. I used to know C very well but I haven't used it in years but it's all coming back to me now. I used LabView in the aerospace industry and I see they have the ability now to interface to it. I love LabView but I'm not going to pony up for it now. :shock:

http://sine.ni.com/nips/cds/view/p/lang/en/nid/209835

I had an idea the other day that I might buy the wave shield and couple it to some track sensors to make realistic noises when trains pass certain points. Since I don't have the DCC decoders with sound that would add some interest to the layout.

Since the layout is never meant to be completed (if it was it would be a horrible event - then what would I do?) I have plenty of time to dream up crazy ideas.

We'll keep talking in this thread if the mods don't mind (the topic is kinda off now). :D

Hmmm ... can we get the topic changed to "Model Railroading and the Arduino?

Party on ...

User avatar
modeller
 
Posts: 118
Joined: Sat Jan 19, 2013 11:12 am

Re: Model Railroad LEDs and Arduino

Post by modeller »

mrex wrote:[
Nskale/Modeller, I signed up on your forums, but I haven't gotten back the confirm email.
Hey are you still on this forum?

I've been hard at work debugging a program to count cars in a passing train using the Arduino and an IR LED / photo transistor. Turns out it ws a lot harder than I first thought, not because of the Arduino but because of the physical aspects of the problem.

If you're interested I'll post what I've got. I don't think anyone else here would have any interest in it at all though.

User avatar
mrex
 
Posts: 15
Joined: Mon Jan 21, 2013 1:48 pm

Re: Model Railroad LEDs and Arduino

Post by mrex »

Hi Modeller!

Nskale, I got swamped with work, I've been meaning to reply for weeks but I haven't had a chance. At the same time, I've worked up an IR Emitter/Detector sketch for Arduino with a corresponding program in Processing to "scope" the output using Radio Shack's cheap IR E/D pair.

We are thinking along the same lines. I will try to find time this weekend to post the code and pix of the results. I think one Arduino could easily drive 4 detectors, and possibly 8. This can be used for occupancy detection and car counting at a relatively cheap price per detector.

I also learned that there are problems getting real time data in milliseconds on an on-going basis. There is an excellent tutorial at adafruit on using an IR sensor here:

http://learn.adafruit.com/ir-sensor

That code takes a snapshot of signals very fast, then displays the output.

My real-time code isn't fast enough to produce results in the kHZ range, I have to review my work to see what my actual sample rate was (I think it was no lower than 500ms). I think it would work to detect an entire train, or even do car counting if the train was moving slowly enough.

Miss you, will post again...
Mrex In Manhattan

User avatar
modeller
 
Posts: 118
Joined: Sat Jan 19, 2013 11:12 am

Re: Model Railroad LEDs and Arduino

Post by modeller »

I'm using an IR LED and phototransistor I got from led-switch.com.

I got the system to work for detecting an entire train using the setup shown in the first pic. The secret was to make the beam (with this IR LED it hardly deserves being called a beam) at an angle to the train. That way it never sees a gap until the train has passed.

I ran into an interesting problem when it came to counting cars. At first I debugged the program using a business card and verified the logic was working, but when it came to the real train, it proved a lot harder to get it to work.

The problem is, unlike the detector for the whole train, there is no good way to position the detectors at the sides if you want to sense both cars and gaps with no chance of leakage. At first I placed them at the height of a flatcar and facing straight across the tracks. This failed miserably.

The reason is that there are too many differences between cars and even engines. The first problem was the engine. At the height of the flatcar, the beam can penetrate to the other side if an engine crosses because there are gaps at the fuel tank there. Even the handrails and coupler will cause false gap sensing, so raising and lowering the detectors to fix that, would then fail on the wide variety of other cars available.

So it seems I'd have to find an angle shooting up that would work that lets more of the car help block the signal. Going from the bottom of the track to a detector looking straight down might work too. If it comes to it I have a bridge I can test it on. For me reflection (having both devices side-by-side under the tracks) is out because it's too dependent on a consistent reflectivity.

The other issue is the short flickers that are caused by all these car differences. Sometimes I'll get 3 or 4 triggers because of the various little parts on each type of car. But I think I know a way to "debounce" this problem.

I finally got it all to work reliably. I have attached a pic of the physical setup. The code is posted below, as well as a copy of the debugging messages.

The key was to set up the detector at an angle, and to include a "toggle" routine. The toggle routine turns off the emmiter as soon as the first detection occurs. I leave the IR LED off for 35 mS, which is a little smaller time than an entire car takes to pass the detector at a very fast speed. Ideally I think the emitter should be below the track and the detector above the track (and train).

But. many of these IR LEDs are very poor directional devices. They are basically a flashlight sort of emmission. I included a pic of one shining onto some optical detection paper. You can see how large the beam is getting even at a short distance. However, I have on order some devices that will solve this problem - IR lasers. I got two of them for $9.99 each off of Ebay -

http://www.ebay.com/itm/110985868796?ss ... 1497.l2649

Using these I'll be able to shine it a long way down the track, or up close perhaps even count wheels. I'll have to adjust the output power up close so I don't burn out the phototransistor. I might have been able to use a red laser, but I don't want it to look like the Terminator is hunting down my trains.

Here's some results from the car counting experiments, but the code did work reliably as is, even thout it needs cleaned up a bit.

Debugging messages

These values were recorded for a "slow" train of 9 units

cars: 1 cartime: 2.00 gap time: 0.11
cars: 2 cartime: 1.59 gap time: 0.10
cars: 3 cartime: 1.53 gap time: 0.07
cars: 4 cartime: 1.66 gap time: 0.09
cars: 5 cartime: 1.80 gap time: 0.10
cars: 6 cartime: 1.72 gap time: 0.08
cars: 7 cartime: 1.70 gap time: 0.05
cars: 8 cartime: 1.61 gap time: 0.09
cars: 9 cartime: 2.13 EOT!!!
gap time: 3.00

These values are for a "fast" train of 9 units

cars: 1 cartime: 0.65 gap time: 0.02
cars: 2 cartime: 0.48 gap time: 0.00
cars: 3 cartime: 0.51 gap time: 0.01
cars: 4 cartime: 0.53 gap time: 0.01
cars: 5 cartime: 0.55 gap time: 0.01
cars: 6 cartime: 0.50 gap time: 0.01
cars: 7 cartime: 0.45 gap time: 0.01
cars: 8 cartime: 0.46 gap time: 0.01
cars: 9 cartime: 0.61 EOT!!!
gap time: 3.00

Code: Select all

/* This is a simple generic IR car/engine counting application shell.
 //
 // It uses a commonly available IR LED emmitter and IR sensing phototransistor.
 // Available many places such as here http://www.led-switch.com/I.%20R.%20LED.htm
 // Place the sensors at the angle you find that works on either side of the tracks.
 // 
 // To use this to trigger another device add the device hardware and code to the Arduino.
 // 
 */

int irtx = 11; // digital pin 11 driving the IR LED
int irrx = A0; // analog pin A0 connected to the phototransistor
int active_car = 2; //digital pin 2, red LED
int cars = 0;
unsigned long time_hack;
boolean EOT = LOW; // End of Train signal
float gap_time;
float car_time = 0.0;
const float gap_limit = 3.0; 

// gap_limit in seconds is the max limit for a unit gap. Set this to suit your needs. 
// If this limit is exceeded it signals the EOT

void setup() 
{                
  pinMode(irtx, OUTPUT);    
  pinMode(active_car, OUTPUT);   
  digitalWrite(irtx,HIGH); //turn on IR LED
  Serial.begin(9600);
}

void loop() 
{
  digitalWrite(active_car,LOW); 
  EOT = LOW;
  cars = 0;
  while((.0049 * analogRead(A0)) < 4.3)
  {
    //wait for 1st unit trigger
  }

  ir_toggle(); 
  while (EOT == LOW)
  {
    digitalWrite(active_car,HIGH); 
    time_hack = millis(); //get a time hack 
   
    while ((.0049 * analogRead(A0)) > 4.3)
    {
     //wait till the car passes
    }
    ir_toggle();
    car_time = float((millis() - time_hack)) / 1000.0; // compute car passing time
    cars++;
    Serial.print(" cars: ");
    Serial.print(cars);
    Serial.print(" cartime: ");
    Serial.print(car_time);
    digitalWrite(active_car,LOW); 
    time_hack = millis(); //get a time hack 
    
    while (((.0049 * analogRead(A0)) < 4.3) && (EOT == LOW)) //wait for the gap or the EOT
    { 
      gap_time = float((millis() - time_hack)) / 1000.0;
      if (gap_time >= gap_limit)
      {
        EOT = HIGH;
        Serial.println(" EOT!!!");
      }
    }
    ir_toggle();
    Serial.print(" gap time: ");
    Serial.println(gap_time);
  }
  delay(2000); //A little EOT saftey delay
}

void ir_toggle() 
{
   // this routine will shut off the IR emmission to prevent false triggers
   digitalWrite(irtx,LOW);
   delay(35); 
   //this value is slightly less than the minimum cartime recorded for a "fast" train
   //this will shut off the IR LED for 35 mS
   digitalWrite(irtx,HIGH);
}
Attachments
Train counting setup
Train counting setup
IMG_0178.JPG (81.19 KiB) Viewed 5470 times
Car counting setup
Car counting setup
ir-counter_angle.JPG (82.17 KiB) Viewed 5470 times
IR LED beam size
IR LED beam size
IMG_0181.JPG (58.33 KiB) Viewed 5470 times

User avatar
The_OG
 
Posts: 2
Joined: Mon May 26, 2014 11:33 am

Re: Model Railroad LEDs and Arduino

Post by The_OG »

Hello everyone! This is awesome stuff. Glad to see I'm not the only one trying this. I've just picked up some track and a loco, etc. after decades away and am starting to mix my hobbies.

So far I've built a simple DC controller which works nicely but now I'd like to create a DCC encoder to drive multiple locos as my layout grows. I'm using an Uno for the time being with with the motor shield v2.

I've got a couple of questions that hopefully someone here has done this before and will have the answer to...

Has the NmraDcc library been used successfully with the motor shield v2 to generate DCC packets? I've seen several implementations with other motor drivers but I ask because the NmraDcc library is looking for a physical pin and interrupt while the motor board is I2C and uses the run() method with no other input method that I can see. I suppose I could adapt the libraries but I'm not sure I2c would be fast enough to generate the DCC packets in a timely manner and it is more work than I was planning on.

Also, does anyone know how the shield and library handle shorts / thermal events?

TIA,
Alex

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Model Railroad LEDs and Arduino

Post by adafruit_support_bill »

I'm not familiar with the internals of the NmraDcc library. But if it is designed around a direct interface to an H-bridge chip, it will require some modification to work with the shield.

The bridge chips on the shield do have thermal overload protection. But as with any electronics, chronic overload conditions will shorten the life of the device.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”