Hi,

I am developing an experiment where a photodiode measures the intensity from a LED. Now, since ‘real’ instruments use a pulsed source I want to try to build it that way as well.

Sadly enough I don’t have my papers with me right now and I don’t remember the ideal frequency, but it shouldn’t be too high (between 5 - 10 Hz, I’ll check it tomorrow, but thought it might be nice to ask the question already)

So, in it’s most basic form, all I want the Arduino to do is to put the LED on and off at 5 to 10 Hz, and measure a voltage on the photodiode everytime the LED is on. My question now is, can I just construct a loop with a delay of 100ms? (see - massively simplified - code) or do I have to take into account the time it takes to read and store (write) a value? I can imagine the time needed for that is negligible compared to the low frequency…

```
loop{
light ON
measure
debug.print(measurement1)
delay(100)
light OFF
measure
debug.print(measurement2)
delay(100)
}
```

And what if, in every 100ms (5Hz) or 50ms (10Hz) period, I measure the average of 10, or 20? (or put differently: how many measurements could I take, average out and print in e.g. a 50ms interval?)

My code now measures the average and standard deviation like this:

```
// Here we compute the mean.
mean_v=0;
mean_vref=0;
for(i_math=0;i_math<49;i_math++)
{
mean_v=mean_v+V[i_math]; // V[50] is an array containing 50 measurments of the Voltage, Vref[50] is the same but for the reference voltage
mean_vref=mean_vref+Vref[i_math];
}
mean_v=mean_v/counter;
mean_vref=mean_vref/counter;
// Here we compute the std.
std_v=0;
std_vref=0;
for(i_math=0;i_math<49;i_math++)
{
std_v=std_v+ pow(((double)V[i_math]-mean_v),2); // voltage value is so small that 50 measurement will not overflow a float.
std_vref=std_vref+ pow(((double)Vref[i_math]-mean_vref),2);
}
std_v=std_v/counter;
std_v=sqrt(std_v);
std_vref=std_vref/counter;
std_vref=sqrt(std_vref);
```

Is it possible to determine the time needed for this calculation?

Thanks a lot guys!