Optical encoder too output moter adafruit motor sheld help

I don't understand why you would need an encoder with the device in your photo. You would need at least one limit switch so the Arduino could establish the HOME or ZERO position but once that is established it should be possible to keep track of the position very accurately by keeping track of the motor steps.


I have three off these units that all need to follow a DC motor with a optical encoder attached yes there is a lot you can do with proximity sensors or reed switches but it does not suit my purpose . It is a experiment that I don't fully want to disclose it is not for 3D printing or DTG stuff or cnc machines it is of my own creation and needs too follow a optical encoder obviously the Adifruit motor shield is not good enough or anyone with enough experience to make this work. It is not the end of the world as there are other ways just not what my original vision was but that's life

Hi I'm confused.

  • You have a DC motor that turns.
  • You want to have an encoder on the shaft of the DC motor.
  • You want the encoder signal to, via controller, drive the stepper that moves the platform.
  • The movement of the stepper will be in sync with the DC motor.

What speed will the DC motor be doing?

Tom.... :)

1.I have a existing DC motor on a shaft with encoder wheel and optical sensor has its own controller. 2. I want to use the counters from optical sensor to control a motor that mimics the dc motor 3.I wanted to have the adifruit motor shield v2 to control the motors via m1 to m4 outputs 4. too keep it simple I just needed help to get one stepper to work via motor shield following the steps the optical encoder counts 5. I eventually would like to stack the motor shields 6 high controlling 11 steppers but if i cant get just one to mimic the encoder/DC motor there will be no point going further with it.

Hold on a moment, now. Most the earlier discussion in this Thread has been about stepper motors and it is clearly a stepper motor in the picture in Reply #19.

How have DC motors come into the discussion?

Are you saying that the optical encoder is detecting the rotation of a DC motor and the data is being used to control stepper motors?

It would make it so much easier to offer useful advice if we know what you are really trying to do.

How many encoder steps per second need to be detected?


What is driving the encoder wheel makes no difference at all if it was a DC motor a stepper motor a monkey riding a bike turning wheel attached to a encoder like I have constantly said I want to mimic the encoder wheel to control a stepper forwards backwards speed what ever it does obviously it's not just the Arduino and motor shield that can not compute quick enough

ok after a lot of playing i have got the basic concept to actually work using the Adifuit Motor shield
If anyone interested this is the basic code

// Madmax/Mydakota Motor Shield Mod to Follow encoder

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

    int state, prevstate = 500, count = 500;
    int nextEncoderState[4] = { 2, 0, 3, 1 };
    int prevEncoderState[4] = { 1, 3, 0, 2 };

    // Number of steps per turn of encoder
    int forward=1;
    int backward=1;

    //Used to calculate direction
    int direct=0;

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
    // Connect a stepper motor 
    // to motor port #1 #2 (M3 and M4)
    Adafruit_StepperMotor *myMotor = AFMS.getStepper(48, 1);

    void setup() {

      pinMode(10, INPUT);
      pinMode(2, INPUT);
      pinMode(9, OUTPUT);
      digitalWrite(9, LOW);
      digitalWrite(2, HIGH);
      digitalWrite(10, HIGH);


    void loop() {
       state = (digitalRead(10) << 1) | digitalRead(2);
      if (state != prevstate) {
        if (state == nextEncoderState[prevstate]) {
           direct= count-1;
          if (count > direct){
          myMotor->step(FORWARD, SINGLE);
       Serial.println("________forward____________________");// used for testing purpose

        } else if (state == prevEncoderState[prevstate]) {
           direct= count+1;
            if (count < direct){
           myMotor->step(100, BACKWARD, SINGLE);
           Serial.println("__________backward_________________");// used for testing purpose
        Serial.print("count =");
        Serial.println(count, DEC);
        Serial.println(direct, DEC);
        Serial.print("prev count =");
        prevstate = state;


Mydakota: What is driving the encoder wheel makes no difference at all if it was a DC motor a stepper motor a monkey riding a bike turning wheel attached to a encoder

It is entirely your option to refuse to answer questions.

However there have been many Threads where the problem was really only solved when all the facts emerged.