Jump to content
 

Arduino Video Tutorials for Model Railways


oorail

Recommended Posts

I've been working on a number of projects related to the Arduino and NodeMCU Internet of Things platforms for my layout and I decided to put together tutorials to explain what I did step by step so that other folks might benefit from it.

 

The latest tutorial is available here -  https://www.youtube.com/watch?v=-ATOKGPQgkk and it covers using the Arduino to test / drive point motors. In the video I walk through the process of getting the Arduino to drive a set of Peco PL-11 point motors.

 

The project uses an Arduino Uno R3 (but you could use any Arduino platform) and a 16-channel relay board to drive the point motors. Each point motor requires two relays, as you cannot use one relay for both directions as that would leave power applied to the point motor and burn it out pretty quickly. On my layout, the vast majority of points are cross-overs and therefore paired up, so I can use two relays to drive both the paired point motors in each cross-over.

 

You can find the code for the project on GitHub - https://github.com/oorail/arduino-rail/tree/master/point-motors/relay

 

You can see the setup in this photo below...

 

post-23733-0-77215800-1454526082.png

 

The code is designed to test the point motor, so in my tutorial, I've got the PL-11 wired to RELAY1 and RELAY2 in the code, which are connected to pin 9 and 10 (so relay 9 and 10 on the 16-channel board). The relay board requires a 12V DC input, so the start of the video walks you through recycling an old PC/AT power supply (not an ATX one)  to provide that and a 5V channel.

 

Over the next couple of weeks, I'll be uploading related tutorials, including integrating the Arduino controlled point motor with signaling, and a tutorial on how to detect the state of the points. We could detect / check state using software, but this could easily get out of sync, so I've got some items on order from China that'll help detect the direction the points are set.

 

Hope you enjoy the tutorial, please feel free to post questions or comments below. I'm going to be knocking out tutorials on this stuff about once a week, so if there is something you would like to see please let me know!

Link to post
Share on other sites

Each point motor requires two relays, as you cannot use one relay for both directions as that would leave power applied to the point motor and burn it out pretty quickly.

 

Not if you incorporate the standard single charge/discharge capacitor circuit with each relay/point motor. That particular configuration has been posted here many times.

Then you could drive twice as many points and not have to worry about timing or burn out. All you then have to do is change relay state to change the point.

Link to post
Share on other sites

Not if you incorporate the standard single charge/discharge capacitor circuit with each relay/point motor. That particular configuration has been posted here many times.

Then you could drive twice as many points and not have to worry about timing or burn out. All you then have to do is change relay state to change the point.

 

Cool thanks... I found a couple of diagrams for building a CDU for an A/C supply, but I'm trying to keep the setup 100% DC if possible. Do you know where I might be able to track down a DC CDU diagram? I will dig around the forums and Google some more tonight...

Link to post
Share on other sites

You can find a version of it here:

http://www.rmweb.co.uk/community/index.php?/topic/44670-dpdt-to-work-seep-point-motor/&do=findComment&comment=488393

You might need to increase the power supply voltage to a bit more than 12V, but that depends on the type of solenoid point motor you are using.

I find that 15V DC is required for my Kato Unitrack demo points for reliability, and I also use 24V DC for things like Peco motors.

Link to post
Share on other sites

You can find a version of it here:

http://www.rmweb.co.uk/community/index.php?/topic/44670-dpdt-to-work-seep-point-motor/&do=findComment&comment=488393

You might need to increase the power supply voltage to a bit more than 12V, but that depends on the type of solenoid point motor you are using.

I find that 15V DC is required for my Kato Unitrack demo points for reliability, and I also use 24V DC for things like Peco motors.

 

