Can't read rotary encoder

Hi guys,

I have some problems when reading rotary encoder. I have a rotary encoder produced by autonic with e50s8 - 3600 - 3 - t - 24 as a serial number of it. I have read the manual book and the datasheet, it can be supplied directly with 5 v. Then I have been trying to read it more about 2 days but I got nothing.

This is my code:

#define encoder0PinA 3
#define encoder0PinB 2

volatile unsigned int encoder0Pos = 0;

boolean A_set;
boolean B_set;

void setup() {

  pinMode(encoder0PinA, INPUT); 
  pinMode(encoder0PinB, INPUT); 

// encoder pin on interrupt 0 (pin 2)
  attachInterrupt(0, doEncoderA, CHANGE);

// encoder pin on interrupt 1 (pin 3)
  attachInterrupt(1, doEncoderB, CHANGE);

  Serial.begin (9600);

void loop(){ 
//Check each second for change in position
    int A = digitalRead(encoder0PinA);
    int B = digitalRead(encoder0PinB);
    Serial.print(" ");
    Serial.print(" ");
    Serial.print("Index:"); Serial.println(encoder0Pos, DEC);

// Interrupt on A changing state
void doEncoderA(){

  // Low to High transition?
  if (digitalRead(encoder0PinA) == HIGH) { 
    A_set = true;
    if (!B_set) {
      encoder0Pos = encoder0Pos + 1;

  // High-to-low transition?
  if (digitalRead(encoder0PinA) == LOW) {
    A_set = false;


// Interrupt on B changing state
void doEncoderB(){

  // Low-to-high transition?
  if (digitalRead(encoder0PinB) == HIGH) {   
    B_set = true;
    if (!A_set) {
      encoder0Pos = encoder0Pos - 1;

  // High-to-low transition?
  if (digitalRead(encoder0PinB) == LOW) {
    B_set = false;

I got the code from the playground web of arduino, if I'm not mistake, I forget it.....
what I get is, when I rotate the rotary encoder the index value can't be increased and when I rotate to the other direction the index value can't be decreased too. I have trying to see what digital pin get and I use digitalwrite() syntax but the result is aslways zero (0).....

can any one help me please, I confuse with this thing.... :confused: :confused: :confused:

Help the forum help you. Post a schematic of your. actual. wiring. of the encoder to the Arduino.

That encoder requires 12-24 VDC for power. E50S8-3600-3-T-24

If you use a 12V power supply, the outputs should be 0 to 9V. So, use a 2:1 (1K and 1K) voltage divider on the A, B, Z outputs, and make sure that the divider output does not exceed 5V, or you will destroy the Arduino.

thanks u for u'r reply dough and jremington.....

ya sure here is my connection

output rotary encoder >>>> arduino

A (black) D2
B (white) D3
V0 (Blue) Gnd
V+ (brown) 5V
Z (orange) ------ not used ---

any way is there any mistake that I have done with my wiring??

oh ya jremington, thank u, but how can u know that the output is 9 volt, I have read the datasheet and I could not find it out...

any way is there any mistake that I have done with my wiring??

Yes, wrong power supply and no voltage divider. The "24" in the model number is critical. STUDY THE DATA SHEET.