Hello Guys,
I am using an arduino uno, an A4988 driver a nema 17 motor, and a potentiometer.
I need the motor spindle to turn a full 360 degrees and depending on the position of the potentiometer, I can position the motor spindle and turn it back and forth.
I have been scouring the internet for days to find a good sketch to work upon.
my driver dir pin is in pin 5 and the step pin in pin 2 (these can be changed anyway.
The pot central terminal is in analogue pin A0.
Could someone guide me to a link where I can find a decent sketch which works?
Thanks in advance.
Perhaps Stepper.h's MotorKnob example:
Or AccelStepper's proportional control:
That tells us nothing about the electrical characteristics of the motor, just its mounting data.
so you need to translate the range of pot values into the # of steps for a complete revolution of the motor. see map()
but don't you also need a mechanism to set the stepper motor to a zero position when the pot is at its zero position? possibly a limit switch
Here is all that NEMA17 tells us about your motor, nothing about voltage, current, torque, or number of steps per revolution, ONLY it's mounting dimensions.
Post a link to the motor's datasheet or, at least, it's brand name and exact part number.
Much more common to have a homing switch to find a reference point, then as long as the stepper motor doesn't miss steps you can move it back and forth between set points as long as you want.
The library you choose will have example sketches, so scour a bit more.
its an SL motor
SL45STH40-1204A
As far as the software goes, the size of stepper motor really does not matter since it's the A4988 driver that the program communicates with.
It can be NEMA 6 or NEMA 42 does not matter.
Guys, Thanks a million as the links you sent are great and keep them coming.
I will definitely go through and find something which will work for my application. I need to buy some L298N's to try them out. I am looking towards running up to six motors individually. It is really a robotic arm I wish to design.
Many thanks again for your feedback and keep it up.
Hi, @mendelevium99
Welcome to the forum.
Forget those drivers, they are dinosaurs and very inefficient.
Stick with the A4988, much better and efficient.
Can you please tell us your electronics, programming, arduino, hardware experience?
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
What is you stepper power supply?
Have you been able to basically get the UNO to run the stepper?
Tom....
![]()
Good afternoon,
I am not an extensive electronic wizard but I have designed many 3d printers and had and run a workshop with over 30 CNC machines with heidenhains, siemens, fanucs and did write all my programs, I have a lot of arduino megas, arduino unos and a lot of surplus drivers like A4988, 8825 and Trinamic drivers and also a lot of surplus Nema 17 motors, 12 and 24 v power supplies. I built machines with the duet wifi stuff as well but I am a bit rusty as I have left this stuff some seven years without touching anything and now retired and have many dream projects to do. Basically I know how to deal with C basic arduino code BUT I never managed to learn to write this language properly. If I get a sketch I can modify it and possibly extend it but I cannot create it on my own from scratch... I can do very complicated circuits, wireing, soldering and can understand electronic components. That is my level of knowledge. programming the arduino is not my strength and that is why I am here ![]()
I am familiar with that... I even had some projects with switchless arrangements. Think they were trinamics. the axis would hit solid and then define the reference point.
Did you try this one:
// 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
//
// Note that the A4988's STEP/DIR pins are connected to two
// separate phases of a 4-wire quadrature signal from the code.
// This works but is 4x slower. It is more effective to use the
// 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
//
// Also, one should always use driver between the Uno and
// the stepper. Something like an L298 or the much more
// efficient TB6612FNC.
//
// ProportionalControl.pde
// -*- mode: C++ -*-
//
// Make a single stepper follow the analog value read from a pot or whatever
// The stepper will move at a constant speed to each newly set posiiton,
// depending on the value of the pot.
//
// 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; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
// 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
void setup()
{
stepper.setMaxSpeed(1000);
}
void loop()
{
// Read new position
int analog_in = analogRead(ANALOG_IN);
stepper.moveTo(analog_in);
stepper.setSpeed(100);
stepper.runSpeedToPosition();
}
Start with that AccelStepper ProportionalControl example, Switch to use the Step/Dir driver per the comment in the header, and do the arithmetic to transform the potentiometer value into a stepper position.
Oh, for 6 motors and 6 potentiometers, it is more complex than the typical 1-function example sketches -- you likely would want to be able to move more than one axis at a time, and also notice changes in the different pots while the motors were moving, IOW: Several Things at the Same Time. Also, you might want to consider handling the steppers and pots as arrays of steppers and pots rather than built up from cut and paste copies of a 1-axis example.