Thanks that is exactly what I was looking for. Looks like I'm off to buy some capacitors today! I'm using the 12V DC fixed output (side connectors) on old Hammant and Morgan controllers (mainly Duettes), what is odd though is most of the ones I have are outputting about 14.5V - 16V DC rather than 12V DC. They are brand new, some hobby shop up in Canada was being liquidated and they were apparently in the very back of a store room. They are export models (115V), so not sure if maybe whatever conversion they did for that might cause the voltage to be slightly higher. I thought at first it might be my multimeter as its pretty cheap, but the analog one is giving the same reading and both give correct readings when testing batteries and other supplies...

 

The 16V DC seems to be good enough to switch the Peco PL-11, I'm using mostly Gaugemaster PM-1 / PM-2, but in a few places due to access restrictions, I'm using PL-11. The only thing I noticed about the PL-11 is they seem to be very picky about the point motor and points being completely flat, when I was testing it out on the workbench, they wouldn't always switch properly unless it was perfectly flat..

Link to post
Share on other sites

I'm using the 12V DC fixed output (side connectors) on old Hammant and Morgan controllers (mainly Duettes), what is odd though is most of the ones I have are outputting about 14.5V - 16V DC rather than 12V DC.

 

Not that surprising really, as these are unregulated outputs from a conventional transformer, straight after the internal bridge rectifier. You will probably have measured the output without a load being connected too.

Higher is usually better anyway (within reason), as the energy delivered into the motor increases with the square of the voltage.

Link to post
Share on other sites

You can find a version of it here:

http://www.rmweb.co.uk/community/index.php?/topic/44670-dpdt-to-work-seep-point-motor/&do=findComment&comment=488393

You might need to increase the power supply voltage to a bit more than 12V, but that depends on the type of solenoid point motor you are using.

I find that 15V DC is required for my Kato Unitrack demo points for reliability, and I also use 24V DC for things like Peco motors.

I'm using a 16v DC laptop power supply and use that capacitor circuit for all of my points on my current layout. It works equally as well with Arduino and I've just built a shuttle system using one that controls direction, speed and points.

 

Cheers,

 

Andy.

Link to post
Share on other sites

So this week's video I decided to try experimenting with FSR (Force Sensitive Resistors) to see if they could be used for train detection, and possibly even ID. You can buy FSR in various sizes, round, square etc. The FSR I chose to use cost about US$7.00, and is about half the size of a ATM card. The FSR is a type of pressure sensor, so the more pressure placed on the sensor, the higher the resistance value. That value can be read by the Arduino and you can then do something with that data.

 

In the example I did for the video (link below), I used the data to allow the program to identify what was placed on the track. I deliberately selected a Dapol 16T wagon, a Bachmann Class 03 shunter and a Heljan Class 27 diesel, as they had significantly different weights. The FSR is accurate enough to get a ballpark reading, but its not quite accurate enough to get an exact weight. So you can tell if something light, heavy or really heavy is placed on the track.

 

I'm thinking it maybe useful for triggering things or train detection in low light where photo-sensitive devices such as photo-resistors won't work as well.

 

The link to the code and the various components used in the video can be found in the YouTube video description, as always let me know what you think, any ideas on how this could be used are welcome too!

 

https://www.youtube.com/watch?v=YVFFuBpcf90

 

post-23733-0-37546000-1455140867_thumb.png

Link to post
Share on other sites

  • 11 months later...

... I'm trying to keep the setup 100% DC if possible...

 

If that's the case, why wouldn't you use a Darlington Transistor as the Switching Element?

 

I believe that all of these (Both PNP & NPN devices included) could be suitable:

  2 Amps  -  BD776, BD777, BD778, BD779 & BD780

  4 Amps  -  2N6036 & 2N6039

  4 Amps  -  BD677, BD678, BD679, BD680, BD681 & BD682

  4 Amps  -  MJE700, MJE702 & MJE703

  4 Amps  -  MJE800, MJE802 & MJE803

  5 Amps  -  TIP120, TIP121, TIP122, TIP125, TIP126 & TIP127

10 Amps  -  BDX33B, BDX33C, BDX34B & BDX34C

 

