How to measure the time a smoke alarm LED flashes

Most probably, you will find a smoke alarm under your ceiling in your bedroom and elsewhere. Many of them will flash about once a minute. But as each flash takes some energy from the battery, may be you want to know how long does each single flash last.

Well, it's easy to fix a photodiode to the smoke alarm, connect it to an Arduino and call the pulseIn-function. But the pulseIn-function requires a digital input signal. And the brightness of the LED will not be strong enough to make the photodiode fully conductive and give a LOW value on a digital input.

So you can either use an amplifier and find out the trigger level.

Or you simply use an analog input.
By setting
ADCSRA = 132; // set prescale to 16
you can get more than 50,000 samples per second. Just upload this sketch and wait for the result to be printed:

// Sensor : BPX81
// Kathode: - A0
// Anode  : - Gnd 
// Hell   : 0
// Dunkel : 1
// Ergebnisse: 8592 ... 8616 Mikrosekunden

const byte sensor = A0;
const word LIMIT = 400;

void setup() {
  Serial.begin( 115200);
  ADCSRA = 132;

boolean wait4low = true;
long t1, t2;

void loop() {
  while (wait4low) {
    word x = analogRead(sensor); 
    if (x < LIMIT) {
      t1 = micros();
      wait4low = false;
  while (!wait4low) {
    word x = analogRead(sensor); 
    if (x >= LIMIT) {
      t2 = micros();
      wait4low = true;
  Serial.println(t2 - t1);    

contact: nji(at)