# Servo controlled crossing gate



## riderdan (Jan 2, 2014)

Here's another servo-control project I have on my workbench. This is an LGB crossing gate that I picked up on fleabay for $10. I need a crossing for double tracks, so I disassembled it and set one half on each side of the tracks, no longer connected to each other. To disassemble it, I had to remove the "works"--a system of rods and levers, activated by weight, which I found finicky anyway.










The little styrene box I built to house the servo. I am using a Tam Valley Servo singlet to drive the servo in the video below, but I'll probably need to put together a different controller, as the singlet wants a momentarily closed contact for control and the IR-based train detector I'll be using latches.


----------



## general1861 (Jan 22, 2010)

Cool!!


----------



## JackM (Jul 29, 2008)

Sounds like a neat project. Unfortunately, the YouTube box is empty except that the upper left corner has what looks like a screwhead which I realize is actually a circle with a diagonal line thru it - the universal sign of "we don't want you to see this".

I just bought this computer with one terabyte of memory, and still I have to deal with this!?!

JackM


----------



## riderdan (Jan 2, 2014)

JackM said:


> Sounds like a neat project. Unfortunately, the YouTube box is empty except that the upper left corner has what looks like a screwhead which I realize is actually a circle with a diagonal line thru it - the universal sign of "we don't want you to see this".
> 
> I just bought this computer with one terabyte of memory, and still I have to deal with this!?!
> 
> JackM


You could watch it directly on YouTube here

```
https://www.youtube.com/watch?v=Mk3Tnv4B1x4
```


----------



## JackM (Jul 29, 2008)

Thanks, Dan - excellent work.

JackM


----------



## Cataptrra (Mar 16, 2015)

So did you ever finalize your servo controlled automated crossing gate{s}?

And how did you set it up to get it to work?

I know this thread is close to being over a year old, but seeing there was no further info, just curious if it ever got off the workbench and onto the railroad?


----------



## riderdan (Jan 2, 2014)

Cataptrra said:


> So did you ever finalize your servo controlled automated crossing gate{s}?
> 
> And how did you set it up to get it to work?
> 
> I know this thread is close to being over a year old, but seeing there was no further info, just curious if it ever got off the workbench and onto the railroad?


Sadly, it never got off the bench. 

I was testing a weather sealed version of this same setup for throwing points, because I didn't want to ruin a bunch of these if they couldn't stand up to the heat/humidity/rain. My impression was that they're not really intended for outdoor use. The weatherproofing test went fine, but I ran into some other issues. One was that the sensors I was going to use to throw the gates weren't reliable outdoors. Not that they couldn't sense in the sunlight (I was using pulsed IR sensors) but they apparently didn't take the weatherproofing as well as the singlets. A second problem was that the "stainless steel" wire I was using turned out to rust through pretty quickly where I used in in another application outdoors. Originally I tried brass wire, but it wasn't stiff enough... 

I'm still trying to work out a sensor scheme that will last outdoors. My current thinking leans towards putting rare earth magnets under locomotives and on the trucks of rolling stock, and using reed switches and a potted electronics module to throw the gates until it doesn't get a signal for <n> seconds. And I've found some very fine brass tubing that is much more rigid than wire.

I actually took this back down off the self last week to work on it. If I get it figured out, I'll post again.

I'm a little bit like that dog from the Disney movie "UP"--I get working on something, run into an issue and put it aside to work on something else, then... "Squirrel!" A year later I look up on the shelf and see the project and start the cycle all over again.


----------



## ewarhol (Mar 3, 2014)

riderdan said:


> I'm a little bit like that dog from the Disney movie "UP"--I get working on something, run into an issue and put it aside to work on something else, then... "Squirrel!" A year later I look up on the shelf and see the project and start the cycle all over again.



Hahahahaha.... I have no idea.... SQUIRREL.... what you're talking about. 

UP is good movie. Our kids enjoy it. When they get distracted my wife and I always shout out squirrel.


----------



## Tomahawk & Western RR (Sep 22, 2015)

that is a cool idea for crossi.......................SQUIRREL!!!!!!!!!!!!!!!


----------



## Cataptrra (Mar 16, 2015)

riderdan said:


> Sadly, it never got off the bench.
> 
> I was testing a weather sealed version of this same setup for throwing points, because I didn't want to ruin a bunch of these if they couldn't stand up to the heat/humidity/rain. My impression was that they're not really intended for outdoor use. The weatherproofing test went fine, but I ran into some other issues. One was that the sensors I was going to use to throw the gates weren't reliable outdoors. Not that they couldn't sense in the sunlight (I was using pulsed IR sensors) but they apparently didn't take the weatherproofing as well as the singlets. A second problem was that the "stainless steel" wire I was using turned out to rust through pretty quickly where I used in in another application outdoors. Originally I tried brass wire, but it wasn't stiff enough...
> 
> ...


Not sure what you could use for a stiffer wire, but for weatherproofing those IR sensors, have you tried any of the Flex Seal products, like the liquid that they could be encased in with just the sensor detector or emitter of them being the only part of the sensor not covered?

This stuff is pretty awesome, I used some on some of my fan driven smoke units that had air gaps in them, just small pin hole or slightly larger holes, just enough that some of the smoke would get blown out these holes and not allow the profuse smoke out the main exhaust port up the stack. 

Used the black flex seal lightly coated around the smoke unit and it sealed up everything, including the holes where the leads from the heating elements were soldered to the board. Also helps keep the wires soldered to the board as well. 

This stuff is inflammable and the smoke oils don't appear to eat it up, like it does with some rubberized items, like the eye dropper squeeze bulbs. This stuff seems to be impervious to heat, cold, moisture and has been holding up very well when in use.