These Darlington devices can be driven directly from a MicroController Output with less current than any LED.  Just remember to put a Flywheel Diode across any Coil (Any 'Inductive' Load), so that the decaying magnetic field doesn't come back to bite the Darlington.

 

 

A wise man (TartanTrax on this forum) once said to me:  'You should implement as much as you can in Software, because it's far easier to change, compared with a hardware implementation.'

 

You can still get the benefit of drawing most of the current from a Capacitor.  It's just a Capacitor on the Power Supply that is also powering the 5 Volt rail to the Arduino (Using a Common Earth).  Obviously, that has an impact on the minimum time between the Arduino firing Coils, because the Capacitor needs time to recharge.

 

As you haven't made any suggestion that the Arduino is connected to the DCC Bus, the Arduino's Power Supply can be as big as it needs to be.  You can even have multiple Arduino's each with their own Power Supply Capacitor, and activate every second Point Motor from alternating Arduino Power Supplies.

 

 

I have found a couple of examples (One each for a PNP & NPN Device) of how you can wire this up.

 

This circuit uses an NPN Darlington, and is commonly known as an 'Open Collector' configuration...

post-30665-0-98404400-1484307028.jpg

One of the benefits of the 'Open Collector' configuration is that the Voltage to drive the Relay Coil can be anything you like, compared to the Signal that is telling the Darlington to turn On & Off.

 

 

This circuit uses a PNP Darlington...

post-30665-0-03460100-1484307413.jpg

Link to post
Share on other sites

Move the points or signals with a small relay servo and there is no need for either transistors or relays. And only a single wire is needed between the Arduino and each servo. An Uno can control 12 servos. A Mega can control 48.

 

...R

EDIT to correct a really stupid mistake - humble apologies for the confusion

Link to post
Share on other sites

Move the points or signals with a small relay and there is no need for either transistors or relays.

 

OK, I'm confused!  If I use "a small relay", "there is no need for ... relays".  How can there be no need for a relay, if you are using a small relay?

 

But, there is NO relay in the solution I was suggesting.  Yes, the pictures that I re-tasked from the Internet show a Relay Coil, but that Coil is the Point Motor coil.  The post was all about using "... a Darlington Transistor as the Switching Element ...".

 

___

At least @Suzie makes a useful comment, but it was just a repeat/reinforcement of what the post @Suzie was responding to said ("... the Voltage to drive the Relay Coil can be anything you like ...").

 

I apologise that I ASSUMEd ('When we ASSUME, it makes an ASS out of U and ME') a certain level of Knowledge.  I provided a general response to a specific problem, and assumed that any person planning to use it could work out what they needed to do.

 

The 'Open Collector' solution has a Positive that any Voltage can be used to drive the Coil, and a Negative that you have to run un-switched VCC to every Point Motor.  That means that there are ample possibilities for a short circuit that relies on whatever safety measures the Power Supply provides.

 

Using this circuit, you would (I ASSUME ... again) understand that you need to make certain that in a Short Circuit situation, the Power Supply would shut down, rather than continue to deliver a bucket-load of current into the failed element causing the short circuit.

 

The alternative solution has a Negative that VCC can be no larger than the voltage on the MCU's VCC Pin (Most often that is 5 Volts, but could be 3.3 Volts too), and a Positive that the wires to the Point Motor are switched VCC and 0 Volts.  Clearly, 5 Volts to a Point Motor is useless.  But if you are doing other things (e.g. Switching LEDs), then the circuit might be useful after all, despite what @Suzie says.

 

___

@Robin2 says "An Uno can control 12 servos. A Mega can control 48."

 

If anyone is interested, I can point them to a series of articles (And the Arduino sketches) that show Servos being controlled using every Output Pin on any Arduino.

 

The software was extended to allow you to do anything it was capable of with any Output Pin...

-  Control a Servo

-  Switch something On or Off

-  Flash a LED (Maybe for a Level Crossing)

 

