Driving a 12V 28BYJ-48 Stepper With the A4988 Stepstick (in Full-step Mode).

Introduction: Driving a 12V 28BYJ-48 Stepper With the A4988 Stepstick (in Full-step Mode).

Table of Contents:

Step 1: Parts

Step 2: Setting Up the Motor, CNC Shield, and UNO

Step 3: Writing Code and Running the Motor

Full Disclosure: One A4988 stepper driver was destroyed with reverse polarity during the making of this instructable.

Warning! 12VDC being back fed into the UNO from the CNC shield and then from the UNO to your computer could potentially destroy your personal computer. This is why I am unplugging the USB cord from your PC before providing 12VDC to the CNC shield.


  • The 28BYJ-48 is not broken out on it's header connector correctly (ignoring the red wire entirely) to be connected one for one to an A4988 stepstick driver. In short, the pink and yellow wires need to be crossed over.
  • The spec. sheet states that an A4988 needs > 8VDC power supply for your motor, i.e. you may not be able to run a 5VDC power supply for driving 5V 28BYJ-48 motors.
  • You do not need to disconnect the 28BYJ-48 red wire to run it in bipolar stepper mode. I have done it both ways and have seen no difference, although I have no quantitative data to back up this assertion. However, visually, stepwise, and to the touch (heatwise) I have noticed no difference in my limited trial.
  • You need to dial the potentiometer back on the a4988 to restrict it's current flow. I have mine set to 0.10V, this value could be slightly increased to get your motor turning more strongly (0.15V). I have accidentally had the 'pot' set at 0.50-0.60V, although it didn't blow the A4988 or 12V stepper, it is too high. Too high of pot reading could prove dangerous if run for too long at this setting, burning your 28BYJ-48 motor, A4988 stepstick, or place of residence up.

Disclaimer: I am not an electrical engineer and my 'facts' should be taken as such.

  • Not needing to disconnect the 28BYJ-48 red wire to run it in bipolar stepper mode, is my opinion (based on my limited trial), and thus should be taken with a grain of salt. Many, claim that you need to both internally cut the circuit track that connects both poles' common line together, and then to disconnect the red wire entirely.
  • Needing to dial the potentiometer back on the A4988 to restrict it's current flow is definitely a fact. However, having mine set to 0.10V, is merely my opinion. You should consult the datasheets and use their values and formulas to set this value properly. By slowly increasing your potentiometer's voltage, your motor will turn more strongly and truely. I have had to tune my driver to about 0.15V in order to achieve the performance I knew the motor was capable of.

Step 1: The Parts

  • Jumper Wires
  • CNC shield, or similar breakout board or a breadboard plus resistors, capacitor, etc.
  • Arduino Uno, although other microcontrollers/microcomputers could be used
  • A4988 stepstick driver
  • Plastic potentiometer screwdriver, or normal #1 phillips' head srewdriver or similar
  • 3mm flathead or silimar to tighten screw terminals snuggly.
  • Wire strippers
  • Multimeter
  • 12VDC 28BYJ-48 stepper motor
  • 12VDC power supply (at least 1Amp for 2 motors) that plugs into household AC or a 12VDC battery with a disconnect.
  • 16 gauge wires for power supply
  • 5VDC USB power supply
  • PC or microcomputer (to run the Arduino IDE and to flash the program via USB to the UNO).

The difference between a microcontroller and a microcomputer could be easily compared the difference between an Arduino (microcontroller) and a Raspberry Pi (microcomputer). They are both capable of manipulating GPIO pins, and executing a code or program. The difference is that a microcontroller needs it's program/code and/or commands sent to it from an outside source, in order to operate; and in it's operation only executes within it's code base and can at most receive and send basic messages to other devices. The Pi can do many of the things an Arduino can, however the Pi utilises an operating system called Linux; which allows the user to basically have a miniature PC that has it's GPIO pins exposed, like an Arduino does.

We can use either a microcontroller or microcomputer for driving a 12V 28BYJ-48 stepper motor with the A4988 stepstick driver. In the case of the microcomputer (RPi), we will both compose and execute the code within the Linux OS. In the case of the microcontoller (Arduino), we will write the code in an IDE on a pc and then flash the code to the microcontroller; the microcontroller then executes that code.

Step 2: Setting Up the Motor, CNC Shield, and UNO

