[TriEmbed] MOSFETs or Relays

The MacDougals paulmacd at acm.org
Fri Jun 27 08:12:57 CDT 2014

Brian, here is my summary of the situation.  Anyone can correct me as needed


Your train switch is two 12V solenoids that are alternately pulsed to change
the direction of the track.

The two solenoids have their "grounds" connected.

You have a working circuit using an N MOSFET on the low side that acts as a
switch to connect the

common ground terminal to ground.  So, if you connect 12V to either the
Straight or Turn connection

the Arduino can move the switch.  If you connect 12V to both straight and
turn, when the MOSFET

closes, both solenoids activate (which is not what you want).


One option is to use a P MOSFET on the high side to control application of
12V to Straight or Turn and have the Ground terminal connected directly to

The problem with this is that your port expander can only provide 5V to the
gate of the MOSFET, which is not sufficient to turn it off (needs to be
around 10V).

Pulling the gate up with a resistor will turn the MOSFET off, but will send
12V into your port expander pin (not good).

Now, you need some other device between the port expander pin and the gate
to switch 12V.  This could be a transistor or an N MOSFET.

So, now you need two MOSFETs on each side.  I use something similar to this
on my Nautilus Gear sculpture to control the power to the ATtiny.

I found a nice small package with both an N and a P MOSFET:


Another approach is to disconnect the two ground wires of the two solenoids.
You essentially want to make your three terminal train switch into a four
terminal device.

Straight, Gnd, Turn, Gnd.  You then use an N MOSFET on each Gnd terminal to
energize that solenoid.


I am sure that you know that these solenoids are not designed to be turned
on for long periods of time.  You just want to energize them long enough to
switch the track.

So, the software driving them should provide a pulse for half a second or


---> Paul



From: TriEmbed [mailto:triembed-bounces at triembed.org] On Behalf Of Rick
Sent: Thursday, June 26, 2014 7:57 PM
To: triembed at triembed.org
Subject: Re: [TriEmbed] MOSFETs or Relays


Good catch Rodney,

Brian, unless you tie the solenoid ground (negative supply terminal) and the
I/O port expander ground (again, negative supply terminal) together, you
will have no reliable gate-source current path. As such, you won't be
controlling the Mosfet.

If you absolutely need isolation between the two, you will need to provide
an optoisolator driven from the I/O port expander, PLUS a 5 volt isolated
power supply to turn the Mosfet gate on.

If you measure the voltage between the gate and source of the Mosfet, you'll
see a voltage, which will explain why the Mosfet is turning on.

Is there any reason you don't want to connect the two negative supply
terminals together?



On 6/26/2014 7:20 PM, Glen Smith wrote:

Is the 12v supply ground and the pi ground tied together? If not you can see
some wacky results with 2 power supplies floating relative to each other. 

- Thumbed one letter at a time on a 2.25 x 1.25 inch Galaxy smartphone
keyboard, please forgive any errors.

On Jun 26, 2014 5:12 PM, "Grawburg" <grawburg at myglnc.com> wrote:

Rodney asked for more detail;


Attached is the single n-MOSFET circuit (it's from the project manual I'm

The MCP23017 is an I/O port expander between the devices and the Raspberry

Each MOSFET connects to a different output port.

The ground is the ground for the 12VDC, not the Pi.

I have not checked the output voltage from the chip; I will try putting a
resistor in-line as suggested.





Triangle, NC Embedded Computing mailing list
TriEmbed at triembed.org
TriEmbed web site: http://TriEmbed.org

Triangle, NC Embedded Computing mailing list
TriEmbed at triembed.org
TriEmbed web site: http://TriEmbed.org


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.triembed.org/pipermail/triembed_triembed.org/attachments/20140627/3ac53e74/attachment-0001.html>

More information about the TriEmbed mailing list