Turntable control with push buttons

Backround of my project:

This is for a turntable for a model train. My plan is to home the turntable using a hall sensor at start up. After that, use normally open momentary push buttons to move turntable to desired position. Also have the ability to re-home the turntable if steps are lost.

The example below is for a single push button to re-home when desired and another to move to a desired position. In the future there will be more position push buttons. I figure this will be additional code similar to the first position.

My set up is an Arduino Mega, a generic A4988 driver, a NEMA 17 motor with a 27:1 gear box, a hall sensor and normally open momentary push buttons.
The A4988 and motor are wired as required.
The hall sensor is wired to 5V, ground and signal pin to Mega
The push buttons are wired to ground and Mega without resistors.

My issues are these:

The turntable will home on start up as expected except that after the sensor is detected, the turntable will slightly accelerate and then decelerate to a stop. I would like the turntable to stop immediately when the hall sensor is detected, if possible, to set this as the zero position.

Next, none of my push buttons have any effect in causing the turntable to move to a desired position or to re-home. I would like to accomplish the moves to a position with accel/decel. The home loop without.

I have cobbled together a program by pulling bits and pieces from examples I could find online. My understanding of using this library is practically nil.

Any advice and input would be greatly appreciated.

Thanks

Rod

[code]

#include <AccelStepper.h>
#include <MultiStepper.h>

#define dirPin 2
#define stepPin 3
#define homingbuttonPin 42
#define hall_sensorPin  40 //hall sensor
#define entry_trackPin    44 //LOW = go to entry track

AccelStepper TT_stepper(AccelStepper::DRIVER, 3, 2); //create stepper object

void find_zero() {                               //homing program
  TT_stepper.setMaxSpeed(400.0);                 //sets max speed of turntable during homing
  TT_stepper.setSpeed(200.0);                    //sets speed of turntable during homing
  while (digitalRead(hall_sensorPin) == HIGH) {  //moves turntable until hall sensor is detected
    TT_stepper.runSpeed();                       //starts the turntable moving
  }

  TT_stepper.setCurrentPosition(0);              //sets the 0 position after homing

}


void setup() {
  // put your setup code here, to run once:
  pinMode(homingbuttonPin, INPUT_PULLUP);
  pinMode(hall_sensorPin, INPUT);
  pinMode(entry_trackPin, INPUT_PULLUP);
  find_zero();                               //runs homing program on start up

  TT_stepper.setCurrentPosition(0);         //sets the current position after homing to 0
  TT_stepper.setMaxSpeed(800.0);            //sets max speed of turntable
  TT_stepper.setAcceleration(100.00);       //sets accel/decel of turntable

}

void loop() {
  // put your main code here, to run repeatedly:

  if (homingbuttonPin == (LOW)) {             //homes the turntable when button is pressed
    find_zero();                              //runs homing program
  }


  if (entry_trackPin == (LOW)); {             //move turntable to entry track position when button is presseed
    TT_stepper.moveTo(500);                   //steps to move to position
    TT_stepper.runToPosition();               //starts turntable moving to desired position

  }

}

[/code]

#define homingbuttonPin 42
. . .
if (homingbuttonPin == (LOW)) { // <———<<<< you need to use digitalRead() to get the status of the pin
find_zero();
}


#define entry_trackPin 44
. . .
if (entry_trackPin == (LOW)); // <———<<<< as above


Suggest you master the examples in the IDE before you go any further.

When you get to it, pay attention to the ‘State Change Detection’ example.

BTW

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components. Posting images:

Many HESs have NPN open collector outputs and need pullup, does yours?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.