@Robin2 might not realise it, but UNO Pins 23 to 28 can also be Output Pins (Despite being in the Analogue Input part of the Arduino).  If you use every Pin (Including TX & RX), you might be able to get up to 20 Output Pins on an Arduino UNO.  See the attached PinOut document.

 

___

I think it's amazing that during the last 11 months, this post has attracted no response from either @Suzie or @Robin2.  But, as soon as someone new comes along and responds, they chip in with their 2 bob's worth.

 
It's unfortunate that @OOrail has had to wait this long for their duplicating and confusing contributions.
 
Maybe, that's why @OOrail stopped uploading Arduino videos, for the benefit of other Members.

Arduino PinOut_Uno.pdf

Link to post
Share on other sites

I cannot see anything in the earlier posts that I can add anything to, but it is clear from the PNP diagram that anybody trying to use it will be disappointed, and that the NPN diagram is an excellent solution. Specifying transistors with 2A to 10A collector current is not the sort of thing for driving a LED from 5V.

 

It might have been worth showing a diagram with a small relay driven directly from the Arduino pin as alluded to in Robin2's post perhaps. There are some double pole 5V relays around that will run from 5V quite happily drawing less than 16mA that can handle 2A per pole - could make life a lot easier for home constructors who want the isolation of a relay.

 

http://uk.farnell.com/te-connectivity/fx2-d3223/relay-signal-dpdt-250vac-220vdc/dp/9913912

 

Just add a 1N4148 back EMF diode and job done.

Link to post
Share on other sites

...

Just add a 1N4148 back EMF diode and job done.

 

Most websites prefer to recommend the 1N400x ('x' is a function of which Voltage you want - Refer to the VRRM in the attached Datasheet), because the 1N4148 is classified as a Small Signal Diode, and rated at only 0.3 Amps.

 

The 1N4148 has a Maximum Current of   2A for 0.000001 Seconds.

 

The 1N400x has a Maximum Current of 30A for 0.008300 Seconds.

(See the graph on Page 2 if the 8.3 ms pulse is to be repeated)

 

Diode, Small Signal_075v 0.300A 0008ns_1N4148_Vishay.pdf

Diode, 1N400x_1A.pdf

Link to post
Share on other sites

@Robin2 says "An Uno can control 12 servos. A Mega can control 48."

 

If anyone is interested, I can point them to a series of articles (And the Arduino sketches) that show Servos being controlled using every Output Pin on any Arduino.

That supports my suggestion to use servos so I'm not sure why it was written in that somewhat critical style.

 

...R

Link to post
Share on other sites

I could write at length about the different merits of 1N4148 and 1N4001 diodes in this application, but they are both suitable for the task - the main difference being size and cost.

 

Worth thinking about two arduino pins per point - one to operate the servo and a second one for the frog switching relay!

Link to post
Share on other sites

I could write at length about the different merits of 1N4148 and 1N4001 diodes in this application...

 

Since you didn't bother to "write at length", I found this article on the Wikipedia website:

-   https://en.wikipedia.org/wiki/Flyback_diode

 

For whatever reason, it disagrees with your assertion that the specifications of a 1N4148 are suitable as a Back EMF Diode.  It gives 2 reasons:

1  -  "... the total time for the solenoid to discharge is a few milliseconds."

