# Laser pulse counting

Hi all,

I have to make an arduino program to check the proper functioning of an infrared laser (900nm) that pulse exactly to 100 pps.
I will use a diode SFH203FA like this circuit:

how to measure pulse?
I have put several diodes to refine the results?

The response of the arduino should be fast because it must stop a production line quickly if bad value.

I'm still a beginner, thank you for helping me on for the code .

Br,

Have a look at this for how to use the UNO's analogue comparator or maybe use an external one.

Riva:
Have a look at this for how to use the UNO's analogue comparator or maybe use an external one.

As I see, maybe i am wrong, to use comparator you need to have 02 hard source to compare, or here I have diode and light :~

I found this picture in the net:
can I do same with android?

thank's

how to measure pulse?

First you have to define what properties of the pulse you wish to 'measure'. Is it pulse width, pulse repetition rate, Pulse high voltage value, pulse low voltage value?

Is a single pulse being measured or a stream of pulses?

Lefty

What I do know is that this is a stream of pulses at 900nm.

retrolefty:

how to measure pulse?

First you have to define what properties of the pulse you wish to 'measure'. Is it pulse width, pulse repetition rate, Pulse high voltage value, pulse low voltage value?

As I see, maybe i am wrong, to use comparator you need to have 02 hard source to compare, or here I have diode and light smiley-confuse

You setup the comparator circuit so laser off reading from your circuit falls below trigger threshold and laser on pushes your comparator circuit reading above the threshold. The comparator output would trigger a interrupt on a digital pin that increments a counter. In your program loop you zero this counter, wait 1 second and read the counter to get how many pulses have happened. What you do with this result if it's not what youe expected is up to you.

Riva:

retrolefty:

how to measure pulse?

First you have to define what properties of the pulse you wish to 'measure'. Is it pulse width, pulse repetition rate, Pulse high voltage value, pulse low voltage value?

As I see, maybe i am wrong, to use comparator you need to have 02 hard source to compare, or here I have diode and light smiley-confuse

You setup the comparator circuit so laser off reading from your circuit falls below trigger threshold and laser on pushes your comparator circuit reading above the threshold. The comparator output would trigger a interrupt on a digital pin that increments a counter. In your program loop you zero this counter, wait 1 second and read the counter to get how many pulses have happened. What you do with this result if it's not what youe expected is up to you.

Thank you for that clarification.

This code is correct ?

``````volatile boolean triggered;
int counter = 0;

ISR (ANALOG_COMP_vect)
{
triggered = true;
}

void setup ()
{
Serial.begin (115200);
Serial.println ("Started.");
ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
ACSR =  _BV (ACI)     // (Clear) Analog Comparator Interrupt Flag
| _BV (ACIE)    // Analog Comparator Interrupt Enable
| _BV (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
}  // end of setup

void loop ()
{
if (triggered)
{
counter++;
}
delay(1000);
if (counter==100)
{
Serial.println ("Laser is ok at 100 pps.");
}
else
{
Serial.println ("Laser is not ok!!");
}
counter=0;
}  // end of loop
``````

``````volatile byte counter;

ISR (ANALOG_COMP_vect){
counter++;
}

void setup (){
Serial.begin (115200);
Serial.println ("Started.");
ADCSRB = 0;                   // (Disable) ACME: Analog Comparator Multiplexer Enable
ACSR =  _BV (ACI)             // (Clear) Analog Comparator Interrupt Flag
| _BV (ACIE)                  // Analog Comparator Interrupt Enable
| _BV (ACIS1);                // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
}  // end of setup

void loop (){
counter = 0;                  // Reset counter
delay(1000);                  // Wait 1 second
byte count = counter;         // Read counter
Serial.print ("Counter = ");
Serial.println (count);       // Display result
}
``````

For the code to work you will need to correctly setup the voltage divider value fed to pin 7 so it sits below the laser off voltage from your circuit and above the laser on value.
Due to system overheads (doing things like serial print) the value may no be exactly 100 and may vary.