Stepper motor bidirectional control

Hi Guys

I have been looking at the examples but im too short in knoweldge about this

i need a stepper motor to go along with a pot, for example
pot is mapped to 0, 100
i need the potentiometer to move backwards from 49 to 0 one step per each value, being 48 one step 47 another and so on, and from 50 100 to move forwards step by step.

i have been looking at this and cant figure out a simple code to do so.

#include <Stepper.h>

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

// 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

void loop() {
  // get the sensor value
  int val = analogRead(0);

  // move a number of steps equal to the change in the
  // sensor reading
  stepper.step(val - previous);

  // remember the previous value of the sensor
  previous = val;

thanks in advance

Can you show a picture of the stepper motor and the pot connected together for your test setup?


What kind of electronic stuff do You have in mind? An Arduino of some kind and a stepper driver board?
I have developed some code and my motors are stepping happily in my little CNC machine. I can share my code in order to provide som basic functions.

hi guys

Thanks for helping

I am using a basic driver from the keyes box with a 5v dc 28byj 48 motor and a B500K pot.
this is for testing.

later on i will have to move to a more powerfull motor like a nema and a speed sensor to regulate a air flow blade to airbox
speed sensor is a hall sensor and dependeg its values it will move the motor one way or another

basic driver... What is controlling that driver?

These links may help

Stepper Motor Basics
Simple Stepper Code

You need to keep in mind that a stepper motor does not know where it is - unlike a servo - so you may need a limit switch so your program can move the motor to the HOME or ZERO position at startup.