Controlling a reversable DC Solenoid/Magnet

Guys,

I need to control an external magnet, but this isn't the standard relay control.

I have a section of track known as a 'point' (railroad terminology) that changes the path that trains take. This is controlled by two small electromagnets. There are two (one to pull in each direction, whilst the other pushes) and they are wired in series. You can see pictures of them here. The direction is controlled by the DC polarity.

Now, I don't know exactly how much current these draw (I intend on checking tonight) but I do know they can function on lower voltages (9v tested successfully)

My question is, how do I control a DC supply momentarily and be able to reverse the polarity? Every schematic I have seen just shows the typical NPN transistor with diode and relay in a fixed polarity.

I suppose I would like to only have one pin of my Arduino used to control one 'point' and, if possible, make it toggle when the pin is momentarily set high. I understand this would then need a flip-flop gate, and am happy to sort that out... the issue then still is to work out how to reverse the polarity and have the power to the point motor/magnets still isolated.

Thanks in advance for any advice.

What you could do is have a transistor controlling a DPDT relay, and wire the relay so on one side is normal polarity and the other side is reverse polarity, when a arduino pin is low polarity is normal, when pin goes high polarity is reversed, simple...

See below diagram, stolen from instructables, this was a guide on reversing polarity with a DPDT switch, but same concept applies to DPDT relay.

bircoe,

Thanks for the response... This would work, but would not be momentary. I can't have the magnets constantly powered as this would result in melting track.

Using a H-Bridge to control your magents, replace the motor with magents.

http://itp.nyu.edu/physcomp/Labs/DCMotorControl

Bill,
That was another thought, as I control a PWM DC signal to the rails here. But I didn't want a H-Bridge per 'point', as there's around 12 of them.

I suppose that could be the correct method for the powering; but I'd just have then use relays to direct the current to the correct set of points.

With those solenoids, aren't they normally constantly powered? I have a friend who has a very large train set but I have not looked into the points control in detail - they are being controlled by a two position switch and the driver board does not look like much more than a relay and some other simple stuff...

Mowcius

But I didn't want a H-Bridge per 'point', as there's around 12 of them.

Unfortunately, you're kinda stuck with H-bridges: that's what's needed to drive those sorts of mechanisms.

You could take the approach of using only one, and connecting it with relays, but then you'd have to add transistors to drive all the relays.

Another approach would be to use one L293D for each two sets of points, drive all their direction inputs in parallel using 2 digital pins, then drive their enable inputs individually as needed to activate them. That can be done using something like a decoder or multiplexer, so you can do the selection with only 4 pins, if you sacrifice one of the 16 outputs as your "safe" state.

Now, I don't know exactly how much current these draw

If they can operate with 40mA at 5V (200mW) or less you could drive them directly from two Arduino digital output pins. Measuring resistance across the coils would give you an indication of what is required (should be higher than 125R).

Another option (if higher voltage/more current is needed) would be to get a power supply with plus and minus rails at the voltage you require and use the Arduino with approproate transistors to switch these against a common ground.

Since you are planning on controlling these with an Arduino, do you absolutely need to use these switchers? They aren't really "authentic" to a layout, so...

Set up servos underneath the layout, with special (custom, likely) clutching mechanisms (or possibly use springs), hooked up to levers and such to move the track segment to and fro; with this arrangement, you could even potentially model a guy switching/moving a dummy lever to switch the rails (if that is what you are modelling).

The servos would be powered in some manner (probably a separate power supply, or maybe they could be powered off of a regulator hooked into the auxillary supply for accessories - however you have things set up). Then, you would just use a servo controller hooked up to the Arduino to control the switching. The clutching mechanism/springs would serve to keep the servo from breaking/burning out (or breaking the track switch) if over-travel was present.

It would present a smooth look, be relatively fast, be easy to interface with, use standard parts from any hobby supply store, and you wouldn't have the annoying click/clack of electromagnets slamming switches back and forth.

The downside? You couldn't control it using standard model railroad control systems; but who cares, right - that's the point of the project, correct?

Good luck in whatever solution you use!

:slight_smile:

With those solenoids, aren't they normally constantly powered?

mowcius, I do know the Peco points make an annoying hum/buzz when active and therefore should not be constantly powered. These are different, and I suppose I should just try and see what happens. I'm currently asking the Japanese N Scale forums if they know if the switches that come with the points are momentary or constant.

Update: This link shows a cut-open switch... these are tricky in their design and the voltage is definitely momentary. The contacts flick past each other and provide enough continuity to switch the tracks.

Unfortunately, you're kinda stuck with H-bridges

Ran, Thanks for the heads up and advice on the L293D. This is a little more economical and a viable option, and I'd be able to get it going.. I do like the idea of multiplexing too, but I'd prefer to stick with easier electronics :slight_smile:

If they can operate with 40mA at 5V (200mW) or less you could drive them directly from two Arduino digital output pins

BenF, I didn't have enough time to check the drain on these last night, I'll probably not have enough time tonight either... I do like your idea of the +/0/- rails though... thanks!

Set up servos underneath the layout...

