Creative Commons images are CC BY-NC-SA 3.0

2.95

added to your
shopping cart

quantity
In stock 187 in stock
2.95 1+ units
2.66 10+ units
2.36 100+ units

Description: This is a 12-step rotary encoder with a nice 'clicking' feel. It's breadboard friendly, and has a pretty handy select switch (by pushing in on the knob). The encoder is different from a potentiometer in that an encoder has full rotation without limits. The unit outputs gray code so that you can tell how much and in which direction the encoder has been turned.

This unit does not come with a knob, but a working knob is related below.

Documents:

Comments 60 comments

  • I have the some example code for the Arduino that does a decent job figuring out where and how much is being turned on the encoder.
    Take a look here:
    http://gist.github.com/154809
    (if you can help improve the code please fork it)

  • hi - so i am using the 3 pins on one side to read-in the rotary data no problem. and actually there is little to no bounce, which is uncommon for such a cheap little unit! but also i have a question, i can’t figure out how to read in the push button data … it doesn’t seem to be the two pins on the other side … am i missing something?

    • One of the reasons for using gray code is that you don’t have to worry about bounce. At a given moment in time only one of the outputs can be unstable, never both.

    • cuzincuz,
      I’ve got one in front of me and the two pins are to the push button. Momentary, normally open.

  • Just FYI, if you wire the encoder backwards (PIN 1 where PIN 2 should go and vise versa), your Arduino sketch will fail on upload saying: “avrdude: stk500_recv(): programmer is not responding.”

    It’s a poor error message - since it doesn’t point you at ALL to the actual problem.

  • Can this product be used as a wheel encoder? I realize it may not be designed for the durability normally required for a wheel enocder, but the most important question is if it can rotate continuously.

  • I have the some example code for TI Launchpad msp430 t Take a look here: https://github.com/littlepiggy/Launchpad-rotary-encoder

  • The code to read a rotary encoder is very very simple if you look at the pattern of bits produced. Code below. The main problem with these things is the incredible amount of switch bounce; when i spin one as quick as i can i get a quadrature event every 2 - 5 mS and bouncing out past 1mS.

    While i prefer to debounce in software, in this case it’s better done in hardware – nearly all the bounce can be removed with a resistor and capacitor. 10K pullup to 5V and .1uF to ground. Don’t rely on the Arduino’s internal pullup.

    I hate dedicating the only two interrupt pins to the encoder, so i run this code in loop() up at the top. This may not work for you – i NEVER use delay() in my code, only millis() and a “timer” (eg. unsigned long T) and if (millis() > T) … for timing things, so the top of my loop() comes around multiple times a millisecond for most programs.

           a  b  c  d    e  f  g  h    i  j  k  l ...
      CW  01 00 10 11   01 00 10 11   01 00 10 11 ...
      CCW 10 00 01 11   10 00 01 11   10 00 01 11 ...
    

    Looking at any pair of reads (ab, bc, fg, gh, etc), adjacent bits will always be different for CW, always the same for CCW.

    The core code is this:

     /* Poll the rotary encoder; returns 1 for CW rotation, -1 for CCW,
      else 0. */
    
      int readRotEnc () {
    
      static char pR;                    // previous read; two bits, AB
    
      char m;                            // MS bit of current read (A)
      char R;                            // current read (two bits, AB)
    
      R= ((m= digitalRead (RPINA)) < < 1) | digitalRead (RPINB);
      if (R == pR) return (0);         // no change since last time
    
      m ^= (pR & 1);                   // m is 0 for CCW, 1 for CW
      pR= R;                           // current read is now "previous"
      return (m ? 1 : -1);
    }
    

    NOTE: the website comment editor has a bug! it deletes all text following a double-less-than! which is of course the *nix input redirect. doh, it probably means this page has some serious vulnerabilities.

    • oh, and glue that code above below this and you have a sample program that demo’s it.

      const int RPINA = 6;
      const int RPINB = 7;
      
      void setup () {
      
        Serial.begin (9600);
      }
      
      void loop () {
      
      
        switch (readRotEnc()) {
          case 1:  Serial.write ("+");  break;
          case -1: Serial.write ("-");  break;
        }
      }
      
  • I want to ultimately convert the codes to tell a audio volume control IC to step the attenuation up or down. Most such chips resolve to about 1db per step, so to have rotary encoder behave something akin to what one would expect in a volume control, I’m going to need about 128 PPR. I’ve been looking all week and have come to conclusion only expensive optical units with offer any PPRs > about 32. So before I start looking for an inexpensive gear arrangement, does anyone know of a a better product for me to look at?

    • We do have a 200ppr encoder, but in my experience you can still take a few revolutions to go from 0% to 100% and not annoy the user. Velocity-sensitivity is another option (increase by a greater gain if you’re turning it faster).

  • A good knob for this is mouser part 450-4761

  • There is no Eagle file for this part in the SparkFun Eagle library! :(

  • I’m having trouble. So If I use the example from : http://www.circuitsathome.com/mcu/programming/reading-rotary-encoder-on-arduino

    All I’m getting is 0,1 and 0,1 whenever I turn the encoder left or right. The code should increment the counter. Any thoughts?

  • I ordered a few of these inexpensive rotary encoders to play with and electrically they work fine. I have some simple PIC test code to inc/dec a 7-segment LED and seems pretty reliable. What I don’t like about this part is the action… it’s too easy to get stuck in the middle of the 12 indents, especially when turning slow. I’m assuming a higher quality part would do a better job of only stopping on the 12 position indent and not in the middle of two positions.

  • Looking at the data sheet this has quadrature outputs and not gray code. There is a big difference. Sparkfun can you comment on this and / or change the description.

    -Sam K

  • “It’s breadboard friendly,”

    Not really. DO NOT PUT THIS IN YOUR BREADBOARD!!!! It bends the leads and then they snap off. You have two options:

    1. solder wires on to it, put heatshrink on them if you have it.
    2. make a pseudo-breakout board w/ http://www.sparkfun.com/products/8886

    baum

  • Worth Noting that these are 48 steps/Revolution not 12, there are 12 DETENTS, each detent counts as 4 steps electrically.

    • This is true, and it allows code to be a lot shorter than other people have it. If it is being used by each click at a time, then connecting the common to 5v and the other to 2 input pins(with some pull-down resistors), you can see which way it was turned by seeing which pin goes high first(it will be all messed up if you keep it in a position between clicks, however).

    • it depends on how you’re reading the code. they are 12 steps per revolution. you’re code is just outputting 4 signals per step. try some of the other example codes.

  • I found the example code pretty confusing. For more understandable, no library and rock steady decoding check out this page.

  • I have created a library that works with this encoder. See it here:
    http://code.google.com/p/adaencoder
    It differs from most other code by being interrupt-driven and easy to use on any pair of Arduino pins (with caveats that the pins must share an ATmega PORT [see the source code for more info]).
    Enjoy!

  • I have designed my own simple rotary encoder breakout board for this part out of necessity. You can check it out here: http://www.inmojo.com/store/disassemble-reassemble/item/rotary-encoder-breakout-pcb-only/

  • First, I can’t believe that someone does not make an I2C decoder for an Rotary Encoder. YES, I have ran across people making PICs that can do it, but I am still surprised that no one has made a 12 pin chip that can fit the bill.
    What I did find, that I thought was interesting, was a made from two 74HC132 chips with some passive glue >> http://archive.electronicdesign.com/files/29/21422/fig_02.gif Full article is here >> http://electronicdesign.com/article/analog-and-mixed-signal/simple-quadrature-decoder-suits-rotary-encoders214.aspx.
    What caught my eye was that there were only two outputs: INC, and DIR.
    My frustration with tying a rotary encoder to an Arduino is that you’re wasting resources of the Arduino. Also you have to make sure whatever code you are writing never hangs so to prevent the Arduino from seeing a INT or changed state from the Rotary Encoder. Yes, I do realize that most Arduino are fast. But there always some type of code that takes it’s sweet time to get through that prevents the processor from seeing the INT or a changed state.

    • I see this exactly the other way around. I like to use the Arduino for this and do everything in software (which I can change if I find out it does not work), instead of using 10 external components and a custom PCB. If you look at the code - it takes only a few lines. Also, you would not free up any pins Enc A and Enc B with one solution and INC and DIR with the other. I guess it comes down to preference and what you are more comfortable hardware vs software…

      • I agree with your assessment with INC and DIR. But what would really be cool is if the Rotary Encoder could be hooked up to something like a PCA9555 {http://www.nxp.com/documents/data_sheet/PCA9555.pdf } and let the PCA9555 do the monitoring of the Rotary Encoder- no software for monitoring the Rotary Encoder, just software that talks I2C, and responds to a INT. Then all you have is two wires for I2C, and an INT. Everything is addressable.
        I think the next step for the Mayhew Labs Rotary Encoder LED Ring Breakout Board is to add RGB LEDs, and Maybe three PCA9635 chips that does all the mixing/dimming on the chips for the LEDs (NO-resistor networks), again all I2C bus (-two wires and the INT, plus VCC and Vss). And all the PCA9xxx chips are addressable meaning you can have a number of I2C chips on the same I2C buss. The PCA96xx can run around 1MHZ and the PCA9555 runs around 400 KHZ. That means the I2C bus has to run at the lower speed unless you can MUX it so they see the speed they like. I just like the thought that you could have the color you want, at the brightness you want, and it does not mean that your locked into one set of colors. HECK you could have the UV meter style output, or maybe one color where everybody else is another color. If the PCA9555 cant trap and help with decoding, then I guess we are stuck with having the Arduino do it.

  • These are definitely quadrature encoders. You can multiply the counts by using edge detection. So you can increase the counts to a maximum of 48 counts easily.

  • For whoever may find it useful: I used a bunch of these rotary encoders for a prototyping project and I wrote a simple wrapper library around them.
    You can find the code on GitHub:
    https://github.com/micheljansen/arduino-rotary-knob
    #define PIN_OFFSET 22
    #define NUMKNOBS 6
    Knob knobs[NUMKNOBS];
    void setup()
    {
    for(int i = 0; i < NUMKNOBS; i++) {
    knobs[i].setup(PIN_OFFSET + 2i, PIN_OFFSET + 2i + 1);
    // abuse output pins for gnd
    pinMode(i+2, OUTPUT);
    digitalWrite(i+2, LOW);
    }
    Serial.begin(9600);
    }
    void loop()
    {
    for(int i = 0; i < NUMKNOBS; i++) {
    int dir = knobs[i].read();
    if(dir) {
    if(dir > 0) {
    Serial.println(“right”);
    }
    else {
    Serial.println(“left”);
    }
    }
    }
    }

  • Does anybody know of a knob that fits this? I tried the silver metal knob (COM-10001) and it definitely does not fit - the shaft is too big. I tried a knob off another piece of equipment (perhaps similar to the black knob, COM-09998) and it didn’t fit either. It’s pictured with COM-08828, is that the only one that fits?
    Thanks.

    • Saccade, if you check the data sheet, you will see that this has a 6mm shaft as opposed to the more common (in the US) ¼" shaft. You can find many knobs on the web for a 6mm shaft - Google “6mm shaft knob” for a zillion of them. The biggest problem you’ll have is finding one that doesn’t cost as much as two of these encoders! You can sometimes make a ¼" inch knob fit very nicely by shimming with a split ring made from an aluminum soda can.

      • Thanks; actually I just didn’t push hard enough. Once I got the encoder mounted, I was able to Push Pretty Hard on the COM-10001 silver knob, and it did fit on the encoder’s shaft.

        • I can’t recommend this. I tried it and the encoder broke under the pressure. If you have your heart set on the 10001 knob, you’ll want to drill out the knob a bit more and use some glue.

          Update: I drilled my 10001 knob out at 15/64ths inch, and now it press-fits great on the shaft of the (replacement) encoder. I probably won’t even glue it.

  • Here’s a slick, 2-wire interrupt-driven Arduino solution (which should be easily adaptable elsewhere) that I saw over at Ayars' Hardware Hacks. It only determines direction, but that’s all I’m going to be using this for.

  • Here’s the Arduino code I ended up using.

    /*
        www.Wusik.com - Created by WilliamK @ Wusik Dot Com (c) 2010
     */
    
    #ifndef ENCODER_h
    #define ENCODER_h
    
    #include
    #include "HardwareSerial.h"
    
    // 12 Step Rotary Encoder with Click //
    // http://www.sparkfun.com/products/9117 //
    #define EncoderPinA 20  // Rotary Encoder Left Pin //
    #define EncoderPinB 19  // Rotary Encoder Right Pin //
    #define EncoderPinP 21  // Rotary Encoder Click //
    
    // ======================================================================================= //
    class Encoder
    {
      public:
        Encoder()
        {
          pinMode(EncoderPinA, INPUT);
          digitalWrite(EncoderPinA, HIGH);
          pinMode(EncoderPinB, INPUT);
          digitalWrite(EncoderPinB, HIGH);
          pinMode(EncoderPinP, INPUT);
          digitalWrite(EncoderPinP, HIGH);
    
          Position = 0;
          Position2 = 0;
          Max = 127;
          Min = 0;
          clickMultiply = 10;
        }
    
        void Tick(void)
        {
          Position2 = (digitalRead(EncoderPinB) * 2) + digitalRead(EncoderPinA);;
          if (Position2 != Position)
          {
            isFwd = ((Position == 0) && (Position2 == 1)) || ((Position == 1) && (Position2 == 3)) ||
              ((Position == 3) && (Position2 == 2)) || ((Position == 2) && (Position2 == 0));
            if (!digitalRead(EncoderPinP)) { if (isFwd) Pos += clickMultiply; else Pos -= clickMultiply; }
            else { if (isFwd) Pos++; else Pos--; }
            if (Pos < Min) Pos = Min;
            if (Pos > Max) Pos = Max;
          }
          Position = Position2;
        }
    
        int getPos(void)
        {
          return (Pos/4);
        }
    
        void setMinMax(int _Min, int _Max)
        {
          Min = _Min*4;
          Max = _Max*4;
          if (Pos < Min) Pos = Min;
          if (Pos > Max) Pos = Max;
        }
    
        void setClickMultiply(int _clickMultiply)
        {
          clickMultiply = _clickMultiply;
        }
    
      private:
        int clickMultiply;
        int Max;
        int Min;
        int Pos;
        int Position;
        int Position2;
        int isFwd;
    };
    
    #endif
    
  • I agree with fluidic on the feel of this encoder. it is very weak, and unstable. but for 3 bucks, it is a great deal for proto work. if you need anything with single-click precision, this model won’t work very well. I used Oleg’s code and it ran first build, as advertised.

  • Tactile feedback is kind of weak, more bumpy than snappy. Still noticeable though. Good enough for prototyping. Might want to try a wider range of alternatives if you’re considering deployment or building something permanent.

  • any tips on using this with COM-10001? I ordered two of each and, alas, the knob doesn’t really fit. I am loath to use glue but I suppose I will if I must.
    Otherwise MANY thanks to all the helpful links! with the info here I got it up and running in about as much time as it took to open the box. =-D

    • I am using this with COM-08828 and had problems with the button sliding down the shaft so far that the select switch would not work. I solved the problem by putting a small wad of paper in the knob so that it could not slide all the way down, but is still secure on the shaft. <br />
      <br />
      BTW, I am using this with a parallax propeller and it works nicely with the article/code from Jon William for Nuts and Volts Magazine:<br />
      <br />
      Article:<br />
      http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp6.pdf<br />
      <br />
      Code:<br />
      http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/code/nvp6.zip

    • It works best with knobs that have set screws.

  • A word of warning about using these in an enclosure. There is very little room between the bottom of the knob (sold seperately) and the encoder case. Without pressing the “button” there is 1.0mm (assuming you make holes for the two small bumps on top of the encoder case). With the button pressed you’re down to about 0.5mm (I couldn’t get my calipers in between to measure).
    I ended up cutting holes in my enclosure large enough for the knobs to fit inside. My case would have looked cleaner if I could have had holes just big enough for the shafts.

  • Very easy to use. I have written some introduction on how to do so here: http://bit.ly/cNdzV7

  • Be warned! This one only has 12 steps per cycle instead of the usual 20.

  • Anyone have an eagle part for this?

  • I have the push working nicely.
    But cannot make sense of the rotary encoding. The values the device reports seem very arbitrary. It is frustrating; I am going to need to re-think the interface to this project. If I had been able to make this work as expected it would have been a perfect choice for this control interface.

  • Yes, I agree with skelso that quadrature would have been more descriptive. The datasheet also does not fully describe which pins the push switch connects to, but I assume that they are the two unlabeled pins. I also assume that they meant to describe the switch as a momentary, normally open type which goes to closed when the shaft is pressed down.
    Clarity in datasheets is becoming rare nowadays…

  • Wouldn’t most say this is a quadrature encoder? Gray code implies absolute, and this would need four bits of Gray to be that. Yes, quadrature is a two-bit Gray code, but still…

    • “Gray Code” is a sequence of binary numbers where only one bit can ever be in transition at any given time. People use it for absolute positioning, yes. They also use it for quadrature encoders like this one.

    • I think they key idea of gray code is that only one bit changes between adjacent states so there is less guessing about the state during a transition. <br />
      <br />
      This is true of a quadrature encoding, as you said.

  • The Rotary Encoder sku: COM-09117 is missing its PDF data sheet. http://www.sparkfun.com/datasheets/Components/TW-700198.pdf fails.

  • :( Mine came with a pin broken and I have contacted sparkfun,but I was really hoping i could get this project done :(
    You REALLY need to “pad” the boxes you use…


Related Products