Encoding Odrive motor with optical encoder

Hello world! Happy New Year to all :0)

Our rover team has a motor drive project and a question about suitable encoders to track position of driven wheel. As you may know, the Odrive encoder spreadsheet calls for a short list of encoder solutions seen here:

Here is a list of the rover’s hardware in development:
48V Odrive V3.5 controller
2 BLDC motors (without access to shaft)
36V Li-Po battery
Optical Encoder disk (mounted to inside of wheel driven by BLCD motor)
OPB704WZ photogate
Ardiuno Uno

Because the big issue is we don’t have access to motor shaft due to BLDC design flavor, the optical encoder could be a solution to count ticks for position to be feed into Odriver controller A and B inputs. The encoder disk in motion is black and white for quadrature encoding and not absolute .
Are the any pitfalls in this solution that come to mind? Thanks for sharing your thought on this prospective encoder workaround.

Thank you kindly,

Our rover team would like to know if optical photogate sensors will work for encoding wheel position driven by a hooverboard motor.

Currently a clear disk (OD 60mm) has black and clear encoder disk (50 black/50 clear segments). This disk is mounted to the inside of 10 inch wheel. Two different opb7030570 photogate sensors are detecting black to clear transitions; one black line while the other sensor see a clear line. Counters in code are tracking the number of ticks as wheel moves.
Here’s the code:

const int encoderIn = 8; // input pin for the interrupter for Rotary
const int encoderIn2 = 7; // input pin for the interrupter for Rotary2
const int statusLED = 13; // Output pin for Status indicator for LED
const int statusLED2 = 11; // Output pin for Status indicator for LED2
const int pulseOutput = 12; // Pulse output pin for external interfacing for Test
const int pulseOutput2 = 10; // Pulse output pin for external interfacing for Test
//int detectState = 0; // Variable for reading the encoder status
int val = 0; // variable for reading the encoder status
int val2 = 0; // variable2 for reading the encoder status2
int count = 0;
int count2 = 0;
int currentState = 0;
int currentState2 = 0;
int previousState = 0;
int previousState2 = 0;

void setup()
pinMode(encoderIn, INPUT); //Set pin 8 as input
pinMode(encoderIn2, INPUT); //Set pin 7 as input
pinMode(statusLED, OUTPUT); //Set pin 13 as output
pinMode(statusLED2, OUTPUT); //Set pin 11 as output
pinMode(pulseOutput, OUTPUT); // Set Pin 12 as output
pinMode(pulseOutput2, OUTPUT); // Set Pin 10 as output
void loop() {
/////////Encoder 1
val = digitalRead(encoderIn); // read input value
if (val == HIGH)
{ // check if the encoder is HIGH (no rotary change)
digitalWrite(pulseOutput,HIGH); // Give a logic-High level output
digitalWrite(statusLED, HIGH); //Turn on the status LED
currentState = 1;
digitalWrite(statusLED, LOW); //Turn off the status LED
digitalWrite(encoderIn, LOW); // turn LED off
currentState = 0;

if(currentState != previousState)
if(currentState == 1){
count = count + 1;
Serial.print("A: ");

previousState = currentState;

//////////Encoder 2
val2 = digitalRead(encoderIn2); // read input value
if (val2 == HIGH)
{ // check if the encoder is HIGH (no rotary change)
digitalWrite(pulseOutput2,HIGH); // Give a logic-High level output
digitalWrite(statusLED2, HIGH); //Turn on the status LED
currentState2 = 1;
digitalWrite(statusLED2, LOW); //Turn off the status LED
digitalWrite(encoderIn2, LOW); // turn LED off
currentState2 = 0;
if(currentState2 != previousState2)
if(currentState2 == 1){
count2 = count2 + 1;
Serial.print("B: ");

previousState2 = currentState2;


Odrive V3.5 48V board is being used. We would like to use optical encoders as the BLDC motor setup doesn’t allow for access to shaft. Would Odrive motor calibration be possible with two optical encoders and Aurdiuno code seen above? Can A, B and Z encoder inputs on Odrive controller be used with this optical setup?

Thank you kindly for your feedback and time,

Here is the photogates used to sense the black and white transitions.

Sure, any quadrature encoder can be used. You would need two phases that are 90 degrees apart.

1 Like


I am curious about this development.

Encoder is working properly?