Yes, it's a bit expensive for a small can if you can locate it in a regular retail store, Walgreen's in my area stocks it, it comes in different colors, black, clear, white and a couple others, but the retail stores seem to only carry the black in their "Seen On TV" sections.

But so far, this stuff has been impervious once it dries and forms its seal.

So might be something to consider if you'd like to try and continue to use those IR devices as sensors for your crossing gates. BTW: maybe you could also dip that fine steel wire in the flex seal as well and it might actually hold up better than trying to locate a different material to use.

Just some ideas/suggestions I thought I'd toss your way for your crossing gates.


----------



## riderdan (Jan 2, 2014)

Just in case there's still interest in this topic...

The original plan called for crossing gates operated by servos connected to the arm by a steel wire. Using the Tam Valley servo singlets it's pretty easy to get the servos to travel from one end to the other when they sense a closed circuit. There were two issues with the original setup. One was that the "stainless" steel wire rusted away to nothing. Another was that I wasn't completely happy with the control of the servos. I wanted something where I could control how fast the servo moved, how long the gate stayed down, etc. That was tricky with the singlets.

So, back to the drawing board I went. To control the servos, I decided on a microcontroller, because that would allow me to program speed, travel, and timing of the servo. I grabbed an Arduino Uno I had around around (I'm always fiddling with electronics) and hooked it up to a reed switch and a servo. I mounted the servo under the crossing gate--I've had good luck "potting" servos with marine grease and plastidip--and hooked it to the gate's operating arm. 










I wrote a quick Arduino "sketch" and got it all sorted. Basically, if either reed switch is triggered, it runs the gates down and keeps them down for four seconds. If the reed switch is triggered within the four second time, the timer restarts. So if the locomotive triggers the gate, and then the tender, and then each of the three passenger cars, the gate will stay down until four seconds after the last car triggers the switch.

Here's a HLW coil car fitted with a magnet tripping the gate





Here's what happens if the car "parks" on the reed switch





Triggering the reed switch was a little sketchy with the standard magnet I had on the bottom of the coil car. I crazy glued a rare earth magnet to a different car and had much better success. The problem is, along with my "Squirrel!" issue I have a tendency to put things just where I know I'll find them again and then not be able to find them for six months. I almost always stumble across them again when I'm not looking for them... and that's where my nice stack of rare earth magnets is.

Because this is fully programmable (in C) there's complete control over how far the servos travel (currently less than the full 180 degrees), how fast they move (there's a 10 ms delay between each servo step--I could go slower), and the hold down time (set at four seconds from the last trigger). So if I'm not happy with how it's working, I'll just update the sketch on my laptop, plug the USB cable in to the Arduino, and update it. 

I'm just waiting for potting compound for the Arduino before putting it outside. I decided that for the Arduino I'd just use real potting compound instead of plastidip, because I want to still have access to the pins and LEDs. Once it's potted, I'll put it and the voltage regulator into an airtight container with some desiccant, seal it up and put it in the crossing guard shed next to the crossing. At that point, I'll post another video.


----------



## Dave Meashey (Jan 2, 2008)

Dan;

If you happen to use an electric toothbrush similar to the Phillips Sonicare toothbrush, you should be able to "harvest" some rare earth magnets from the base of the brush module. I have a fair collection of these magnets, that I have knocked from the base of the brush modules with a light hammer and modelers' chisel.

Just a thought,
David Meashey


----------



## Cataptrra (Mar 16, 2015)

Looks awesome. And seems to be very smooth and fluid. Really like the way you've got that working, videos were great on showing the detail of how smooth everything works.


----------



## riderdan (Jan 2, 2014)

Here's a video of both gates working on the bench.






I fried the voltage regulator on the Arduino (my fault--I wasn't careful enough with the temporary wiring and shorted a pin) so for the moment it's running off USB power. Once a new board arrives, I'll pot it and stick the whole thing outside to see how it does.


----------



## Cataptrra (Mar 16, 2015)

Seems you have a bit of a delay between the two gates lowering and raising.

Do your servos have an adjustment so that both gates would go down at the same exact time and release the same way?

That delay, at least to me, between the two gates lowering and raising is just a wee bit too noticeable.

Otherwise, looks really good.


----------



## riderdan (Jan 2, 2014)

Cataptrra said:


> Seems you have a bit of a delay between the two gates lowering and raising.
> Do your servos have an adjustment so that both gates would go down at the same exact time and release the same way?
> That delay, at least to me, between the two gates lowering and raising is just a wee bit too noticeable.
> Otherwise, looks really good.


I noticed that, too.

Actually, what's happening is the result of the servos not running quite the same. The "early closer" is running through about 100 degrees of rotation, while the "late closer" actually needs to rotate through 90 degrees. Well, not really "degrees"--what's really going on is that the micro-controller needs to send different values to the two servos to get the gates to the same position on both sides at the same time. 

Right now there's a single loop in the program to close and open the gates--so the processor is doing some math to keep the gates closing at a similar rate. Unfortunately, you can't send a variable containing a non-integer to the servo API, so I'm casting a long to an int to truncate it (the API doesn't seem to include a round() function). I'm pretty sure this is what's causing the difference in closing rate. Or it's possible that the "closed" position of the faster closing gate is set too far "down." Whichever it is, it's solvable, but I'm still working everything out. 

Once I have everything potted and permanently wired (there's alligator clips and breadboard pins in a lot of places at the moment) I'll set it up on the railway and then tweak it until it works correctly. It's possible that will mean changing the loops that control the gates to work in a different way than they do now.

But that's one significant benefit of using a micro-controller rather than a hard-wired board: everything's software and infinitely tweak-able.


----------

