I'm using a 28BYJ-48 stepper motor with a ULN2003 driver board. I'm trying to control the motor using an Arduino MEGA. I initially connected the pins on the driver: IN1,2,3,4 to pins of the Arduino: 8,9,10,11 respectively; as was given in a youtube video I referred to(https://www.youtube.com/watch?v=HdqCtAJxhrs). The power for the motor was given from the 5V and GND ports in the Arduino. What happens is that it rotates 180 degrees,and then stops and then goes at random angles and stops. This was the code:

#include <Stepper.h> 

Stepper stepper1(64,8,9,10,11); 
int a=1;

void setup() {

void loop() {
  • Does anything happen? Have you tried any of the stepper example programs, and do they work? How is your stepper connected? A diagram would be helpful. Is the power supply sufficient for this motor? Can you confirm the supply is working? There is a lot more you could provide in your question - or check for yourself and and provide that information - to help us help you.
    – JRobert
    Jul 15, 2019 at 11:38
  • @JRobert so it's supposed to keep rotating at 180 degrees with breaks right, but it just rotates once and stops. I was wondering if the power supply would be a problem because right now it's connected to the Arduino. I'll get a power source tomorrow and try again. IN1,2,3,4 were connected to pins 9,11,10,6.
    – Dan
    Jul 15, 2019 at 12:04
  • @JRobert, I checked out another video and changed the pin configuration. Other details are updated in the question. If you need any other information then just let me know :)
    – Dan
    Jul 15, 2019 at 12:17
  • Most motors need more current than an Arduino pin can supply, so if the stepper driver doesn't power your motors through a separate supply, there is a good chance that is your problem. Arduino pin drivers are supposed to be limited to 20ma nominal, and 40ma absolute max. Trying to draw more than that will likely fail (the device will be under-powered), may damage the pin drivers (by over-heating), and may pull down the Arduino's own supply voltage enough to it to reset (typically cycling itself through startup/attempt to run/reset, ... etc. until you shut it off or something fails).
    – JRobert
    Jul 15, 2019 at 16:22
  • Hey @JRobert!!! I finally got it working!! So what I did was connected the motor to a 5V 0.3A supply. And then I changed the number of steps per revolution to 2038 and used the code on Michael Schoeffler's website (mschoeffler.de/2017/09/23/…). And it finally works!! Thanks for all the help :)
    – Dan
    Jul 16, 2019 at 5:11

1 Answer 1


For those who missed the comments, what I made a mistake in, as @JRobert pointed is that I was suppose to have connected the stepper motor to a separate power supply as the Arduino was not capable of so much resources. I also altered the code as I think I had gotten the steps-per-revolution wrong which is needed in the Stepper function in the Arduino Code. One needs to check this with the datasheet or somewhere online for the respective stepper motor model. The final code that got it working is here. All thanks to @JRobert for helping me figure out the solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.