Int buttonState, speedVar, counter, startTime, endTime, x, delayInMillis For example, if I separate the encoder from the motor and rotate it quickly, the motor almost stops for a while, and then runs again.ĭo you have any idea for how to solve this problem? I adjust the speed with a potentiometer and print the speed in rpm.Įverything works, except that the motor doesn't rotate smoothly when also the encoder is rotating. Then I can position the motor and the encoder connected to it to a certain position, click the button to set the zero angle of the encoder and then the motor starts rotating. My components are: stepper motor NEMA 17, controller A4988, rotary encoder with 600 pulses/rev, arduino mega.Īt the beginning of the code the motor doesn't rotate. the motor doesn't rotate fluently but brakes and accelerates if the encoder is rotated.įirst I set the zero angle of a rotary encoder, and then I rotate the motor connected to the encoder and I acquire the angle and print the rpm. I have a problem when an encoder is connected to the Mega board together with a stepper motor.