Above is a somewhat fuzzy picture of the crossover of the pink and yellow lines, notice my orange and red jumper wires cross over each other. Also notice the red is not connected.

  1. Prepare motor to plug into A4988 outputs.
  2. Put CNC shield on top of UNO.
  3. Power the UNO and set potentiometer/s.
  4. Unplug UNO's USB from power supply or computer. Hook 12VDC to the CNC shield to 'proof it'.
  5. Unplug 12VDC power supply from wall. Or if using a 12V battery disconnect it from the CNC shield. Your project is now entirely disconnect from all power source. With niether 5V nor 12V connected to the UNO-CNC sandwich, it can be safely manhandled and stored.

1) Correct Wiring for a 28BYJ-48 stepper for A4988 bipolar mode:

  1. Ignore the red wire. You do not need to disconnect it internally of from the connector.
  2. The pink and yellow wires need to be crossed over.
  3. The correct order of 28BYJ-48 wires pinned for stepstick use is blue, yellow, pink, and then orange; or vice versa.

28BYJ-48 to a4988 connections:

  • Red wire= not connected
  • Orange = 1B
  • Yellow= 2A
  • Pink= 1A
  • Blue= 2B

Basically, the pink and yellow wires need to be crossed over. I have done this by re-wiring with jumpers, by simply crossing the pink and yellow jumper positions with each other when plugging them into their stepstick outputs, I did this because I can still pull these jumpers back out and plug the motor's connector back into the stock ULN2003 unipolar stepper controller. However, the 28BYJ-48's white connector could be rewired instead by popping out and switching the locations of the yellow and pink wires within the motor's connector, permanently mapping it for compatibility with the A4988 driver. This is a matter of opinion, ultimately I needed extra length in my wires so I went for the jumper crossover option.

Remember red is unconnected and yellow and pink are swapped.

2) Correct Assembly of the a CNC shield:

Never step the A4988 without having a stepper hooked to it's outputs, it will likely fry it. For that matter, it may be advisable to not connect to your 12V power supply until your stepper motor are connected securely to each of the four outputs, on each of your A4988s.

  1. I recommend that you don't microstep the 28BYJ-48 stepper, it already contains an internal gear train so microstepping it will be rather silly. Do not install jumpers on the microstepping 2x3 header to achieve full-stepping. Install or don't install your black squarish jumpers correctly to select a microstep setting.
  2. Insert A4988 into the CNC shield, the direction matters. On my version, the side with the potentiometer(pot) gets inserted toward the bottom (side with the motor power supply screw terminals) of the breakout board. Consult the internet or a photo to double check.
  3. Plug a properly pinned out (via crossover cables or re-populating the stepper's header) 28BYJ-48 stepper motor into the 4 outputs on each A4988 you have plugged in. While, being careful to not connect the red wire.
  4. Insert CNC shield onto the UNO making sure that all your pins are aligned properly and that they are going to slide easily into the UNO. CNC shields might have bend pins need to straighten first, you could also inspect for solder bridges while checking pins.

3) Adjusting the a4988 potentiometer:

  1. Plug the UNO's USB cord into the UNO. Then plug the other end into a 5VDC power supply or a computers USB port. It would be safer to use a power supply, than a computer.
  2. Set multi-meter to a mode suitable for reading DC voltages between 0.0 & 1.0 VDC.
  3. Read the potentiometer voltage, by putting the positive red lead on the top the pot (where the screw driver goes), and putting the negative black lead on a negative point, a good large one is the CNC shield's power supply negative (-) screw terminal. You could even clamp your black multimeter lead carefully into the negative screw terminal.
  4. Set this value by turning the pot counterclockwise a little at a time, taking intermittent voltage readings. Turning clockwise to raise the voltage back up if needed. Mine is set to 0.10V, I believe this to be a safe rating, however this is merely my opinion. You should consult the datasheets and use their values and formulas to set this value properly.
  5. If your motor seems to be a little lack lustre performance or power wise, you can slowly increase your potentiometer's voltage. As you this value increases, your motor will turn more strongly and truly. I have tuned my driver to about 0.15V in order to achieve the performance I knew the motor was capable of. The motor's power will no longer increase past a point. I wouldn't recommend values in excess of 0.15V. Excess power = excess heat.

