Everything on model trains, model railroads, model railways, locomotives, model train layouts, scenery, wiring, DCC and more. Enjoy the world's best hobby... model railroading!

Arduino controlled Turntable

 Tony models in OO and writes:

I’m having great problems getting my Arduino code to work. I have the Turntable working but can’t get the code to do what I want when the Hall Sensor is working. As soon as the Hall sensor starts the turntable stops and will not move at all.

Here’s the part I can’t make good:

The final bit is just where the Turntable goes and how long it stops for. 

Thanks for your help in advance.

4 Responses to Arduino controlled Turntable

  • Jim Christenson says:


    It might help if you provided more details as to what is hooked up. What causes pin 2 to change?

    So, assuming that pin 2 changes and you want to move you have two choices. The AccelStepper library has a blocking and a non-blocking call to move the stepper. Here is some code I am using to move a stepper:

    void loop() {
    if (stepper1.distanceToGo() != 0 && digitalRead(2) != HIGH) {
    stepper1.run(); // move the stepper
    } else {
    digitalWrite(13, LOW); // Stopped at limit?

    The key is to call the stepper1.run() until the distance to go is 0.

    The other way to make the stepper to move is to use the blocking call. Note that it will move without stopping, so if an external event (switch, etc) wants to stop movement it won’t…


    I also don’t think you loop is robust enough based on assumptions I am making about how this is triggered. If you power-up and move you might put the stepper1.move(600) in your setup function, otherwise you might want to look for the condition that triggers the move in your loop() and move if it becomes true.

  • Jim Christenson says:


    My last post didn’t look good at all, so I am going to show my actual code. Note that my external switch ‘trigger’ happens in either my client.loop() or ts.execute() method which I don’t show. The main part of the attached code is responsible for moving the stepper.


  • Jim Christenson says:


    This article helped me (remembered after last post…) I want to move a stepper motor to an unknown home position until a switch is triggered, then move it down a little bit and call that position 0.

    See this link: https://www.brainy-bits.com/post/homing-stepper-motors-using-the-accelstepper-library


  • Nigel says:

    I’m not an expert on Arduino but do play around with them and also wanted to use one to control a turntable.

    The following thread on RMWeb is excellent and provides a really good step by step description of the programming process including using a hall effect sensor to calibrate the turntable:


    I’m not knowledgeable enough to comment on the specifics of your code but, hopefully, there’ll be something on the link which solves your problem.

    Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *

Add a photo or image related to your comment (JPEG only)

Use Tiny Railroad Micro Controllers

N Scale Track Plans

Watch Video

Download Your Free Catalog

Model Train DCC HELP


Model Train Help Ebook


FREE Tour Inside Club

Take a FREE tour inside the club.

Scenery Techniques Explained

Scenery & Layout Ideas

Model Railroading Blog Archive

Reader Poll

Sorry, there are no polls available at the moment.