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;
}