(The 1N4148 has a Maximum Current of  2A for 0.000001 Seconds.  If Wikipedia is to be believed, the Duration of the Back EMF exceeds the 1N4148's limit by thousands of the specified time units.)

2  -  "... one would seek a diode which has very large peak forward current capacity (to handle voltage transients without burning out the diode) ... Depending on the application and equipment involved, some voltage surges can be upwards of 10 times the voltage of the power source, so it is critical not to underestimate the energy contained within an energized inductor."

(10x 12V = 120V  -  VRRM for the 1N4148 is 100V,   In addition, the 1N4001 that @Suzie specified has a VRRM of only 50V, so a  1N4007 with a VRRM of 1000V would be a safer choice).

 

___

@Suzie goes on to say:  "... they are both suitable for the task - the main difference being size and cost."

 

If you have a look at these 3 Maplin links, you find an odd thing:

1N4148 is £0.09 (http://www.maplin.co.uk/search?text=1N4148&x=0&y=0)

1N4001 is £0.09 (http://www.maplin.co.uk/search?text=1N4001&x=0&y=0)

1N4007 is £0.09 (http://www.maplin.co.uk/search?text=1N4007&x=0&y=0)

 

If you have a look at these 3 Farnell links, you find a quite different cost structure:

1N4148 is £0.0154 (http://uk.farnell.com/multicomp/1n4148/diode-100v-150ma-do-35/dp/9565124)

1N4001 is £0.0706 (http://uk.farnell.com/multicomp/1n4001/diode-standard-1a-50v-do-41/dp/9564993)

@Suzie's Cost claim doesn't seem to be borne out at Maplin.  But at Farnell, you will get 4.5x of the 1N4148 for the cost of the 1N4001.  Or, you could go the safer route (1N4007), and save 0.9 Pence!  But, still costing about the same as 4x of the 1N4148.  A third or fourth vendor might have different pricing again.

 

I don't know about you, but the cost of the Darlington at Farnell is more than 5.6x the cost of any of the 1N4007 Diode (£0.347  -  http://uk.farnell.com/on-semiconductor/bd681g/darlington-transistor-to-225aa/dp/9557709). So, you can save 4.62 Pence on the Insurance, and then pay to replace whatever might blow up.   If a 1N4148 faulire occurs, do you want to find out what the full cost is?  Or would you prefer to pay the extra 4.62 Pence as Insurance?

 

Without the full Cost facts, it's possible that Members will be scared into doing something they might regret.  When, in fact, the Cost difference is (IMHO) quite small.  Members should decide for themselves, once they have the full facts.

 

 

Then, there is @Suzie's claim that the Size difference of a Back EMF Diode is an issue.

 

The above Datasheets show that the size of the 2 Diode Bodies are:

1N4148  -  1.75mm x 3.4mm

1N400x  -  2.70mm x 5.2mm (Maximum figures used)

Savings  -  0.95mm x 1.8mm

If 1.8 millimeters is important to Members, then the 1N4148 wins!!!

 

However, to avoid the Back EMF Current flowing through lots of wire between the Coil and the Switching element (Which adds resistance and lengthens the period that Back EMF occurs), it is common to wire any Back EMF Diode across the Terminals of the Coil.  Now, I don't know how small the coils in @Suzie's mind are, but the one provided as a Reference by @Suzie above (http://uk.farnell.com/te-connectivity/fx2-d3223/relay-signal-dpdt-250vac-220vdc/dp/9913912) is  huge by comparison to both the 1N4148 and the 1N400x, but the 1N4148 is smaller than the 1N400x (As shown above).

 

So, assuming that the 1N4148 is fit for the purpose, there is a small difference.  But, in the case of a Coil, the difference between the Diodes (IMHO) doesn't seem worth comparing.  Again, Members should be able to decide for themselves, once they have the full facts.

 

___

Maybe there are Members out there that have used the 1N4148 successfully wired across the Coil of a Relay or Point Motor.  They might like to contribute to the discussion here, so that other Members can save the few pence and the couple of millimeters that @Suzie is concerned about.

Link to post
Share on other sites

I'll outbid you all: 6 outputs for 256 coils (or 128 points)  :boast:  Nice bit of multiplexing (pun intended :P) with 17 (!!) CMOS 4514 chips and 32 (!!) ULN2801...4A Darlington transistor arrays.

 

The Datasheet provided by @Dutch_Master for the ULN2804A Darlington Transistor Array shows that it has a Current Limit of 0.5A.  That might be insufficient for the Peco PL-11 Point Motors that @OOrail originally wanted to switch with an Arduino.

 

The Peco PL-11 Manual (http://www.peco-uk.com/imageselector/Files/Instruction%20sheets/PL-11%20Instructions.pdf) says that a Power Supply of  "16VAC at 2 Amps is recommended."  However, you can use multiple channels in the ULN2804A, to get an aggregate of the required current by whatever Point Motor is in use.  For a PL-11 that would appear to be a minimum of 4 (i.e. 2x Coils per ULN2804A), and for a PL-10, that would appear to be a minimum of 8 (i.e. 1x Coil per ULN2804A),

 

The Price for a ULN2804A at Farnell (http://uk.farnell.com/stmicroelectronics/uln2804a/darlington-array-8npn-2804-dip18/dp/1094429?ost=ULN2804A&selectedCategoryId=&categoryNameResp=All%2BCategories&searchView=table&iscrfnonsku=false) is  £0.938, so is a more expensive alternative to (Say) a BD681 (NPN Darlington, 100V, 4A  -  http://uk.farnell.com/on-semiconductor/bd681g/darlington-transistor-to-225aa/dp/9557709) at £0.347 per Coil or Channel.

 

If other Members need to switch anything within the limit of 1 Channel in the ULN2804A, then it is only £0.11725 per Channel (33.7% of the BD681 price).

Link to post
Share on other sites

Smart people don't buy in bulk from Farnell :rolleyes:  They go to the source themselves:

 

Even smarter people know that some sellers in China deal in counterfeit devices, that might not work according to the Datasheet for the part number on the device.

 

 

And, not everyone buys in lots of 50 Pieces that @Dutch_Master's 3 AliExpress Sellers want customers to buy in.  Farnell give quite tangible discounts if you buy 10+ of the same device (Even better if you buy 100+  -  If you are that keen).

 

Obviously, the smartest people compare apples with apples.

Link to post
Share on other sites

The peak release current from the relay is 16mA - well within the spec of a 1N4148 (at least 75mA and probably 1A in this application).

 

The diode reverse voltage will be 5V - well within the spec for a 1N4148 (at least 75V).

 

Operating in 4nS to limit the back EMF voltage as a 1N4148 does is better than having to wait much longer for a 1N4001 to start conducting before it protects the driver transistor(s).

 

I pay 0.1p for 1N4148 in the quantity I normally use them - literally ten a penny, 1N4001 are not that cheap because they use more material in their manufacture due to their larger size, and the use of more expensive materials, and fewer are sold. Maplin are clearly making a lot of profit on 1N4148!

 

Having got through several reels of 1N4148 diodes for exactly this use without any reported failures I do think they work and I continue to commend them to the RMweb readership.

Link to post
Share on other sites

Now, I don't know your background, but given you have obviously some knowledge on electronics I'll happily assume it's technical.

 

OK, I can see that my background has piqued your interest.  If you want to play 20 Questions (You have already used up 1), I will give you the following hints:

-  My 1st job was as a Copy Boy for a Newspaper

-  My 2nd job was as a Photographer (For the same newspaper)

-  My 3rd job was as a Relief Worker in India, Bangladesh, and then Ethiopia

-  My 4th Job was as a Car Cleaner

 

As you can see, none of these were Technical.

 

If you want to continue to play 20 Questions, suggest the most appropriate forum to continue, because speculation about my background probably shouldn't have ever been raised here.

Link to post
Share on other sites

I'll outbid you all: 6 outputs for 256 coils (or 128 points)  :boast:  Nice bit of multiplexing (pun intended :P) with 17 (!!) CMOS 4514 chips and 32 (!!) ULN2801...4A Darlington transistor arrays.

This comment is not aimed specifically at @Dutch_Master.

 

I am lazy. I like the idea of controlling stuff with as few components as possible and the minimum use of the soldering iron.

 

I reckon you don't have to spend very long connecting up external chips and diodes and such before the cost of an extra Arduino and a few servos looks attractive.

 

...R

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...