How to connect an optical encoder on DC motor


I've spent the best part of the day trying to figure out how to take a reading off a Yamamoto 24V DC motor with built in 50 step optical rotary encoder. I want to be able to calculate RPM and count the amount of revolutions, and know I need to use interrupts to do this. I finally found some info that seemed the most applicable to my need but am still uncertain as to how to connect the 3 wires from the encoder. I don't really need to be able to tell direction information from the sensor so am only going to monitor one of the two outputs

The three wires from what I can tell from examples of other encoders are output A, common /ground, and output B. In some examples I've seen the A and B outputs connected to 5v through 10k resistors, and to input pins on the arduino, and in others they go direct. In both cases using the code below copied from an example, I don't get any meaningful data. Any help would be greatly appreciated - if I am omitting some information that would be useful please let me know....

// The pin the encoder is connected
int encoder_in = 2;

// The number of pulses per revolution
// depends on your index disc!!
unsigned int pulsesperturn = 50;

// The total number of revolutions
unsigned int revolutions = 0;

// Initialize the counter
volatile unsigned int pulses = 0;

void count() {
  // This function is called by the interrupt

void setup() {
  pinMode(encoder_in, INPUT);
  attachInterrupt(0, count, RISING);

void loop() {
  revolutions = pulses / pulsesperturn;
  // Here you can output the revolutions, e. g. once a second

Before you connect the encoder to an Arduino, you need to determine the functions of the three wires coming from the encoder. Optical encoders usually require a power source (e.g. for an on-board LED), so it is hard to imagine how you could have A and B outputs, plus ground and power, with only three wires. It is possible that this is just a tachometer and the three wires are power, ground and signal, but more information is clearly needed.

thanks for your reply jremington. Yeh that occurred to me too, and upon closer inspection it looks like a photo interrupter-an LED and a photodiode...the component has the led and transistor sides marked so I should be able to figure out where power, ground and signal connections go.

Thanks again for pointing it out, I was getting stuck in a rut...