Two photo interrupters and Arduino Leonardo

Hello, I'm using two photo interrupters to measure rpm from DC motor. Problem is that when wing of speed encoder of the motor passes in front of the interrupter interrupt triggers 2 or 3 times instead of one. Interrupters are attached to Schmitt triggers, so I get clean digital signal on output. I even made simple oscilloscope with processing and Arduino to check what's going on there, and every time wing pass in front of the interrupter I got one pulse as expected, so problem is somewhere in the code or Arduino. Here is code:

volatile int d = 0;
volatile int l = 0;
void pcl(){
  l++;
}
void pcd(){
  d++;
}
void setup(){
  pinMode(2, INPUT);
  pinMode(7, INPUT);
  attachInterrupt(1, pcl, FALLING);
  attachInterrupt(4, pcd, FALLING);
}
void loop(){
  Serial.print("L:");
  Serial.println(l);
  Serial.print("D:");
  Serial.println(d);
  delay(500);
}

Thanks in advance.

You forgot Serial.begin().

How often are these pulses coming? Could it be that several additional pulses arrive while the serial printing is happening? Can you slow down the motor?

I run motor by hand just to see if this is working. So, there is no pulses when Serial.print() is happening.
I forgot to put Serial.begin() here, because I had to rewrite code here (code on notebook, internet on desktop, no usb sticks around :slight_smile: )

Okay, I did some testing and I found out that one interrupter works fine, but another don't. Second photo interrupter make 6-7 pulses when I remove object in front of it, but makes one pulse when i put object in front of it. I am triggering interrupts on RISING edge.

I think I solved problem with this code for interrupt:

volatile int d = 0;
volatile int l = 0;
volatile unsigned long mc = 0;
volatile unsigned long mr = 0;
void pcl(){
  if (micros() - mc > 500){
  l++;
  mc = micros();
  }
  
}