Phoxtane

DIY Cheap Motorized Track Switches (no cutting/glue)

Recommended Posts

I finally have good pictures of the demonstrator model for my take on a cheap no-modification-required switch track motor. Have a look!

800x583.jpg

The key that makes this work is that the servo acts on a slider, which pushes on the little spring-loaded switch point piece, rather than forcing the lever mechanism back and forth. As such, it takes very little force to change the switch from open to closed and vice versa. I'm using two of the 1x1x1 corner panels to trap the servo horn so that it pushes the slider back and forth, while a 2x2 corner tile pushes the point piece backwards and forwards. The actual switch lever needs to be in the 'open' position to allow the point piece to move back and forth properly; otherwise, the switch will stay closed even when the servo releases the point piece. I'm using an Arduino Uno, but you could use any Arduino or compatible clone as long as you get the pins hooked up right.

800x530.jpg

It's a lucky coincidence that the servo is the size it is; two of the 1x2x3 panels form a nice enclosure that keeps it from moving about too much. It's important to get the older style that don't have the reinforcing ridges on the edges, as otherwise it won't fit. I used a small piece of paper folded on itself a couple of times to keep the servo wedged in tightly. I imagine you could use some of those 1x2 bricks with the vertical groove in them to help hide the servo cabling, but I didn't bother since this is only a demonstrator.

800x547.jpg

Here's a better view of the setup without the track in the way. My servos came with a pack of three differently-shaped horns to put on them - I'm using the shortest one available to me (mine was 19.5mm long with six small holes in it and was the only one with one 'arm' on it). I also have not permanently attached it with the screws that also came in the package, mainly for the purposes of testing.

800x648.jpg

Lastly, here's a picture of the support structure I built up to keep everything in place. I also made an LDD file of the structure as well as the slider mechanism and servo holder so that you can build your own! http://bricksafe.com/files/Phoxtane/digital-model-files/servoswitchtrack.lxf

The hard part of this built is not the mechanism, but setting up the servo as well as the Arduino controller. If anyone is interested, I can do a more in-depth post on how these servos work and how to use them, but the basics go something like this:

  1. Attach the servo to the Arduino using the diagram on this page: https://www.arduino.cc/en/Tutorial/Sweep
  2. Test your servo to make sure it's working using the example code on that page (the servo should slowly move back and forth between its endpoints)
  3. Center the servo at 90 degrees - http://www.allbot.eu/build/allbot-arduino/centering-a-servo/ - this puts the servo at a known position for use in our mechanism
  4. Place the small one-arm servo horn onto the servo spline so that it's pointing across the servo body, not away from it. This allows the servo to reach the little pocket we've built and actuate the slider.
  5. This is the tricky part; you have to play around with the Arduino code to calibrate your servo for its switch track. These servos are mass-produced as cheaply as possible, so the actual physical position of the horn at the 0 and 180 degree endpoints will vary somewhat from unit to unit. For my servo, the two positions the servo should move to for a closed and an open switch are about 83 degrees and 113 degrees, respectively. The corner tile should barely touch the point piece when open, and should keep the point piece tight against the outside track piece without the servo struggling or forcing itself out of position.

I made some minor improvements to this code for my demonstrator - the servo doesn't sweep between positions, but jumps between them, so it's faster to actuate. I also have the Arduino disconnecting the servo in between movements so it doesn't 'hum' while waiting to move to the next position. 

General improvements to this model would include building the mechanism out of DBG and black for the servo holder, as well as tidying up the wiring to the servo. The servo horns stand out quite a bit color-wise, but since they're nylon, they could easily be dyed black to match the servo housing, and the silver-colored screws that come with the servo horns could be touched up with some paint or nail polish to turn them black as well.

The only downside to this mechanism is that you can't run a train backwards through the straight part of the switch when it's closed, since the point piece can't move out of the way. Since this is already being controlled by a microcontroller, it wouldn't be difficult at all to add some sort of sensor that would open the switch when a train is approaching it from the wrong side.

As for overall cost, beyond the price for the pieces needed to build this barebones mechanism (I had all of the pieces in my collection): I bought a ten-pack of these servos for $2 apiece, and if you don't already have one, a small Arduino starter kit can be found online for $25. The Arduino Uno has six analog pins, so it can potentially control up to six servos at once. If you're starting out from scratch, the total cost for six motorized switches would end up being around $37 - which is much cheaper than the ~$125 it would take to build this out of genuine Lego parts (one battery box, six M-motors, three IR receivers, three IR remotes), and it doesn't take any PF channels.

Share this post


Link to post
Share on other sites

A very good idea Phoxtane, it works very well, I use this same principle and have used if for about 5 years now and it really does the job :) I would recommend XBee (Series 1) wireless controllers with Teensy 3.2 boards to make sure you don't have too many wires.

Share this post


Link to post
Share on other sites
11 hours ago, JopieK said:

