0

I am making a DIY gaming steering wheel and am stuck. For measuring the rotation of the wheel, I'm using a sensor encoder timing disk, which is usually found in printers. - https://robu.in/product/photoelectric-speed-sensor-encoder-coded-disc-code-wheel.

A lot of tutorials on youtube use this. But I just cannot seem to understand how to use this sensor.

Please help me in figuring this out: using this sensor, how to -

  1. Measure how much the wheel rotated?

  2. Know which direction did the wheel rotates in (clockwise, anti-clockwise).

PS: I tried using a rotatory encoder, but it is unable to sense rotation when rotated by a 1000 RPM motor. Would love to understand why.

Thanks!

asked Dec 27, 2019 at 12:16
1
  • 2
    From the product description it isn't clear, if the sensor has 1 or 2 phototransistors. If it has only 1, you cannot sense the direction. If it has two, it is simple A/B encoding like any rotary encoder. Can you provide a more specific and detailed datasheet? Commented Dec 27, 2019 at 13:42

1 Answer 1

1

It seems to be a A/B coding : if A gets high before B, it's one way (count for exemple), and if B gets high before A, it's other way (decount). So, connect power and ground. Then connect the two wires to input pins :

 int P_A=2; int P_B=3; //Inputs
 long int position = 0; //Position of wheel
 long int lastPosition = 0; //last position of wheel : for speed computing

Notice that one pin must be an hardware interrupt pin (Uno 2 an 3 are interrupt pins. Then attach interrupt in the stup :

 attachInterrupt(2, wheel, RISING); //wheel is arbitray

Then create the interruption code :

 void wheel(){
 int sB = digitalRead(P_B);
 if (sA == sB) { //Clockwise
 position++;
 }
 else { //Counterclockwise
 position--;
 }

Then, in your loop, you can print position when it changes to read current position :

 if(lastPosition != position){
 Serial.println(position);
 }

i hope it will help... Notice that if you use both interruptions, you get a better resolution, but speed limit is lower.

answered Dec 27, 2019 at 12:31
1
  • 2
    I'm having trouble understanding this. Could you please provide a code snippet? Commented Dec 27, 2019 at 14:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.