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;
}
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.
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.
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.
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.
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.