Hi - I'm working on a model railway project using pico boards, but have spotted something that ought to be improved.
The power to each section of track is scheduled to be switched by a relay. I've a bank of 8 traditional relays, but have just realized the total relay current will be up to a half amp or so worst case. I'm looking to a solid state solution.
The relays are switching DC at 12V, but the polarity is determined before the on/off relay. Most SS relays I've seen are triac-based for AC only; one type would do DC, but not with the polarity changing (and at
10x the cost anyway!).
Does anyone know anything solid state that might do this without breaking the bank?
Thanks.
Didn't find your answer? Ask the community — no account required.
A
Andy Burns
You could use a H-bridge, rather than build it from discrete transistors/FETs they come as a single or dual bridge in an IC, possibly with built-in snubber network.
T
The Natural Philosopher
Absolutely
What you need is a switching MOSFET. And a couple of resistors to control the gate and maybe a diode to absorb spikes.
I am using LB8721s.
Ground the gate to negative with 150k and feed it from your Pi with something like 150 ohms. and connect the source to negative and the drain becomes the switched negative output. You may want to put a 1N5187 diode across the load to calm any switch off spikes .
On a bit of metal to absorb heat these will do about 20A continuous - they have very low 'ON' resistance so they don't get too hot.
These are only single pole and only able to switch the negative of course.
If you want to switch the positive (as well) you will need a P channel device and I don't know what to recommend
T
The Natural Philosopher
Good thought. If you want to *reverse* the voltage . I am not familiar with how todays model railways actually work. I thought they had electronics in them to control speed and direction.
Actually re reading the question he wants a *polarity neutral* switch.
That is not easy. And is not exactly what an H bridge will do.
I'd probably use a P channell and N channel MOSFET in parallel
But realistically I'd probably use a 3.3 or 5V Songle relay. They are uber cheap in bulk from Aliexpress.
formatting link
on a board with a nice opto isolated input. If you want full isolation just use two :-)
I use this sort of relay in my central heating controller to switch the zones.
If you want single relays then they are less than 50p in bulk.
formatting link
And in fact cheaper elsewhere.
The 5V coils are around 70ohms which was too low for my application direct from a PI so I added transistor buffering - the relays draw about 70mA
This is the sort of thing its not hard to design and get PCBs made up for at minimal cost. I use old style components as my eyesight is not good enough for surface mount goodies.
R
R.Wieser
Mike,
Carefull there : any kind of sparking (like can happen with a bad contact between the loc and the rails) could cause quite a power spike on the solid-state relais and destroy it. I would suggest keeping the relais you now have.
Use Andys' suggestion*. Just make sure the snubbing network is upto the task.
Take a look at the H- or T-bridges used for stepper motors.
Regards, Rudy Wieser
T
Theo
I was wondering about using back to back IGBTs. See 'four quadrant switching' on p23 here:
formatting link
but with IGBTs not bipolar (NPN/PNP) transistors.
Never actually used an IGBT for real so not sure how 'small scale' they can go, but I'm seeing 6.5A versions so they're not just for kiloamp-scale locomotives:
formatting link
Agreed, I think that's the simplest solution here.
Theo
D
David Higton
There are various solutions, each with its own advantages and disadvantages.
One is to use two MOSFETS with the sources and drains parallelled, the switched path being that between the two drains. You'll see a drop of about 0.6V across it when it's on. (If this is a problem you can connect a Schottky diode in parallel with each MOSFET, which will reduce the drop to nearer 0.3V.) The principal snag is that the control voltage, which is applied between gates and sources, has to float.
If you can drive relays momentarily but not continuously, consider bistable relays.
David
A
Adrian
Some people are still using the traditional DC systems, others use DCC, which requires electronics in each loco.
Adrian
M
Mike Scott
plus ££££££
I was trying to get something simple done on the cheap. The expense of DCC would barely be justifiable.
M
Mike Scott
I do have some, bought for another part of the project. But at IIRC ~£7 a pop, they're not cheap: I need 8.
M
Mike Scott
I'm beginning to agree. I've been hunting round for prebuilt modules to do the trick, and nothing provides isolation like a good old-fashioned relay. Maybe I just have to put up with the current drain.
Many thanks to all who've responded with ideas. I'll look around a bit more, then press on with the relay bank.
T
The Natural Philosopher
A 20p transistor driving a 40p relay is probably best then
T
The Natural Philosopher
Well its only 70mA a relay When its on
M
Mike Scott
On 01/08/2025 17:52, The Natural Philosopher wrote: ,,,
.
x8 though, worst case. Over half an amp. Seemed a lot just to let some current through to the tracks.
T
Theo
I'm seeing things like this for searches of 'magnetic latching relay' for £1 a relay or £2 on a board with GPIO inputs:
formatting link
No experience, but I think there are some boards which do the latching digitally and then drive a conventional relay. These ones look like the real deal.
You have to hold the latching inputs for a certain length of time - not sure what happens if you exceed the rated time, I don't know if there's a danger of burning something out (railway modellers will perhaps be all too familiar with this idea from motorised points).
Theo
C
Computer Nerd Kev
There are also "high sensitivity" type relays which can use less.
I repaired a modern model train controller a while ago and it had a bank of mechanical relays inside. Variable speed control was done with a very beefy set of MOSFETs in a H-bridge circuit, which had nevertheless been blown apart when the owner hooked the power supply up backwards.
T
The Natural Philosopher
*shrug* subjective.
A Pi pico draws up to 2.5A
So you are faced with having a little 5V/2.5A PSU block on board anyway.
T
The Natural Philosopher
:-)
-- There is nothing a fleet of dispatchable nuclear power plants cannot do that cannot be done worse and more expensively and with higher carbon emissions and more adverse environmental impact by adding intermittent renewable energy.
G
Gordon Henderson
So you're looking for an AC SSR. Forget that the polarity is switched before the relay as to all intents and purposes it's effectively AC.
The main issue I had when doing this on a Pi some years back was that all the SSRs I used had a 5v input voltage with built-in limiting resistors on the opto isolator part. Saying that, I didn't find one that wouldn't work with the Pi's 3.3v output. I've no experience of the Picos outputs though.
I was switching 240v AC not 12v AC - and there is another issue - a lot of them are aimed at higher voltages - say 36-240v AC
Searching ebay find this for example:
formatting link
it's actually rated 3 to 32v input but the output is >= 24v AC so it may not turn on at 12v. Also be aware that triac based ones may be relying on the zero crossing to turn off, so once on, it might remain on even when you remove the control voltage. I suspect the ones with GTO switches are the more expensive ones.
Personally, I think that if I already had a working bank of mechanical relays (with opto isolated inputs such as the multitude sold for Adruino and Pi) I'd just suck it up and give it a separate 5v PSU capable of driving the coils. (Or take the main system 5v and give it a good decoupling from the electronics side to minimise any interferance).
Sure, it may well be a waste of energy but half an amp at 5 volts is a mere 2.5 watts. Run that continually for a year and that's 22 KWh which should be under a fivers worth of energy, but the chances of running it like that are probably remote... (how much was the last coffee and cake you bought?)
And mechanical relays will allow the passing of any DCC signals if you're using that.
-Gordon
T
The Natural Philosopher
Remember that although a PI can only drive 3.3V it can happily (and usually does) run off 5V.
I bought a load of these
formatting link
5V 3W. I used a simple single NPN transistor and a couple of resistors to drive the relays off 5V
I've found that drawing up a PCB for these sorts of things is so simple that I dont even prototype them
You need a PSU and best practice is a suppression toroid, and suppression cap and fuse on the mains side and a small smoothing cap on the output side. and a diode to feed the PICO so that you can program it with the power off. Picos pins feed NPN transistor bases via resistive droppers and collectors go to the relay coils and then to 5V.
The whole thing is a single neat circuit board . The pico solders onto it using pins
If I don't need wifi I use the RP2040 Zero unless I need more pins to be accessible. Its cheap as chips
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.