A very good idea Phoxtane, it works very well, I use this same principle and have used if for about 5 years now and it really does the job :) I would recommend XBee (Series 1) wireless controllers with Teensy 3.2 boards to make sure you don't have too many wires.

Wires don't matter that much when you're building everything on MILS - I've got plenty of space underneath to hide wires, and small hills should do the job for the various control boards.

Share this post


Link to post
Share on other sites
13 hours ago, Phoxtane said:

 ...The Arduino Uno has six analog pins, so it can potentially control up to six servos at once. If you're starting out from scratch, the total cost for six motorized switches would end up being around $37 - which is much cheaper than the ~$125 it would take to build this out of genuine Lego parts (one battery box, six M-motors, three IR receivers, three IR remotes), and it doesn't take any PF channels.

Great idea for use with raised tracks.  :thumbup: 

Looking at your pictures, I think you are using one of the digital pin to control the servo motor.  The Arduino servo library allows most Arduino boards to control up to 12 servo motors.  There are 14 digital pins on the UNO if I recall.   It would be good idea to have a separate power supply to supply enough current for that many servo motors. :classic:

 

Share this post


Link to post
Share on other sites
Just now, dr_spock said:

Great idea for use with raised tracks.  :thumbup: 

Looking at your pictures, I think you are using one of the digital pin to control the servo motor.  The Arduino servo library allows most Arduino boards to control up to 12 servo motors.  There are 14 digital pins on the UNO if I recall.   It would be good idea to have a separate power supply to supply enough current for that many servo motors. :classic:

 

Apparently I am - so then you could easily run 10+ switch tracks from the one controller, if you aren't using any sensors. The cost would only be another $8 added on from the four servo motors left over in the previous example. At that point it'd be prudent to use a separate power supply, but I know you can get servo breakout boards that handle that for you.

Share this post


Link to post
Share on other sites

14 digital pins does not mean 14 usable pins for Servo's. Servo's use PWM (pulse width modulation). Only the ~ marked pins on the UNO provide hardware PWM. You could use software PWM but that has it's own disadvantages. I use a dedicated PWM print with extra cap's to provide enough momentary power when a peak current is drawn from a servo. Often you see that board like the UNO will reset themselves when some servo's might operate at almost the same time. A board like the Teensy 3.2 that uses an ARM Cortex M0 µC but still can be programmed using the (easy) Arduino IDE is often a better idea than a big and very limited UNO.

Share this post


Link to post
Share on other sites
6 hours ago, JopieK said:

14 digital pins does not mean 14 usable pins for Servo's. Servo's use PWM (pulse width modulation). Only the ~ marked pins on the UNO provide hardware PWM. You could use software PWM but that has it's own disadvantages. I use a dedicated PWM print with extra cap's to provide enough momentary power when a peak current is drawn from a servo. Often you see that board like the UNO will reset themselves when some servo's might operate at almost the same time. A board like the Teensy 3.2 that uses an ARM Cortex M0 µC but still can be programmed using the (easy) Arduino IDE is often a better idea than a big and very limited UNO.

It's what the library can handle on the Uno - and apparently the Mega can do 48! As for the reset, that's why you'd use a servo shield or breakout board with its own separate power supply. I'd go for a maximum of two driven off the Uno directly, personally.

Share this post


Link to post
Share on other sites
13 hours ago, Phoxtane said:

It's what the library can handle on the Uno - and apparently the Mega can do 48! As for the reset, that's why you'd use a servo shield or breakout board with its own separate power supply. I'd go for a maximum of two driven off the Uno directly, personally.

There is a difference between hardware PWM and software PWM that has nothing to do with a library it has to do with the Atmega328 chip and how it's timers work. I teach embedded systems related stuff in college so I dug a little deeper as I should know for my students.

Share this post


Link to post
Share on other sites
16 hours ago, JopieK said:

There is a difference between hardware PWM and software PWM that has nothing to do with a library it has to do with the Atmega328 chip and how it's timers work. I teach embedded systems related stuff in college so I dug a little deeper as I should know for my students.

I don't know as much as you, since you're teaching on the subject, but it is very possible, apparently: http://electronics.stackexchange.com/questions/108689/how-can-the-arduino-uno-support-up-to-12-servos-if-it-only-has-6-digital-pwm-pin It may not be very efficient but certainly doable!

Share this post


Link to post
Share on other sites
8 hours ago, Phoxtane said:

I don't know as much as you, since you're teaching on the subject, but it is very possible, apparently: http://electronics.stackexchange.com/questions/108689/how-can-the-arduino-uno-support-up-to-12-servos-if-it-only-has-6-digital-pwm-pin It may not be very efficient but certainly doable!

Well it uses software PWM then and not hardware PWM: https://www.arduino.cc/en/Reference/Servo it apparently uses the hardware PWM pins of pin 9 and 10 and then adds some timing magic to support even more servo's. While it theoretically can support so many servo's I can promise you you will run into problems when field-testing, I have seen a lot of our first-grade students struggle with even one ore two servo's (without the external power supply I must say that makes a big difference already)

