Need some help with programming Arduino to handle turnout control

trainplayern8 Mar 21, 2016

  1. trainplayern8

    trainplayern8 TrainBoard Member

    So I've been working on my new layout (DC layout, not DCC) for a while now and just got the idea that I'd like to try and make switching turnouts a bit more "automated". I have 8 manual turnouts on my layout in the rail yard.

    I've watched some videos, tried copying some programming and tried some programming myself and have still not been able to figure it out.

    I'm using an Arduino Mega, 2 breadboards, 8 digital buttons and 8 Tower Pro SG9 servo's. They are all externally powered, but that's not the problem I'm coming up against.

    This is what I want to be able to have it do. I want to be able to push a button correlating with each turnout individually. When I push the button once, it should switch to the other position. When I push the button again, it should switch back to the original position.

    With some of the codes I've seen and used from the net, I can get all of them to swing independently, but once they're at the target position, they swing right back to the original position once I release the button.

    Can anyone assist or is this a hopeless project?
    Last edited: Mar 21, 2016
  2. Xmtrman

    Xmtrman TrainBoard Member

    No, not at all hopeless.

    I have Arduino Unos swinging 8 servos each with dual LED indication for each turnout.
    I use an 8 channel touch sensor board to switch but push buttons could be substituted at the expense of the LED.

    A Mega has more than enough pins to run 8 servos with LEDs and push buttons.

    Let me see what you've got and I'll see where the problem lies.

    Let's go off list - send your code to xmtrman at Gmail dot com.
    papahnash likes this.
  3. rva1945

    rva1945 TrainBoard Member

    Instead of using push buttons, you should use switches, they hold their position.
    if you use a push button, instead of commanding the servo according to the push button value, or, better saying, state of the Arduino pin connected to that push button, you should change the value of a variable with each pressing of the button, toggling between false and true, for example, and then decide with angle corresponds to false of true of that variable.
    I use switches in my layout.

Share This Page