4) Connect 12VDC to the CNC shield:

  1. Disconnect the UNO from 5V. This protects your power supply or computer from being fried if there is a dead short in a poorly/cheaply manufactured CNC shield.
  2. Hook up your 12V power supply to the CNC shield with 16 gauge wire (18 gauge could be used for such small motors), making sure positive wire is going to positive screw terminal and negative to negative. Make sure you don't strip the wire too far back (only about 4-5mm or 1/8" -3/16" for the CNC screw terminal wire ends), if using multi-stranded wires-- twist each end of each wire round and round so they are tightly together (so the ends are less like multi-strand wire and more like a 'solid' core one), and then tighten the correct wires into the correct screw posts. It is important get these ends are tightened and fastened really well within the screw posts, we can give each wire a slight tug to ensure it's solid. Also 16 gauge wire works better than 18 because it has a larger diameter to clamp.
  3. Turn the power on and let it sit for like 30 seconds to a minute. This is 'proofing'/proving whether or not the shield is operable, 'bricked on arrival' or perhaps bricked because our shortcomings. If during this time, if you hear, see or smell something funny-> unplug the shield's 12VDC power, as quickly and safely as possible.

I applied a 12V reverse polarity to to my shield during this step, fried an A4988 and thankfully nothing else. I then simply added a new A4988 and I re-powered it correctly (+ to +, - to -), it seems fine. But, a possibly damaged shield like this should be marked as such (Sharpied note to self), so it doesn't wind up accidentally getting put into service in an end project someday.

Warning! 12VDC being back fed into the UNO from the shield and then from the UNO to your computer could potentially destroy your personal computer. This is why I am unplugging the USB cord before proofing. Accidents can and do happen.

5) Disconnect 12VDC from the CNC shield:

  • To be 100% safe the 12V should be turned off from the CNC shield at this point. Unplug the 12VDC power supply from the AC wall outlet. Or if using a 12V battery disconnect it from the CNC shield; this is done with a positive-side switch that can handle the current or by putting a barrel jack inline or another type of quick connector. It is important that the disconnection occurs in a minimum the positive wire. I am using a battery as my power supply and have an inline barrel jack as a shut off.
  • 12VDC being back fed into the UNO from the shield and then from the UNO to your computer could potentially destroy your personal computer.
  • I am unplugging 12V power now, because we are going to proceed to flash a sketch to the UNO in the next step.
  • With niether 5V nor 12V connected to the UNO-CNC sandwich, it can be safely manhandled and stored.

Step 3: Writing Code and Running the Motor

To be 100% safe the 12V should be turned off from the CNC shield at this point. 12VDC being back fed into the UNO from the shield and then from the UNO to your computer could potentially destroy your personal computer. It could happen... be warned.

I personally use a Raspberry Pi to write my code and then flash it to the UNO. Because of the non-valuable nature of my PC I am willing to have both 12VDC connected and the USB hooked to the computer all at once. I personally have never fried my Pi, but it's cheap nature allows me to gamble a little. I recommend disconnecting 12V before putting the UNO USB into the computer. Better yet, I'd recommend getting a Pi because things are much easier and pleasant if you don't have to worry about destroying an expensive PC.

Note: I'm assuming that you already have basic competency within the Arduino IDE.

  1. Hook UNO to computer via USB.
  2. Start the Arduino IDE.
  3. Write program. I'm assuming your stepper is hooked to the x-axis on the CNC shield. (see below for other UNO to CNC shield pin assignments)
  4. Flash program to UNO.
  5. Check the serial terminal at 9600 baud to ensure the program flashed properly... 'stepping' will be printed very rapidly once per line.
  6. Unplug UNO from computer.
  7. Plug UNO into 5V USB power supply. (Or if using a Pi you could leave it plugged in to the Pi, do this at own risk)
  8. Connect 12VDC to CNC shield.
  9. Watch motor spin.
  10. Unplug the 12VDC when done, because it will still be powering your one pole of your motor even when idle. Plus, you could write good code that disables the A4988 when you are done with it, thus powering your motor down.