I use a 4017 multiplexer between the Atmel chip to make things much more reliable. Remember that if the point is set in either a false direction or even faulty one (between straight and bent) you get derailments so it should be as reliable as possible of course.

You can open it in Eagle CAD. Nowadays I always use SMD parts and make ground planes but since I formally only have a software background I learned myself the electronics parts (our students only use 'bought' stuff so they are also not 'bothered' by making PCB's themselves although it is a lot of fun.

The small prints to the right of the PCB are IR beacons, I currently don't use them, but one could use them to send PF signals to a train or let an intelligent train detect the IR led and then e.g. stop.

LEGuanO_servo_v21a.zip

Share this post


Link to post
Share on other sites
13 hours ago, JopieK said:

Well it uses software PWM then and not hardware PWM: https://www.arduino.cc/en/Reference/Servo it apparently uses the hardware PWM pins of pin 9 and 10 and then adds some timing magic to support even more servo's. While it theoretically can support so many servo's I can promise you you will run into problems when field-testing, I have seen a lot of our first-grade students struggle with even one ore two servo's (without the external power supply I must say that makes a big difference already.

Well, I never said it'd be reliable, to be fair. Nice PCB as well. For my purposes I'll probably stick with some sort of servo shield or breakout, but I was planning to do that anyway.

Share this post


Link to post
Share on other sites
9 hours ago, Phoxtane said:

Well, I never said it'd be reliable, to be fair. Nice PCB as well. For my purposes I'll probably stick with some sort of servo shield or breakout, but I was planning to do that anyway.

No you never said indeed ;) But Eurobricks is about sharing ideas and I like your approach as well! Hope others find this also useful. Even without a lot of technical know-how it still is very doable I think!

Share this post


Link to post
Share on other sites

This sort of motor and switching method is pretty much exactly what I have been thinking I want to do. Getting a huge high torque motor to fight the switch lock never seemed like the right way to me, especially since it leaves a huge ugly box on the inside of the switch turn that is likely to foul up longer coaches.

One other really neat thing with this particular motor and switching method - if you are ballasting your track and your baseplates are built up about the height of the MILS standard, you should be able to hide the entire motor underneath the switch itself!!

Edited by Daedalus304

Share this post


Link to post
Share on other sites

But... This is amazing. :P

I have been trying to find a good solution for a year, but the measurements are really wonky, the torque required is high and the bottom of the switches are really fragile. 

Thank you!

Share this post


Link to post
Share on other sites

This has been done before with the "spear Method", using only Lego parts. A Lego spear fits in the little slot in the rail from the side, pushing  the little spring-loaded switch point piece. I have built one with success using the servo motor, controlling it by PF.

Share this post


Link to post
Share on other sites

I realize this post is over 3yrs old however I just got into the lego train hobby over the past 3months.  I'm very interested in this switch solution, cost is right as well as the footprint the servos take up where I'm using stock lego switch tracks I've modified or had to cut to maintain the 8 block gap in a switch yard I've built.

Hoping to take you up on offer for more details, I've already checked out the Arduino website.  I've got a bunch of questions regarding servo's you used as well as how to break out power for multiple switch servos (my layout has at least 20 switches!).

Appreciate any information or thoughts on updates regarding any advancements/changes given the age of this post and ever changing technology.

Share this post


Link to post
Share on other sites
23 hours ago, bn77 said:

Hoping to take you up on offer for more details, I've already checked out the Arduino website.  I've got a bunch of questions regarding servo's you used as well as how to break out power for multiple switch servos (my layout has at least 20 switches!).

Appreciate any information or thoughts on updates regarding any advancements/changes given the age of this post and ever changing technology.

If there were more details they've been lost to time. I've graduated and gotten a job since this post was made.

You're looking for 9-gram servos - for this job, literally any cheap servos will do, since all they have to do is move a little bit and not fight against the airflow on a model airplane wing (their original intended application). In addition to the color improvements I (apparently) suggested in the original post, it may be possible to dye the insulation black on the servo cable so as to get rid of the yellow-red-brown colors.

If you're going to use an Arduino, I would recommend getting some sort of servo breakout board with a separate power supply. Anything more than a few LEDs being powered directly by the microcontroller is likely to cause brownouts and resets, both of which mean your project won't work as intended.

I didn't bring this project any further along because I didn't (and still don't) have a space for a permanent layout. Check back in another three years, I might own my own place with a dedicated Lego room by then.

Were I to do it again today, I'd build up my own custom control board dedicated to controlling the servos and allow for serial communications to the outside world for integration with any other automation I would want to add. I'm not immediately sure how I'd handle the overall architecture, but it'd probably have to be a (relatively) low gauge wire running in a power bus around the layout with each servo tapping power from the bus, while the PWM signals travel to and from the controller directly. This prevents any issue with a high-current device (servo) trying to draw too much power through a tiny wire and yanking the voltage too low by accident.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.