DFRobot 360 degree rotary encoder module is designed based on EC11 rotary encoder button. This module has three signal terminals: terminal A & B is encoder output; terminal C is button signal output. It is very suitable for applications such as volume knob, lighting adjustment. The rotary encoder module comes with XH2.54 bonding pad, easy to be used in prototyping projects, like automotive electronics, multimedia speakers, instrumentation, smart home and other fields.


Board Overview

EC11 Rotary Encoder Module

Num Label Description
1 VCC 3.3~5V
3 A Encoder-phase A
4 B Encoder-phase B
5 C Button

CW Direction: phase A B signal: A B Pulse Output



Connection Diagram

EC11 Arduino Connection

Sample Code

int encoderPinA = 2;
int encoderPinB = 3;
int buttonPin = 4;

volatile int lastEncoded = 0;
volatile long encoderValue = 0;

long lastencoderValue = 0;

int lastMSB = 0;
int lastLSB = 0;

long readEncoderValue(void){
    return encoderValue/4;

boolean isButtonPushDown(void){
      return true;
  return false;

void setup() {
  Serial.begin (9600);

  pinMode(encoderPinA, INPUT);
  pinMode(encoderPinB, INPUT);
  pinMode(buttonPin, INPUT);

  digitalWrite(encoderPinA, HIGH); //turn pullup resistor on
  digitalWrite(encoderPinB, HIGH); //turn pullup resistor on

  //call updateEncoder() when any high/low changed seen
  //on interrupt 0 (pin 2), or interrupt 1 (pin 3)
  attachInterrupt(0, updateEncoder, CHANGE);
  attachInterrupt(1, updateEncoder, CHANGE);


void loop(){
  //Do stuff here

    Serial.println("you push button down!!!");
  delay(50); //just here to slow down the output, and show it will work  even during a delay

void updateEncoder(){
  int MSB = digitalRead(encoderPinA); //MSB = most significant bit
  int LSB = digitalRead(encoderPinB); //LSB = least significant bit

  int encoded = (MSB << 1) |LSB; //converting the 2 pin value to single number
  int sum  = (lastEncoded << 2) | encoded; //adding it to the previous encoded value

  if(sum == 0b1101 || sum == 0b0100 || sum == 0b0010 || sum == 0b1011) encoderValue   ;
  if(sum == 0b1110 || sum == 0b0111 || sum == 0b0001 || sum == 0b1000) encoderValue --;

  lastEncoded = encoded; //store this value for next time

Expected Results

Printing Info.


For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get EC11 Rotary Encoder Module_SKU SEN0235 from DFRobot Store or DFRobot Distributor.

Turn to the Top