How to change a common potentiometer to a multiturn potentiometer?

Hello. I'm using a potentiometer type B 10k, to control a nema17 motor of 200 steps (when I turn the potentiometer to the right, the motor turns to the right, when I turn the potentiometer to the left, the motor also turns to the left) next to a device (l298n) that makes the connection between the engine and the arduino. The connections with the motor are correct and the outputs In1, In2, In3 and In4 are connected to ports 11, 10, 9, 8 of the arduino, respectively. My problem is: I recently bought a multiturn potentiometer (10 turns, 10k) and connected it to the circuit, however, instead of each turn of the new potentiometer giving the motor one turn (360 degrees), each turn of the potentiometer is only giving a slight movement in the engine, about 36 degrees. I was told that this should be adjusted in the code, but I couldn't do it anyway.

/*
 * MotorKnob
 *
 * A stepper motor follows the turns of a potentiometer
 * (or other sensor) on analog input 0.
 *
 * http://www.arduino.cc/en/Reference/Stepper
 * This example code is in the public domain.
 */

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 200

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

// the previous reading from the analog input
int previous = 0;

void setup() {
  // set the speed of the motor to 30 RPMs
  stepper.setSpeed(30);
}

void loop() {
  // get the sensor value
  int val = analogRead(0);
  int step = map(val, 0, 1023, 0, STEPS);
  // move a number of steps equal to the change in the
  // sensor reading
  stepper.step(step - previous);

  // remember the previous value of the sensor
  previous = step;
}

Well... Why did you do that? What did you expect?

1 turn of the 10-turn pot is about 1/10th of a turn on a regular pot (except a regular pot doesn't go 360 degrees).

You can change your map() function to increase the sensitivity of the pot, but if you are only using 1/10th of the range, the ADC readings won't have as much usable resolution.

And I'm not really sure what happens when you go beyond the expected map() range so you might have to add some code to deal with that.

And what do you want to do when you go beyond one-turn?

#define STEPS 2000

The solution is simple, purchase a 10 turn pot, they are readily available. A rotary encoder would work as well but you will need to change your code.

I've already tried modifying the map() function several times, but usually the motor doesn't even turn on or start spinning and doing commands by itself

I bought an encoder, I'm waiting for it to arrive :slight_smile:

thank you bro