2
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ why do you believe that you require PWM signal to control a stepping motor? $\endgroup$
    – jsotola
    Commented Feb 20, 2020 at 16:26
  • $\begingroup$ For not blocking the main code. Like PWM with DC motor. $\endgroup$
    – Pasha
    Commented Feb 21, 2020 at 11:06

2 Answers 2

1
$\begingroup$

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.

Considering read the wiki about steppers to get a better idea about them.

$\endgroup$
11
  • $\begingroup$ 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. $\endgroup$
    – Pasha
    Commented Feb 21, 2020 at 10:48
  • $\begingroup$ Speed is a function of steps. $\omega=2 \pi f$ $\endgroup$ Commented Feb 21, 2020 at 10:50
  • $\begingroup$ 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. $\endgroup$
    – Pasha
    Commented Feb 21, 2020 at 10:57
  • $\begingroup$ Like PWM, it gives same duty cycle until you change it, $\endgroup$
    – Pasha
    Commented Feb 21, 2020 at 10:57
  • $\begingroup$ 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 ;) $\endgroup$ Commented Feb 21, 2020 at 10:59
1
$\begingroup$

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.

$\endgroup$

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.