help needed with optical tachometer


been trying to put together an optical tachometer as instructed here: seems really straight forward and a perfect solution for an upcoming project for which I need to be able to read in real-time the speed of a rotating object and use the speed to control parameters (lights, sound and visual) through the arduino. However I am not getting much results, I have followed the instructions with the only confusion so far being the infrared phototransmitter - the one I have been using does not have a clearly marked collector and emitter (found here: ). I have tried plugging it in both ways around and no results - the serial monitor just reads a continuos 0. when i unplug the gnd cable I get a load of fluctuation and if i bring my hand near the gnd wire then the numbers start to jump up. The infra red LED definatly works as I checked it with an infrared camera. I am at a real loss as to how to get this to work - has anyone had much experience with a similar device?

the code I am using is taken from the tutorial:

 * Optical Tachometer
 * Uses an IR LED and IR phototransistor to implement an optical tachometer.
 * The IR LED is connected to pin 13 and ran continually. A status LED is connected
 * to pin 12. Pin 2 (interrupt 0) is connected across the IR detector.

int ledPin = 13;                // IR LED connected to digital pin 13
int statusPin = 12;             // LED connected to digital pin 12

volatile byte rpmcount;
volatile int status;

unsigned int rpm;

unsigned long timeold;

 void rpm_fun()
   //Each rotation, this interrupt function is run twice, so take that into consideration for 
   //calculating RPM
   //Update count
   //Toggle status LED   
   if (status == LOW) {
     status = HIGH;
   } else {
     status = LOW;
   digitalWrite(statusPin, status);

void setup()
   //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
   //Triggers on FALLING (change from HIGH to LOW)
   attachInterrupt(0, rpm_fun, FALLING);
   //Turn on IR LED
   pinMode(ledPin, OUTPUT); 
   digitalWrite(ledPin, HIGH);
   //Use statusPin to flash along with interrupts
   pinMode(statusPin, OUTPUT);

   rpmcount = 0;
   rpm = 0;
   timeold = 0;
   status = LOW;

 void loop()
   //Update RPM every second
   //Don't process interrupts during calculations
   //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
   //happened once per revolution instead of twice. Other multiples could be used
   //for multi-bladed propellers or fans
   rpm = 30*1000/(millis() - timeold)*rpmcount;
   timeold = millis();
   rpmcount = 0;
   //Write it out to serial port
   //Restart the interrupt processing
   attachInterrupt(0, rpm_fun, FALLING);


any help would be greatly appreciated

never mind - i used another schematic I found on the arduino tutorials for connecting the phototransistor and it works great now. For those that might get stuck at this problem - refer to this tutorial: