Rotary Encoder - 200 P/R (Quadrature)

This 200 pulse per rotation rotary encoder outputs gray code which you can interpret using a microcontroller and find out which direction the shaft is turning and by how much. This allows you to add feedback to motor control systems. Encoders of this kind are often used in balancing robots and dead reckoning navigation but it could also be used as a very precise input knob. The encoder comes with a set screw coupler which will attach to any 4mm shaft.

  • Resolution: 200 Pulse/Rotation
  • Input Voltage: 5 - 12VDC
  • Maximum Rotating Speed: 5000rpm
  • Allowable Radial Load: 5N
  • Allowable Axial Load: 3N
  • Cable Length: 50cm
  • Shaft Diameter: 4mm

Comments

Looking for answers to technical questions?

We welcome your comments and suggestions below. However, if you are looking for solutions to technical questions please see our Technical Assistance page.

  • Member #184164 / about 6 years ago / 1

    Don't forget the pull-up resistors!

    On the Arduino, you can use the internal resistors by defining your inputs with INPUT_PULLUP.

    This is my code to use it:

     #define rotaryA 2
     #define rotaryB 3
     #define LED 13
    
     volatile int stateA = LOW;
     volatile int stateB = LOW;
     volatile int counter = 0;
     volatile int lastCounter = 0;
    
     void setup() { 
       pinMode (rotaryA, INPUT_PULLUP);
       pinMode (rotaryB, INPUT_PULLUP);
       pinMode (LED, OUTPUT);
    
       Serial.begin (9600);
    
       attachInterrupt(digitalPinToInterrupt(rotaryA), changeA, CHANGE);
       attachInterrupt(digitalPinToInterrupt(rotaryB), changeB, CHANGE);
    
       stateA = digitalRead(rotaryA);
       stateB = digitalRead(rotaryB);
     } 
     void loop() {
       digitalWrite(LED, stateA);
    
       if (counter != lastCounter) {
        Serial.println(counter);
        lastCounter = counter;
       }
     }
    
     void changeA() {
       stateA = !stateA;
    
       if (stateA == HIGH) {
         if (stateB == LOW ) {
           counter++;
           if (counter == 200) {
             counter = 0;
           }
         } else {
             counter--;
             if (counter == -1) {
               counter = 199;
             }
         }
     }
    
     void changeB() {
       stateB = !stateB;
     }
    

  • Member #721850 / about 8 years ago / 1

    I´m trying to read the encoder with the Arduino and everything is okay. But when I read an analog signal the arduino only reads the analog input. I connect both GND, but its still not reading. Does anyone know how can I fix this? Thanks

  • KevCarrico / about 11 years ago * / 3

    as opposed to the example above, here's some code that will get this working right-away in true quadrature fashion. [model #E6A2-CW3C]

    sorry if it is wrong to post this here, but it's free to the world, have spark-fun!

    // code start
    
    [put pound sign here!]include "digitalWriteFast.h" // google this and install it
    
    const byte pin_A =  2; // connect white wire here
    const byte pin_B =  3; // connect black wire here
    int A_set =         0;
    int B_set =         0;
    long pulses =       0;
    
    
    void setup()
    {
      pinMode(pin_A, INPUT);
      digitalWrite(pin_A, HIGH); // enables pull-up resistor
      pinMode(pin_B, INPUT);
      digitalWrite(pin_B, HIGH); // enables pull-up resistor  
    
      A_set = digitalRead(pin_A);
      B_set = digitalRead(pin_B);
    
      attachInterrupt(0, encoderPinChange_A, CHANGE); // pin 2
      attachInterrupt(1, encoderPinChange_B, CHANGE); // pin 3
    
      Serial.begin(115200);  
    }
    
    
    void loop()
    {
      Serial.println(pulses);
    }
    
    
    void encoderPinChange_A()
    {
      A_set = digitalReadFast2(pin_A) == HIGH;
      pulses += (A_set != B_set) ? +1 : -1;
    }
    
    
    void encoderPinChange_B()
    {
      B_set = digitalReadFast2(pin_B) == HIGH;
      pulses += (A_set == B_set) ? +1 : -1;
    }
    

    • KevCarrico / about 11 years ago * / 1

      lol - that looked a lot better when I pasted it!!!

  • michaelshiloh / about 12 years ago * / 2

    Great little encoder for the price. Here's my experience:

    1. Easy hookup, especially since the wiring is documented on the encoder. Wish other products did this! Ground, +5, Out A and Out B. I wired the outputs to my Arduino interrupts, in the case of my Uno that's D2 and D3.

    2. Don't forget the pullups between each output and +5! (I did at first.) The output is open collector and so won't go up to +5 otherwise. I used 10K.

    3. I used the Quadrature encoder library QuadratureEncoder.h pretty much right out of Dr. Rainer Hessmer blog here. Thanks Dr. Hessmer!

    4. In Arduino 1.0 Wprogram.h has been replaced by Arduino.h

    5. In my sketch I copied the example usage from the library and added the following:

      Serial.println ( encoder.getPosition()); delay (10);

    6. Don't forget to initialize the serial port in setup()

    That's it! worked right away.

  • Member #338967 / about 12 years ago / 1

    I'm having a hard time figuring out how to wire the shield wire. It says "Shield: GND" on the rotary encoder. But it's very confusing because the blue wire is "0V(Common)", which is what I connect the negative terminal of the power source to (I think). And the negative side is usually called "ground" right? So, Why is the shield called ground? And what do I connect that to? I'm planning to use an arduino mega with the encoder.

  • Member #138252 / about 12 years ago / 1

    Hmm... Why is there a photo of 5 wires? This rotary encoder only comes with 4 wires, there is no yellow wire. I'm new to all this stuff, a wiring diagram would be fantastic

    • Shannon2 / about 12 years ago / 1

      Mine came with a wiring diagram. Also the data-sheet has a wiring diagram.

      As for the 5th wire. Mine also has a yellow wire, but it is clipped short. No doubt a 5 wire cable is used for all of their encoders and is simply disconnected for this model. Ignore it if you have it and don't worry about it if you do not. Good luck.

  • S1 / about 12 years ago / 1

    I played with an implementation of a quadrature encoder on Arduino and documented some of my understandings / learnings. Might help someone understand the basics...

  • ironyeti / about 13 years ago /

    Index tic would be nice.

  • Dizzy / about 13 years ago /

    Outputs gray code? What I could gather from the datasheet is that the encoder outputs quadrature signals, is that the case really?

    • Lex E / about 13 years ago * / 1

      According to the photos and the datasheet, it's definitely quadrature: two square waves, 90 degrees out of phase. These two signals give direction of rotation, as well as the usual speed.

      It's a kind of gray code, since only one bit changes at a time, but because there are only two bits it only counts 0, 1, 3, 2, 200 times per revolution.

      0 0

      0 1

      1 1

      1 0

  • Member #75535 / about 13 years ago /

    how one could mount it on a DC motor?

    • tyggerjai / about 13 years ago /

      There are a few ways, but you don't really mount it on the motor itself, generally. For small motors, one of 2 solutions:
      a) On the shaft of the motor, in addition to whatever you're using for drive, you can have a gear/pulley that links to the encoder. Depending on your setup, this can also let you have a large gear/pulley on the motor going to a small gear/pulley on the encoder, so a 200 ppr encoder will have a much finer resolution in terms of motor revolutions. So whatever you've bolted your motor to, bolt your encoder to the same thing and have gears/belts/whatever between them.
      b) Attach the encoder to the thing actually being driven. We use encoders like this in theatre a lot for automated scenery, and for a lot of things, you don't actually care about how far the motor has moved, only how far the scenery has moved. While they are almost always the same, if your drive system has any potential for slip (belt drive, friction drives, etc), you want to measure the thing moving, not the motor itself.

      • Member #75535 / about 13 years ago / 1

        many thanks indeed for the detailed reply. could you direct me to some practical examples online?

        • tyggerjai / about 12 years ago / 1

          Sorry for the delay! I'm in the middle of moving house, but I'm also in the middle of building a mini motion control system, so I'll put up some photos and instructions for both those approaches.

  • L1011 / about 13 years ago /

    This would of been very handy for when I converted my L1011 altitude encoder to digital output for flight simulation.. Better yet, a board that could interpret the 400hz ac resolvers that were originally inside the instrument would of been best!

Customer Reviews

5 out of 5

Based on 1 ratings:

Currently viewing all customer reviews.