How to use the Z-output for my rotary encoder E6B2-CWZ3E (1024 P/R)?

I'm working on a project where I'm using a Rotary Encoder - 1024 P/R (Quadrature) E6B2-CWZ3E. The encoder has 1024 pulses per revolution, and I'm trying to use the Out Z (orange wire) to accurately reset the encoder position after one full rotation, as my project requires high precision. What I've tried so far:

  • I connected the Out Z (orange wire) to my Arduino pin.
  • I measured the voltage on the Out Z pin using a multimeter while slowly rotating the encoder, but I didn't observe any significant changes in the voltage. It constantly reads around 0V, with only small fluctuations.
  • I know the Z output should give a pulse once every full rotation (90° high signal), but I'm not sure if it works with this model or if I'm missing something.
  • I also tried using both an external pull-up resistor and the internal INPUT_PULLUP in my Arduino code to try and get a proper signal from the Z output, but it didn't help.

Is it even possible to use the Z-output (orange wire) of this encoder model to reset the position after one full rotation?
If yes, how should I properly wire the Z-output to the Arduino and modify the code to detect the pulse?
Is there a special requirement for activating the Z signal, such as specific timing or conditions?
Could there be a problem with my model, or is there something specific I need to do to get the Z signal?

Thank you for your help! I've already spent quite a bit of time on this, and any guidance would be greatly appreciated.

#define encoder0PinA 2  // Pin for channel A
#define encoder0PinB 4  // Pin for channel B
#define zIndexPin 5     // Pin for Z-output (orange wire)

volatile long encoderPos = 0;  // Current encoder position
long lastEncoderPos = 0;  // Last sent encoder position

void setup() { 
  pinMode(encoder0PinA, INPUT); 
  pinMode(encoder0PinB, INPUT); 
  pinMode(zIndexPin, INPUT_PULLUP);  // Using internal pull-up resistor for the Z pin

  attachInterrupt(digitalPinToInterrupt(encoder0PinA), updateEncoder, CHANGE);
  attachInterrupt(digitalPinToInterrupt(zIndexPin), resetEncoder, CHANGE);

  Serial.begin(9600);
}

void loop() {
  if (encoderPos != lastEncoderPos) {
    Serial.println(encoderPos);  // Send the current encoder position
    lastEncoderPos = encoderPos;  // Update the last sent position
  }

  delay(10);
}

void updateEncoder() {
  int stateA = digitalRead(encoder0PinA);
  int stateB = digitalRead(encoder0PinB);
  
  if (stateA == stateB) {
    encoderPos++;
  } else {
    encoderPos--;
  }

  if (encoderPos < 0) {
    encoderPos += 2048;
  }
  encoderPos = encoderPos % 2048;
}

void resetEncoder() {
  Serial.println("Z-index signal detected, resetting position to 0!");
  encoderPos = 0;
}

Did you connect the grounds? This line ensures that Vcc should appear on the Z input, if it is open drain or collector.

 pinMode(zIndexPin, INPUT_PULLUP);  // Using internal pull-up resistor for the Z pin

Yes, I have connected the grounds. The GND of the encoder (blue wire) is connected to the GND pin of the Arduino, and the black probe of the multimeter is also connected to the Arduino's GND.

According to the encoder data sheet, the outputs are open collector. So there is something wrong with your wiring.

Are you connecting encoder 0V to Arduino GND, as required?

Here is how I have wired the encoder:

  • Black -> Digital 2 (Channel A signal)
  • White -> Digital 4 (Channel B signal)
  • Orange -> Digital 5 (Out Z - Z-index signal)
  • Brown -> pin 5V of Arduino (Vcc)
  • Blue -> pin GND of Arduino (GND)
  • Shield (thicker black wire) -> pin GND of Arduino (Shielding)

I have connected the grounds as required, with both the blue wire (encoder GND) and the shield (thicker black wire) connected to the Arduino GND.

Despite this setup, I still don't see significant voltage changes on the Z-index pin (orange wire) when rotating the encoder slowly. The voltage remains close to 0V.

Hi, @potter3366

1024CPR => 360/1024 = 0.35 degree per step.

The Z output will be 0.35 degrees of rotation wide.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Which Arduino? Which pin? Is that pin an external interrupt pin? All encoder input pins should be pulled up.

Arduino UNO R3, digital pin 5

https://assets.omron.eu/downloads/datasheet/en/v5/q085_e6b2-c_incremental_rotary_encoder_40_mm_datasheet_en.pdf

The code is working correctly overall. I have tested it with graphics in Processing. However, since I need precise positioning for my installation, I would like to reset the position after every full rotation using the Out Z signal, if that is its intended purpose.

In the datasheet for my model, it says: Output configuration: Voltage output (NPN output). Does this mean I need to add an external 10kΩ pull-up resistor between Out Z (orange wire) and Vcc (5V)? Why didn't I need to add one for Out A and Out B?

According to the data sheet, internal or external pullups on all outputs are required.

As pointed out by @TomGeorge, the Z output will be a very narrow negative pulse, easy to miss with a multimeter. But you will never see that if there is a problem with the wiring, as the 0 V reading suggests.

Alligator clip leads are at the bottom of the list for reliability, as the wires break easily and the teeth don't grip well. Bare wires poked into a female header connection are even lower on that same list.

It would be a good idea to learn to solder and make up proper connectors.

What type of connections do you recommend, which wires, please leave me a link..

Hi,
For all to see.


With 5V supply, 10K pullup = 5 / 10K = 0.0005 A = 0.5mA

I would use 1K pullup.

5 / 1k = 0.005 A = 5mA

As the spec says up to 35mA, but 5mA should be enough.
0.5mA I would consider susceptible to noise.

Tom.. :smiley: :+1: :coffee: :australia:

For connections to Arduino female headers, Dupont connectors (or crimp connectors) are highly recommended. Buy premade jumpers, or the parts and crimping tool to make your own.

Can I put a 220 pull-up on every Out? That would be 23mA < 35mA ?

1K is recommended.

I don't have them right now, I only have 220 and 2k :slightly_frowning_face:

Use 2K then. 220 Ohm pullups would be complete waste of power.