Hello everyone, first of all, I have these guys with me (actually the whole set for the Rover A4WD1):
]GH Motor 7.2vdc 50:1 175rpm (6mm shaft) (GHM-04)/:m]
]Quadrature Motor Encoder (QME-01)/:m]
but I can’t get the rotation directions, I already read the theory about the quadarture enconders, the 90 degree shift between channels and the way it is supposed to work to identify whether is going CW or CCW but nothing works, until now I’ve tried dozens of sample codes in both C language (Arduino) and Python language (raspberry pi) without success.
do I need to add some other components (resistors, capacitor, others) to the encoder output channels (besides connecting it right away to the microcontroller)?
I came here looking desperately for help. my knowledge about these matters surely is still incomplete so I’d really appreciate any help.
thanks
kind regards
Hey,
Well, according to the manufacturer datasheet for this encoder, it is a typical 100 CPR, 2 mm bore, single-ended signal quadrature encoder.
Just to be on the safe side, we took one of those out from stock and tried it out with motor and an Arduino library. It worked right away.
Here the steps we took*******:
- Connect the red/black wires from the sensor to the Arduino’s 5 V / GND respectively. Similarly, connect the green/yellow wires to the Arduino’s A2/A3.
- Obtain a copy of the RotaryEncoder library for Arduino

- Open the interrupt driven example
- Upload to your Arduino and open the serial monitor (baud rate = 57600, by default).
- Rotate the motor (either electrically or manually). As the position changes, the Arduino will output its count. From that count, you can tell direction.
This example should be able to get you started quickly into using quadrature encoders!
*******: Please note this assumes the encoder is already installed properly on the motor and working. It may be possible that your sensor has the disk too close or too far from the sensor and therefore does not produce a proper signal.
See these instructions for an example of an assembly. They are for the newer model (slightly different physical size, but identical otherwise).
Sincerely,
thanks a lot!.. It really helped… however this example uses the Analog ports of Arduino… the Encoder channel outputs aren’t digital?.. so wouldn’t be better to plug them into a digital input instead?
Hey,
The encoder outputs are indeed digital signals. Please note that the “analog (input) pins” are actually also digital pins, too! 
What often happens in microcontrollers is that many of the pins serve more than one purpose. This allows more flexibility for the end-users when integrating the chip while not requiring a huge amount of pins.
In most cases, you will not use all of the various peripherals simultaneously, so many of the pins can serve multiple purposes depending on how they are configured.
As an example, check out the datasheet (page 14) of the AVR chip ATmega328 (used in the Arduino Uno and many others). It shows a pinout of the chip itself and how most pins have more than one function.
As you can see there, port C is composed of 7 pins (PC0-5). All of them can be digital, 6 of them can be analog inputs (PC0-5, ADC0-5) and 1 can be used as reset (especially useful during programming).
Of course, each pin can only be configured for one specific function at any moment in time. But, in most cases, you can change that function very quickly with a some changes to a few registers.
Sincerely,
hey man! you’re the best! thank you very much for your help! really appreciated it!
Blessings and kind regards!