void setup() {
  pinMode(2, OUTPUT);//step pin
  pinMode(5, OUTPUT);//direction pin
  pinMode(8, OUTPUT);//enable pin
  //enables a4988 stepper drivers, pin 8, 0=enable, 1=disable
  digitalWrite(8, 0);
  //sets x axis direction
  digitalWrite(5, 0);

void loop() {
  digitalWrite(2, 1);//step signaL ON
  digitalWrite(2, 0);//OFF
  //delay between steps-- 5ms is a common value that works well in full step mode

UNO pins to CNC shield:

  • pin 8= a4988 stepper drivers enable pin
  • pin 2= x-axis step pin
  • pin 3= y-axis step pin
  • pin 4= z-axis step pin
  • pin 5= x-axis direction pin
  • pin 6= y-axis direction pin
  • pin 7= z-axis direction pin

Step 4: Going Further... A4988 on a Breadboard Operated by a Raspberry Pi

First, I'd recommend looking at some other pictures online about the A4988's pinout and/or breadboarding it to supplement my poor pictures

  1. Put A4988 on breadboard.
  2. Write code for Pi.
  3. Watch motor spin.

1) Breadboard an A4988:

  1. Insert the A4899 on a breadboard, ensuring that one of it's 1x8 headers is on one side of the breadboard and the other 1x8 header is on the opposite side.
  2. If left unhooked, the enable pin is floating or pulled to ground-- in either case the A4988 is ready to operate a motor without connecting this pin.
  3. If left unhooked, the ms# pins are floating or pulled to ground-- in either case the A4988 is ready to operate a motor in full-step mode with these pins not connected. You can hook each ms# pin to 5v with a resistor (1k-10k), so you can set the different step modes.
  4. The reset and sleep pins need to be connected with each other. This can be accomplished via a jumper wire.
  5. The motor gets connected to 2B, 2A, 1A, 1B. See Step 2: 1) Correct Wiring for a 28BYJ-48 stepper for A4988 bipolar mode.
  6. Put a capacitor (approximately 100uF) between Vmotor (top right, assuming your A4988 is aligned the same as my diagram). Positive (top right pin) to the positive capacitor leg and the negative or ground (GND) capacitor leg to the negative or ground (GND) pin, it's the next pin down.
  7. Hook the motor's VDC 12V power supply to the Vmotor. Positive (top right pin) to the positive (power supply) and negative to negative. Negative or ground (GND) is the next pin down.
  8. Unhook the 12V power supply, only the positive line really needs disconnected.
  9. Hook the microcontroller to the A4988. I hooked the step pin to gpio18 on the Pi. And I hooked the dir/direction pin to gpio17 on the Pi. Then, hook the 5VDC from the Pi to the A4988, we could use an external 5v power supply to make this step safer. Piositive to positive-- Vmicro (5V) pin (second from the bottom) to microcontroller's/supply's 5v pin, and negative to negative-- GND on micro and supply(if used) to GND (bottom right pin) on the stepper driver.
  10. Set the A4988 potentiometer to limit the current. See Step 2: 3) Adjusting the a4988 potentiometer.
  11. A common ground needs to be present in order for electronics to work; all the negatives must all be connected with one another. i.e. The Pi and motor power supplies are connected by grounds through the A4988 stepstick. If you are using an external 5v power supply obviously connect it's negative to the GND (bottom right pin); however, we must not forget to also tie the Pi's/micro's GND here too.
  12. Finally, we can write some code and run the example. We could achieve this on an Arduino with their IDE. However, I am going to use a Pi to control the A4988 by running a python script.

2) Code for your Pi...

import RPi.GPIO as GPIO
from time import sleep

GPIO.setwarnings(False) #sets gpio to numerical pin assignments... 1-40 GPIO.setmode(GPIO.BOARD) #sets pins as outputs GPIO.setup(11, GPIO.OUT)#(gpio17) GPIO.setup(12, GPIO.OUT)#(gpio18)

#sets direction pin GPIO.output(11, 1)

while True: #step pin GPIO.output(12, 1) GPIO.output(12, 0) sleep(0.004) print("test")

  • Put code in text document or favourite IDE and save it to test.py, or similar. Let's save the file directly on the desktop.
  • Open a fresh terminal and type:cd /home/pi/Desktop/(enter key)
  • Then type:python test.py(enter key)
  • The program will start and wildly print test.
  • Hit Ctrl+C to exit the program, it loops forever
  • Leave terminal open.

