Controlling the speed and direction of rotation of a large stepper using a single potentiometer

This simulation doesn't do a deadband, but it does proportional +/- speed control or proportional position control, built from an AccelStepper example:

// https://wokwi.com/projects/428502497518500865
//
// modified to use a driver.  Based on:
// https://wokwi.com/projects/410058296261374977
// Code from https://www.airspayce.com/mikem/arduino/AccelStepper/ProportionalControl_8pde-example.html
// Other example simulations https://forum.arduino.cc/t/wokwi-simulations-for-arduino-built-in-examples/1304754
// See also  https://wokwi.com/projects/408621270297541633 with acceleration
//
// Driver example
//
//  AccelStepper::DRIVER initialization parameter like:
//     AccelStepper stepper(AccelStepper::DRIVER,4,3);
//  This simulation shares both wirings so the code
//  distributed with AccelStepper works as-is
//
//
// ProportionalControlV2.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move with acceleration to each newly set posiiton,
// depending on the value of the pot, or in Speed mode, move CW or CCW at
// variable speed, 
//
// Copyright (C) 2012 Mike McCauley
// $Id: ProportionalControl.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper::DRIVER, 4, 3);

// This defines the analog input pin for reading the control voltage
// Tested with a 10k linear pot between 5v and GND
#define ANALOG_IN A0
#define MODE_PIN A1

void setup()
{
  stepper.setMaxSpeed(1000); // steps/sec
  stepper.setAcceleration(100); // steps/sec/sec
  pinMode(MODE_PIN, INPUT_PULLUP);
}

void loop()
{
  if (digitalRead(MODE_PIN) == HIGH) { // Position mode
    // Read new position
    int analog_in = analogRead(ANALOG_IN);
    //stepper.setSpeed(100);
    stepper.moveTo(analog_in);
    stepper.run();
  } else {
    int analog_in = analogRead(ANALOG_IN);
    //stepper.moveTo(analog_in);
    stepper.setSpeed(map(analog_in, 0, 1023, -100, 100));
    stepper.runSpeed();
  }
}

Other Wokwi simulation examples in this thread:

Many thanks Dave. That looks like a good solution. Would adding a NC switch to either the 5V 0r the GND lines to the pot stop it dead when opened?

I once had and used a large mill/drill with a DC motor to turn the lead screw. It had a clutch lever that would immediately stop the screw turning. Did not have to wait for the motor to stop. You will eventually see the need for something like that on your machine.

1 Like

No. In speed mode, breaking the 5V or 0V circuit to the pot would let the other two terminals go to whatever the still-connected terminal was, and drive full speed.

For emergency stop, you should break the power to the driver.

Or for a regular stop. add a button/switch and do it in code.

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