# Arduino and stepper motor

How arduino stepper library handles stepper motor with ULN2003? I mean, for controlling stepper motor one actually needs four pwms. It can be reduced to two by encoding, or maybe even to one by using other techniques. But could you, please, clarify how arduino does it? I could not find the low level code for that from arduino to inspect.

Thanks

• why do you believe that you require PWM signal to control a stepping motor? Feb 20 '20 at 16:26
• For not blocking the main code. Like PWM with DC motor. Feb 21 '20 at 11:06

There is generally a stepper example in the arduino Compiler, you can find the code there, or look at the stepper library

However arduinos can‘t control steppers directly, but they send signals to stepper drivers, which then send the correct voltages to the stepper to rotate in a specific direction and rotate at a specific frequency.

Arduinos are basically ‚bit banging‘ namely they send a single high and low signal at a specific frequency and duty cycle, which determines the rotational speed of the motor itself. One line is high/low for direction, another for the signal. The advantage is you can count how many times you bit banged, and have an open loop position control system for easy NC applications

No-one would use the analog pins on an arduino to control stepper motors.

4wire stepper motors have A and B coils that require specific timing to excite (read, step) the motor and a large amperage/voltage requirement. Hence the drivers.

• I mean 28BYJ-48 motor. Can't we control speed? I mean stepper motor rotates with certain speed. And at each sampling time we just change its speed, not give step commands. Feb 21 '20 at 10:48
• Speed is a function of steps. $\omega=2 \pi f$ Feb 21 '20 at 10:50
• Yes, but when you give certain number of steps it is gonna stop after doing that. But we want it to rotate continuously until we change speed. Feb 21 '20 at 10:57
• Like PWM, it gives same duty cycle until you change it, Feb 21 '20 at 10:57
• So you’ve have to write a function that continuously bit bangs that allows you change freq at will. You’ll have to do some math ;) Feb 21 '20 at 10:59

Here is Arduino library code specifically for the 28BYJ-48 stepper motor using the ULN2003 controller board. The readme discusses the various driver modes and how they work. It's not done with PWM like a servo motor (where PWM is a repeating square wave control signal). Rather it is done by energizing the coils in the motor such that they attract to magnets. Energizing in a specific pattern will move the motor from magnet to magnet, thus turning the spindle.

There is an example sketch for implementing a differential drive robot using two 28BYJ-48 stepper motors. There is an example sketch that uses a LM393 optical encoder to calculate the steps per rotation of the stepper motor.