3) Run motor

  • Recconnect 12VDC to A4988.
  • Start python script again in terminal:python test.py
  • If all is well, your motor is spinning. If not double check your connections.
  • Hit Ctrl+C to exit the program and stop the motor.
  • Unplug the 12VDC, because it will still be powering your one pole of your motor even when idle.

Warning! 12VDC being back fed into the Pi from the A4899 could potentially destroy your Raspberry Pi. Breadboard this circuit at your own risk. Reverse polarity is the utmost enemy. If you value your Pi use an external 5V supply and be very careful not to feed 12VDC accidentally in to the common ground line. This can fry your Pi. Reverse polarity (connecting positive to negative accidentally) fried a A4988 while hooking up my CNC shield. Beware, of damaging your electronics by proceeding with caution and double check your connects before applying power to a circuit.

Be the First to Share


    • Puzzles Challenge

      Puzzles Challenge
    • Rice & Grains Challenge

      Rice & Grains Challenge
    • CNC and 3D Printing Contest

      CNC and 3D Printing Contest



    3 years ago on Step 4

    Thanks to BasementDriver for this thorough and well-presented guide. Following this, and other resources I spent considerable time trying to make a high-precision system using the A4988 and would like to share my experience so others can decide if their needs will be well satisfied.

    Driving 28BYJ steppers with A4988 may be a quick and dirty way to get something moving coarsely but has some considerable drawbacks if you want to maximize the performance you can get out of these steppers. Instead, driving these steppers with a TMC2130 will get you much better results if you can take on the extra complexity of wiring the SPI ports and setting up the code. Given that the cost of a TMC2130 is not very different than an A4988, I will never ever again use an A4988.

    Following is a confession in my struggles in trying to use 28BYJ + A4988. The A4988 I tried were embedded in a Step Stick (https://www.reprap.org/wiki/StepStick). The 28BYJ were converted to bipolar by cutting the common connection between coils.

    My application required that I created a rotational joint with a significantly accurate (<0.1 degrees) positioning resolution in a small and reasonably priced (<$500) package. The system this was going into had a 12V supply so something that worked with that would be preferred. I did not need absolute positioning, only relative and repeatable stepping.

    I tested several steppers: NEMA 8s were too heavy, X27168 too weak. I converged on 28BYJ-48 because they tested to have the correct torque-to-mass ratio and step resolution, despite having some pretty bad hysteresis (or output backlash) > 0.9 degrees. I would compensate for hysteresis in software. The 28BYJ-48 has 32 steps (raw) per revolution and a gear ratio of 63.68395:1, so 2038 steps per output revolution would give me 0.17 degrees per step. This was not good enough, but with 16x micro-stepping, I would get ~0.01 degrees per micro-step. Sweet!

    I bought some 28BYJ-48 5V version on Amazon knowing that steppers are current devices so by limiting the current of the A4988, and integrated them into my setup. I empirically tuned Vref on the A4988 to the minimum for making the steppers move. This was almost at the minimum Vref and made about 25 mA per coil as expected from 5V through 200 ohms. I proceeded to measure the output precision using an indicator on an arm attached to the stepper shaft, and also by using a laser pointer that hit a mirror mounted on the arm. This is where the surprises started. It turned out that the A4899 was not generating the proper micro-steps at low currents, and it would instead behave as if it was doing full steps. I confirmed this with an oscilloscope on the coil signals. I experimented by giving them more current and discovered that there was a sweet spot over which the A4988 would produce the proper micro-stepping PWM signals and the motor output would indeed micro-step almost as expected.

    It was easy to find the tunning sweet spot for the A4988 by maximizing the horrendous screeching sound the motors would make. I actually think I damaged my hearing working on this. For some reason not apparent in the A4988 datasheet, the proper PWM micro-stepping only kicked in when the driver was tuned to a higher Vref, which produced about 200 mA. At this point, I was getting the mechanical behavior I wanted, but the noise was unbearable and the 5V motors were getting ~10X their design current so they were getting toasty (~80C).

    I then ordered some 28BYJ-48 12V version, thinking this resolve the heating and would allow the A4988 to work in a higher Vref domain solving the micro-stepping and heating problems. More surprises. With these new motors, the current was self-limiting because we are driving them at their design voltage of 12V so the A4988 current threshold had no real effect and could be set to the max. However, there was no point throughout the Vref range that would make the A4988 micro-step. The overheating went away and the noise was lower, but I only got full steps, which were not good enough for me.

    I went back to the 28BYJ-48 5V version, considering I could fix the noise and live with the hot motors. I replaced the R4 resistor in the A4988 StepSticks (from 0 ohms to 5 kOhms) to reduce the "time-off" period and increase the PWM frequencies so that the noise would go away. Note, replacing these 0603 resistors requires considerable abilities with PCB tools and most-likely a microscope. This worked, most of the stepping frequencies were pushed above 20 kHz (some up to 80 kHz) and the ones remaining below 20 kHz measured at about 30 dB which was an acceptable compromise. At this point, I had a not-banshee-screaming system that gave me the angular resolution I needed but got a little hot. Time to assemble everything for closure.

    I integrated the motors into my final setup which was 3D printed with PLA and started testing the accuracy. With hysteresis compensation in my Arduino code I was getting almost-perfect positional repeatability and very decent and smooth micro-stepping. Surprisingly though, after a few minutes, the output position started to slowly creep. This happened even when the position was set to a fixed setpoint. What? It turned out, that the temperature was hot enough to soften the 3D-printed PLA parts and the weight of the arm was enough to cause a slow creeping deformation.

    Positional accuracy: Check. Acceptable noise level: Check. Operating temperature: Fail. The motors were melting my setup. I considered annealing the PLA but that is a pain because it is laborious, slow and creates deformations; all of which kill the rapid-prototyping spirit. PETG deforms similarly to PLA at these temperatures so why bother. I ordered some heat-sinks and glued them to the motors while I 3D printed a new version of my setup, which had melted.

    The heat-sinks reduced the motor temperature to ~60 C, which is still pretty hot and the fan of my power supply was kicking in. After all, I was burning 200mA * 12V * 2 motors ~5W for doing nothing. At this point, what should have been an afternoon (2 days max) project had crept way longer than I will ever admit. I was reluctant to mount the motor into my setup again because they were still hot and could melt it (the shaft temperature may be hotter than the shell I was measuring) and overall there should clearly be a better way than to fight so much against noise and heat. I decided to try driving these steppers with a TMC2130 that I had previously (and painfully) set up for another project.

    I hooked up the 28BYJ-48 12V motors to a system I had with a TMC2130 driver and I immediately confirmed quiet, cool and super smooth output motion with 256 micro-stepping resolution. Yes, it is a bit more involved to wire the SPI of the TMC2130 and you need to integrate the right libraries into your Arduino code, but that labor is so much better invested than fighting against the A4988. Therefore, I hereby bow to never, ever again, use A4988 stepper drivers for anything.

    In summary:
    28BYJ-48 12V + A4988 = A4988 will not produce micro-stepping.
    28BYJ-48 5V + A4988 = No micro-stepping if configured to propper (~25 mA) current.
    28BYJ-48 5V + A4988 = 16x micro-steps at the expense of horrible screeching noise and too-hot-for-comfort motors if tunned correctly in a very narrow band. Noise can be resolved. Instead of heatsinks, switch to TMC2130 drivers
    28BYJ-48 12V + TMC2130 = Silky smooth 265X micro-stepping, cool and quiet.
    28BYJ-48 5V + TMC2130 = Tried it very briefly. There was some noise and heat, but I did not spend more than 5 seconds trying to tune the current.

    Again, if you need some trivial positioning out of your stepper motors, the A4988 may be a simple solution for you. However, as soon as you encounter the first signs of resistance from these drivers, I recommend you burn them and switch to TMC2130 (or similar) and reap the benefits of modern and intelligent stepper drivers.


    Reply 1 year ago

    Rodrigo, i think your post saved me so much time.
    Thank you so much


    2 years ago

    Had similar experience , tried to use this stepper as bipolar for lifting extruder with ramps board and 4988 as external stepper driver to duet wifi board, no luck , after reading the comments, here used built in Duet wifi TMC2660 and at 90 mA i got this motor runing cool and quiet


    Tip 2 years ago

    Best way to run those steppers off a normal driver is to convert them to bipolar by cutting the trace under the blue cap that ties both coils together (usually connected to the red line)
    There are ton's of howto's to do that...just remember these steppers are geared way down...so don't expect high rpm's when using these