Phototransistor - Pulse Width Tips: Position and Angle

I'd just like to share my experience with pulse counting. I'm currently doing an electric meter pulse counting project and it works great. However when the pulse rate increased, the accuracy decreased. I was wondering why I was getting maxed out on my counts (ms per count). I thought I had a problem with the sensor (capacitance issue I thought), it turns out the sensor is plenty fast. The datasheet say it has a 5us recovery. When you have no control over the pulse width of what's being measured, this helped out a lot.

You can vary the distance and angle from the pulse to get better resolution.

I hope this helps others.

Cheers, Dan

const byte ledPin = 13;  // LED pin
const byte inputPin = 2; // Photo transistor input, common emitter config 10K resistor
int sensorState = HIGH;  // we start HIGH, detecting LOW Trigger
byte val = 0; // variable for reading the pin status

unsigned long startPulse;
unsigned long timeNow;

void setup() {
  Serial.begin(57600);
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  digitalWrite(inputPin, HIGH); // enable pull-up, we are detecting LOW
}

void loop() {
  val = digitalRead(inputPin); // read input value
  if (val == LOW) { // check if the input is LOW
    PORTB |= _BV(PORTB5);  // D13 HIGH, faster than digitalWrite(ledPin, HIGH);
    if (sensorState == HIGH) {
      startPulse = millis();
      sensorState = LOW;
    }
  }
  else {
    PORTB &= ~_BV(PORTB5); // D13 LOW, faster than digitalWrite(ledPin, LOW);
    if (sensorState == LOW){
      timeNow = millis();
      Serial.println(timeNow-startPulse);
      sensorState = HIGH;
    }
  }
}

ou can vary the distance and angle from the pulse to get better resolution.

Are you referring to adjusting the physical position of the sensor transmitter or receiver ?

I am not sure I understand what you are saying. Without a photo of the motor or any thing else as a reference I am not sure what you mean. Can you explain some other way ?

No motor involved.

I'm referring to the phototransistor as the sensor and it's distance and angle from that fixed pulse source, an IR led.
I had the sensor right up against the IR led which reduced the resolution. Pulling it back from the IR source was the key.

Oh. I went back and reread your post and realized you said :

I'm currently doing an electric meter pulse counting project

For some reason my brain read " electric motor project". (I probably just wasn't paying enough attention to what I was reading)

Can you be more specific ? (optimum distance in mm)
I will tell you this . I did some experimenting myself a month ago (coincidently) and I discovered I got a better looking signal on the scope if the the phototransistor was at a 45 degree angle from the the center of the IR led. I had it on a breadboard and was not even thinking about distances so they were about 2 cms apart.