cr0sh, I love it, but I'm not going for ultra realism this time :). This is to be a small and easy Japanese layout with focus more on the electronics rather than the actual real-world operation. I'll leave the tortoise switches (they're the model-railroaders version of servos) for my house-sized HO layout when I'm 64. Otherwise your idea is fantastic and I'd love to see the servos driving the points, the semaphores and yeah, the signalmen.

Instead I might utilise servos for other effects on the layout, as these points are nice and compact and it'd really be a waste to not use the built in mechanism.

I must thank you all for your replies, you've really helped me out. Now I just need to find the time to implement the ideas.

You can probably make a crude rotary switch setup using two inexpensive servos, two plastic jar lids, and wire. Might be interesting just to watch it operate.

I do like the idea of multiplexing too, but I'd prefer to stick with easier electronics

Oh, the decoding really is "easier electronics": look into the 4514 (also available as the 74HC4514). Unlike many decoders, it has a latch, so you need 5 pins to control it. But it has active high outputs, instead of the active low decoders usually do, so you don't need to add inverters to match the L293D's active high Enable input. That gets you to just about the minimum possible component count: 7 chips, and 7 Arduino pins, to control all 12 sets of points.

Ran,

I have just been designing my concept, since finding out that it needs to be momentary... The goal is to just send a short HIGH to the enable pin to activate that point.

Controlling the actual electromagnets:

Enabling the H-Bridges using 5 pins: (updated... not finished)

..that equals 8 pins for 8 points.

Now, I'm going to look into the 4514 :slight_smile:

Since you're only going to activate one H-bridge at a time, you can tie all their direction inputs into one pair: you don't care what the states of the inactive H-bridges' inputs are, because their outputs are turned off.

You missed something on your "enable multiplexer", though: the unselected outputs aren't low. They're effectively an open circuit, so the Enable pins on the unselected L293Ds are free to float to a high or low. Ideally, they'd have a weak pull-down on the chip, so that motors don't glitch during system reset, when the microprocessor pins that usually drive the pin are defaulted to inputs. But that doesn't show up on the datasheets I've looked at, so prudence demands that you add the pull-down externally.

Ran,

I was thinking about this when you mentioned that 7pins would do it... and it's a great idea to tie the direction pins together.

As for pulling the 4051 to ground, does this require a 'pull-down' resistor? Or is it straight to ground?

Meanwhile, you mentioned the 4514. This looks great with 16 outputs, but I don't quite understand the latching?
Does this mean that you can start setting the next output on the pins and then toggle the strobe to get the new pin high? i.e. you can have it so that a pin is always outputting something, whereas the 4051 requires that you turn everything off before switching? That's the best I can make of it.

And finally, daisy-chaining these ICs would provide more than enough outputs for me.

After that, I think we've pretty much got it :smiley:
Thanks again!

As for pulling the 4051 to ground, does this require a 'pull-down' resistor?

Yes, something on the order of 5-10K, so the Arduino can easily pull the pin high when its output is active, but the L293 input is still pulled low when the Arduino output is not connected through the multiplexer.

With the 4514, you set the 4 "select" pins to a value from 0000 through 1011, then toggle the "STROBE" line to change the output pins. Make sure you tie the "INHIBIT" pin low, or it will disable the outputs.

It appears that you've noticed that, as you change the "select" inputs to the 4051 one pin at a time, you can get glitches on the outputs. This is true, but they'll be too short to matter: the few microseconds of glitch could (and probably would) cause problems with digital logic, but won't be enough to move the solenoid. Ideally, you'd use an Arduino pin to hold the "OUT/IN" pin low while changing the "select" pins, but, in this case, you can get away with tying it high if you want to save an Arduino pin.

You probably could control the 12 H-bridges in the chips using 3 74HC259 chips and 6 Arduino I/O pins.

With the 4514, you set the 4 "select" pins to a value from 0000 through 1011, then toggle the "STROBE" line to change the output pins. Make sure you tie the "INHIBIT" pin low, or it will disable the outputs.

Ran,
Thanks for the further information. I take it i'll be using the inhibit pin to actually activate the h-bridges as it'll control the output. The process would be to keep inhibit high, set the output, toggle the strobe, then toggle the inhibit. Overkill yes, but clean enough. The 4051 would be good enough but this single IC gives double the amount of outputs. It also provides me with outputs that don't need to be pulled in either direction.

The final solution, when using an inverter on the output for the direction means 1pin for directional control and then 6 pins for the 4514. I wonder if I can tie the strobe and inhibit together, using a capacitor to delay the inhibit if required to get it to fire after the strobe.

Then again, I am using a Mega and I don't need to be this much of a stooge with pins.

You probably could control the 12 H-bridges in the chips using 3 74HC259 chips and 6 Arduino I/O pins.

zoomkat,
I could, but these chips seem to be overkill for what I want to do. For the majority of the time I don't want them to output anything... I simply want to set the output pin and then push HIGH for a short period of time. Even the 4514 seems overkill, but due to the 16 output pins I'm going to go for it.

So, now that I'm opening my eyes, it seems that there is quite a wide range of line decoders available... To really save pins I should find one on I2C or RS232 :slight_smile:

Well, if you to use a single serial pin using rs232 protocol, then get three SN74LV8153 chips ($1.37 each at Mouser). The chip uses TTL input, so you probably wouldn't have to do any signal inverting.

The process would be to keep inhibit high, set the output, toggle the strobe, then toggle the inhibit.

Not a good process: you want to keep the inhibit line low all the time, because taking it high will tristate the decoder outputs, and allow the L293 inputs to float.

The advantage of using the 4514s is that the latching feature lets you fiddle the select inputs individually (which the I/O structure of the Arduino pretty much forces you to do), then change the outputs only when you're done.

So the right process is to set up the 4 select lines as needed, then toggle the strobe line to transfer them all at once to the 4514's internal logic.