# Calculate the correct current limit for driver A4988

**URL:** <https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927>\
**Category:** Motors, Mechanics, Power and CNC\
**Created:** [October 29, 2021, 10:20pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927 "2021-10-29T22:20:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![acroscene](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@acroscene](https://forum.arduino.cc/u/acroscene)\
**Post date:** [October 29, 2021, 10:20pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/1 "2021-10-29T22:20:41Z")

</div>

Im using the driver [A4988](https://www.pololu.com/product/1182) together with stepper 28byj-48. Ive read somewhere that the correct current limit on 28byj-48 is somewhere between 0.1-0.15 v. However if I feed it with 12 v there is a high frequence noise that wont go away untill I turn my powersupply down to around 9 v. However if I adjust the current limit to around 0.2 v the noise goes away. I wounder it this is to high value for my stepper. How do I know?

How can I calculate the correct value on the current limit?

Here is the specs for 28byj-48:

```
Voltage 5V
Current 0.26A

```

Do I need different current limits depending on how much voltage I feed to the driver? On 9 v the stepper sometimes fails to hold its position on high speed.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [October 29, 2021, 10:29pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/2 "2021-10-29T22:29:56Z")

</div>

I have never used the 28byj-48 stepper motors with the A4988, but have used the A4988 with several NEMA17 motors.

To properly set the coil current on the A4988 drivers **you first must know the value of the sense resistors** on the board to insert into the formula Vref = 8 \* Imax \* Rcs where Vref is the desired reference voltage to set, Imax is the coil current and Rcs is the value of one current sense resistor.  
The current sense resistors can be 0.05Ω, 0.068Ω (Pololu) or 0.100Ω (chinse) or ??, you need to **look at what you have**. The [Pololu page on the A4988](https://www.pololu.com/product/1182) explains how to locate the sense resistors and a detailed procedure for setting the current limits.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [October 30, 2021, 12:28am UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/3 "2021-10-30T00:28:09Z")

</div>

> [@acroscene](#):
>
> the noise goes away.

The noise is is coming from the motor windings and is a sign that the motor driver is actively limiting the current, and working as expected.

If it bothers you, don't use a current limiting stepper driver. There is no need to do so with that high impedance motor.

---

<div class="post-metadata">

**Author:** ![MicroBahner](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/microbahner/32/238923_2.png) [@MicroBahner](https://forum.arduino.cc/u/MicroBahner)\
**Post date:** [October 30, 2021, 7:02am UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/4 "2021-10-30T07:02:29Z")

</div>

> [@acroscene](#):
>
> Im using the driver [A4988](https://www.pololu.com/product/1182) together with stepper 28byj-48.

How did you connect the motor to the driver? Out of the box the 28byj-48 cannot be connected correctly to an A4988 as it is a 5 wire unipolar stepper with a common Vin for all coils. The A4988 needs a 4 wire bipolar stepper.

---

<div class="post-metadata">

**Author:** ![acroscene](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@acroscene](https://forum.arduino.cc/u/acroscene)\
**Post date:** [October 30, 2021, 3:01pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/5 "2021-10-30T15:01:46Z")

</div>

thanks. interesting. What is the alternatives? I have modified my 28byj-48 into bipolar stepper.

---

<div class="post-metadata">

**Author:** ![acroscene](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@acroscene](https://forum.arduino.cc/u/acroscene)\
**Post date:** [October 30, 2021, 3:02pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/6 "2021-10-30T15:02:24Z")

</div>

yes I know. It is modified into a bipolar stepper and works well together with a4988

---

<div class="post-metadata">

**Author:** ![MicroBahner](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/microbahner/32/238923_2.png) [@MicroBahner](https://forum.arduino.cc/u/MicroBahner)\
**Post date:** [October 30, 2021, 3:41pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/7 "2021-10-30T15:41:05Z")

</div>

> [@acroscene](#):
>
> What is the alternatives?

You can use the ULN driver that is normally supplied with these steppers. Why do you want to drive it with a current driver?

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [October 30, 2021, 3:57pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/8 "2021-10-30T15:57:08Z")

</div>

> [@acroscene](#):
>
> What is the alternatives?

For the modified 28-BYJ, any H-bridge motor driver chip like L293 or L298. They are inefficient but don't do current limiting, which causes the noise.

---

<div class="post-metadata">

**Author:** ![acroscene](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@acroscene](https://forum.arduino.cc/u/acroscene)\
**Post date:** [October 30, 2021, 4:57pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/9 "2021-10-30T16:57:40Z")

</div>

Since I need to save pins 🙂 2 pins instead of 4

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [October 30, 2021, 5:13pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/10 "2021-10-30T17:13:41Z")

</div>

The [Stepper library reference](https://www.arduino.cc/en/Reference/StepperBipolarCircuit) shows how to use a L293 with 2 pins to drive a bipolar motor.

Also a [2 wire circuit for a unipolar motor](https://www.arduino.cc/en/Reference/StepperUnipolarCircuit) with a ULN2003 or ULN2004.

---

<div class="post-metadata">

**Author:** ![acroscene](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@acroscene](https://forum.arduino.cc/u/acroscene)\
**Post date:** [October 30, 2021, 8:00pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/11 "2021-10-30T20:00:01Z")

</div>

Ok. In what way are they inefficient? The most importen for me is that they are not producing noise and that I can drive a stepper with two pins instead of four. I cannot find any decent instruction telling me how to drive my stepper with L293 with only two pins from arduino. Is it possible? On a4988 im using step and dir. Can I use L293 in a similliar way?

---

<div class="post-metadata">

**Author:** ![acroscene](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@acroscene](https://forum.arduino.cc/u/acroscene)\
**Post date:** [October 30, 2021, 8:12pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/12 "2021-10-30T20:12:23Z")

</div>

Interesting. However I cant find anyone how documented that they actually succeded to drive the stepper with just two pins. Only with four pins like [here](https://lastminuteengineers.com/stepper-motor-l293d-arduino-tutorial/)

---

<div class="post-metadata">

**Author:** ![acroscene](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@acroscene](https://forum.arduino.cc/u/acroscene)\
**Post date:** [October 30, 2021, 8:20pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/13 "2021-10-30T20:20:29Z")

</div>

Any other suggestions that lets me drive a bipolar stepper (like the modded 28byj-48) with just two pins?

---

<div class="post-metadata">

**Author:** ![MicroBahner](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/microbahner/32/238923_2.png) [@MicroBahner](https://forum.arduino.cc/u/MicroBahner)\
**Post date:** [October 30, 2021, 8:42pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/14 "2021-10-30T20:42:20Z")

</div>

> [@acroscene](#):
>
> Any other suggestions

What's the problem with the links from @groundFungus ?  
If you drive the stepper in full step and use 4 pins, then there are two pairs where one pin is always the inverted one of the other. You don't need an extra pin on the Arduino for that, you can do that with an inverter. And this is what can be seen in the links from @groundFungus.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [October 30, 2021, 8:55pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/15 "2021-10-30T20:55:15Z")

</div>

> [@acroscene](#):
>
> In what way are they inefficient?

The driver typically has a voltage drop of 2 to 4V and wastes a significant fraction of the supplied power as heat.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [October 30, 2021, 11:37pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/16 "2021-10-30T23:37:24Z")

</div>

Hi,  
This VERY basic circuit of the 293 may help.  
When conducting current it has to flow through 2 **BJTs**.  
They each drop a minimum of 1V across their Collector -Emitter, this is lost power.  
 ![l293d-clock-wise-direction-current-flow_orig](https://europe1.discourse-cdn.com/arduino/original/4X/1/e/f/1efb05a35f1597b5fc6e03cc8225b66c7d76b6ad.png)

Tom... 😀 👍 ☕ 🇦🇺  
Source;

> **[L293 and L293D h bridge motor driver Ic Pin out and Working](https://www.engineersgarage.com/l293d-pin-description-and-working/)**
>
> When ever you want to drive heavy loads with a small TTL signal you use a transistor, bjt or a mosfet. In case the circuit becomes complex and you need to drive load with two, three or four TTL signals you use a combination of transistors...

---

<div class="post-metadata">

**Author:** ![acroscene](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@acroscene](https://forum.arduino.cc/u/acroscene)\
**Post date:** [November 4, 2021, 11:42am UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/17 "2021-11-04T11:42:22Z")

</div>

I have now made the [circuit](https://www.arduino.cc/en/Reference/StepperUnipolarCircuit) @groundFungus suggested. I works fine running ULN2003 with only two pins.

The noise is gone when it is idle but the motor gets very hot!

However I have some problems with the changing of direction which is not relieable and only works 3 times out of 5. Any suggestions to improve the code?

And is it possible to run it with some library?

here is my code:

```cpp
const int coilA = 2;
const int coilB = 3;
const int ms = 500;
int inc = 0;
bool changeDir = false;

void setup() {
  Serial.begin(9600);

  pinMode(coilA, OUTPUT);
  pinMode(coilB, OUTPUT);
  digitalWrite(coilA, LOW);
  digitalWrite(coilB, LOW);
}

void loop() {
  if (inc % 500 == 0) {
    changeDir = !changeDir;
    delay(100);
  }
  if (changeDir == 1) {
    cw();
  } else if (changeDir == 0) {
    ccw();
  }
  inc++;
}

void cw() {
  step1();
  step2();
  step3();
  step4();
}

void ccw() {
  step1b();
  step2b();
  step3b();
  step4b();
}

void step1b () {
  digitalWrite(coilB, LOW);
  delayMicroseconds(ms);
  digitalWrite(coilA, HIGH);
  delayMicroseconds(ms);
}

void step2b () {
  digitalWrite(coilB, HIGH);
  delayMicroseconds(ms);
  digitalWrite(coilA, HIGH);
  delayMicroseconds(ms);
}

void step3b () {
  digitalWrite(coilB, LOW);
  delayMicroseconds(ms);
  digitalWrite(coilA, HIGH);
  delayMicroseconds(ms);
}

void step4b () {
  digitalWrite(coilB, LOW);
  delayMicroseconds(ms);
  digitalWrite(coilA, LOW);
  delayMicroseconds(ms);
}

void step1 () {
  digitalWrite(coilA, LOW);
  delayMicroseconds(ms);
  digitalWrite(coilB, HIGH);
  delayMicroseconds(ms);
}

void step2 () {
  digitalWrite(coilA, HIGH);
  delayMicroseconds(ms);
  digitalWrite(coilB, HIGH);
  delayMicroseconds(ms);
}

void step3 () {
  digitalWrite(coilA, HIGH);
  delayMicroseconds(ms);
  digitalWrite(coilB, LOW);
  delayMicroseconds(ms);
}

void step4 () {
  digitalWrite(coilA, LOW);
  delayMicroseconds(ms);
  digitalWrite(coilB, LOW);
  delayMicroseconds(ms);
}

```

---

<div class="post-metadata">

**Author:** ![MicroBahner](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/microbahner/32/238923_2.png) [@MicroBahner](https://forum.arduino.cc/u/MicroBahner)\
**Post date:** [November 4, 2021, 12:46pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/18 "2021-11-04T12:46:24Z")

</div>

> [@acroscene](#):
>
> Any suggestions to improve the code?

Your stepping is not correct. coilA and coilB should be driven like this:  
00 -\> stepdelay -\> 01 -\> stepdelay -\> 11 -\> stepdelay -\> 10 -\> stepdelay -\> 00 ...  
To change the direction of rotation, the coils must be driven in reverse order.

> [@acroscene](#):
>
> but the motor gets very hot!

Which voltage do you apply to the coils? With the ULN driver this must not be more than 5..6 Volt.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [November 4, 2021, 1:04pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/19 "2021-11-04T13:04:29Z")

</div>

The circuits came from the reference for the Stepper library.

---

<div class="post-metadata">

**Author:** ![acroscene](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@acroscene](https://forum.arduino.cc/u/acroscene)\
**Post date:** [November 4, 2021, 2:37pm UTC](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927/20 "2021-11-04T14:37:48Z")

</div>

Do you mean like this? In that case it wont work for me. It doesnt run at all. Just idle

```cpp
const int coilA = 2;
const int coilB = 3;
const int ms = 800;
int inc = 0;
bool changeDir = false;

void setup() {
  Serial.begin(9600);

  pinMode(coilA, OUTPUT);
  pinMode(coilB, OUTPUT);
  digitalWrite(coilA, LOW);
  digitalWrite(coilB, LOW);
}

void loop() {
  if (inc % 500 == 0) {
    changeDir = !changeDir;
    delay(100);
  }
  if (changeDir == 1) {
    cw();
  } else if (changeDir == 0) {
    ccw();
  }
  inc++;
}

void cw() {
  step1();
  delayMicroseconds(ms);
  step2();
  delayMicroseconds(ms);
  step3();
  delayMicroseconds(ms);
  step4();
  delayMicroseconds(ms);
}

void ccw() {
  step4();
  delayMicroseconds(ms);
  step3();
  delayMicroseconds(ms);
  step2();
  delayMicroseconds(ms);
  step1();
  delayMicroseconds(ms);
}

void step1 () {
  digitalWrite(coilA, LOW);
  digitalWrite(coilB, HIGH);
}

void step2 () {
  digitalWrite(coilA, HIGH);
  digitalWrite(coilB, HIGH);
}

void step3 () {
  digitalWrite(coilA, HIGH);
  digitalWrite(coilB, LOW);
}

void step4 () {
  digitalWrite(coilA, LOW);
  digitalWrite(coilB, LOW);
}

```

This do work bot direction is still not reliable:

```cpp
const int coilA = 2;
const int coilB = 3;
const int ms = 800;
int inc = 0;
bool changeDir = false;

void setup() {
  Serial.begin(9600);

  pinMode(coilA, OUTPUT);
  pinMode(coilB, OUTPUT);
  digitalWrite(coilA, LOW);
  digitalWrite(coilB, LOW);
}

void loop() {
  if (inc % 500 == 0) {
    changeDir = !changeDir;
    delay(100);
  }
  if (changeDir == 1) {
    cw();
  } else if (changeDir == 0) {
    ccw();
  }
  inc++;
}

void cw() {
  step1();
  step2();
  step3();
  step4();
}

void ccw() {
  step4();
  step3();
  step2();
  step1();
}

void step1 () {
  digitalWrite(coilA, LOW);
  delayMicroseconds(ms);
  digitalWrite(coilB, HIGH);
  delayMicroseconds(ms);
}

void step2 () {
  digitalWrite(coilA, HIGH);
  delayMicroseconds(ms);
  digitalWrite(coilB, HIGH);
  delayMicroseconds(ms);
}

void step3 () {
  digitalWrite(coilA, HIGH);
  delayMicroseconds(ms);
  digitalWrite(coilB, LOW);
  delayMicroseconds(ms);
}

void step4 () {
  digitalWrite(coilA, LOW);
  delayMicroseconds(ms);
  digitalWrite(coilB, LOW);
  delayMicroseconds(ms);
}

```

[Next page](https://forum.arduino.cc/t/calculate-the-correct-current-limit-for-driver-a4988/919927.md?page=2)
