Programming encoder to control Stepper Motor

Hi thanks for clicking on my post!

I'm fairly new to Arduino so I don't have a huge grasp on a lot of the intricate aspects of the system, but when pointed in the right direction I can make magic happen :slight_smile:

So I have a stepper motor driving a weight across a set distance. This distance is to be determined through calculations. What I want to do is to be able to program an encoder to take that calculated distance and convert it into a certain number of steps for the motor to drive the distance.

From the tutorials I've read and watched online I often see people manually controlling encoders by hand or using an optical sensor to read black and white. I'm wondering if there's a simpler way to turn a calculated int value into encoder steps and then into motor steps.

I hope this makes sense. Thank you for your help!

Please decide what you want. If you have a calculated int value, why do you want to convert it into encoder steps?

@DrDiettrich

I'm confused, if I have an int value for my distance can I use the to drive my stepper motor that amount? Do I not need an encoder to connect the two?

The stepper motor moves the weight a constant distance with every step. Convert the int distance value into the required number of steps, using e.g. map().

But I think that your real problem is how to get the int value - from the encoder?

jeremyvtt:
I'm confused, if I have an int value for my distance can I use the to drive my stepper motor that amount? Do I not need an encoder to connect the two?

No. An encoder is a device to tell an Arduino how many degrees a shaft has rotated.

A stepper motor needs a stepper motor driver between the Arduino and the motor. The Arduino sends a pulse to the driver everytime it wants the motor to move one step. If you want the motor to move 237 steps then the Arduino just needs to send 237 pulses one after the other. The speed at which the pulses are produced determines the speed of the motor.

Have a look at this Simple Stepper Code and at the background info in Stepper Motor Basics

...R