# Stepper motor easy driver left and right turn code?

**URL:** <https://forum.arduino.cc/t/stepper-motor-easy-driver-left-and-right-turn-code/433162>\
**Category:** General Guidance\
**Created:** [January 24, 2017, 2:25pm UTC](https://forum.arduino.cc/t/stepper-motor-easy-driver-left-and-right-turn-code/433162 "2017-01-24T14:25:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![djgorandj](https://avatars.discourse-cdn.com/v4/letter/d/839c29/32.png) [@djgorandj](https://forum.arduino.cc/u/djgorandj)\
**Post date:** [January 24, 2017, 2:25pm UTC](https://forum.arduino.cc/t/stepper-motor-easy-driver-left-and-right-turn-code/433162/1 "2017-01-24T14:25:34Z")

</div>

Need me for easy stepper driver code for this schematich:

to follow direction of potentiometer left and right side? Please help me, i am find code bt stepper no follow potentiometer, only turn on left isde, or fight.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 24, 2017, 3:07pm UTC](https://forum.arduino.cc/t/stepper-motor-easy-driver-left-and-right-turn-code/433162/2 "2017-01-24T15:07:04Z")

</div>

What have you tried? Can you read from the potentiometer? Can you make the stepper move in one direction? In the other direction? If the potentiometer reading changes value by +1, how many steps do you want to take? If the potentiometer reading changes value by -3, how many steps do you want to take?

---

<div class="post-metadata">

**Author:** ![djgorandj](https://avatars.discourse-cdn.com/v4/letter/d/839c29/32.png) [@djgorandj](https://forum.arduino.cc/u/djgorandj)\
**Post date:** [January 24, 2017, 3:57pm UTC](https://forum.arduino.cc/t/stepper-motor-easy-driver-left-and-right-turn-code/433162/3 "2017-01-24T15:57:27Z")

</div>

A im using this code:

```cpp
#include <Stepper.h>
int current_position = 0;
const char direction_pin = 3;
const char step_pin = 2;
const char pot_pin = 0; //analog input 1
#define Limit01 7  
#define Limit02 8   
void setup()
{
pinMode(Limit01, INPUT);
pinMode(Limit02, INPUT);
pinMode(direction_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(pot_pin, INPUT);
}

void loop()
{
int  readvalue = analogRead(pot_pin);
readvalue = map(readvalue,0,1023,0,1151);
if (readvalue > current_position+20)
{
 step_motor_forward();
 current_position += 1;
}
else if (readvalue < current_position-20)
{
 step_motor_back();
 current_position -= 1;
}
}//end of loop

void step_motor_forward()
{
if (digitalRead(Limit02)) {}  
    
else {
digitalWrite(direction_pin, LOW); // control in one side
digitalWrite(step_pin, HIGH);
digitalWrite(step_pin, LOW);
}
}

void step_motor_back()
{
if (digitalRead(Limit01)) {} 
    
else {
digitalWrite(direction_pin, HIGH); // controll in revers side, no working, only working in one side!
digitalWrite(step_pin, LOW);
digitalWrite(step_pin, HIGH);
}
}

```

This code turn stepper only left side.

```cpp
void step_motor_forward()
{
if (digitalRead(Limit02)) {}  
    
else {
digitalWrite(direction_pin, LOW); // control in one side
digitalWrite(step_pin, HIGH);
digitalWrite(step_pin, LOW);
}
}

void step_motor_back()
{
if (digitalRead(Limit01)) {} 
    
else {
digitalWrite(direction_pin, HIGH); // controll in revers side, no working, only working in one side!
digitalWrite(step_pin, LOW);
digitalWrite(step_pin, HIGH);
}
}

```

I need direction change control by potentiometer, example . When the knob of pot. Turn right motor turn right. And when its left motor turn left . All thath with the same speed of motor or same steps. Some thing like that

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [January 24, 2017, 4:08pm UTC](https://forum.arduino.cc/t/stepper-motor-easy-driver-left-and-right-turn-code/433162/4 "2017-01-24T16:08:45Z")

</div>

These links may be helpful.

[Stepper Motor Basics](http://forum.arduino.cc/index.php?topic=284828.0)  
[Simple Stepper Code](http://forum.arduino.cc/index.php?topic=277692.0)

Are you sure the Easydriver can provide enough current for your motor?

And AFAIK the Easydriver (and BigEasydriver) default to microstepping whereas the Pololu A4988 defaults to single stepping.

...R

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [January 24, 2017, 4:14pm UTC](https://forum.arduino.cc/t/stepper-motor-easy-driver-left-and-right-turn-code/433162/5 "2017-01-24T16:14:03Z")

</div>

> djgorandj:  
> I need direction change control by potentiometer, example . When the knob of pot. Turn right motor turn right. And when its left motor turn left . All thath with the same speed of motor or same steps. Some thing like that

Assuming the potentiometer produces an analogRead() value of 1023 when turned fully then the following will give you direction and speed

```arduino
int potVal;

potVal = analogRead(potPin); // 0 to 1023
potVal = potVal = potVal - 512; // range is now -512 to +511

if (potVal < 0) {
  direction = 1;
}
else {
  direction = 0;
}

```

...R

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 6:06pm UTC](https://forum.arduino.cc/t/stepper-motor-easy-driver-left-and-right-turn-code/433162/6 "2021-05-05T18:06:07Z")

</div>

Closed on May 5, 2021, 6:06pm UTC


