emonTH reading external analog sensor (TCRT5000), signal on unexpected pin

That’s certainly another approach that Bert could take. The principal point I was making is 200 ms is way longer than necessary. LEDs light up in the order of microseconds or less, so ‘warm-up’ time is not significant. And I’m pretty sure you’re right about the S&H, otherwise there’s no point in having it! It should be possible to get an estimate of how long it is open from the maximum permitted drive impedance and the capacitor value.
Using interrupts allows the main loop of the sketch to carry on, and the presence or absence of the pulse drops straight into the present pulse-counting mechanism, which uses the ISR and which would otherwise have been triggered by the input pin from a reed switch.

hmmm… maybe I’m looking at the wrong code. Here’s what I found in his zip file above:


  //Enable sensor
  pinMode(TCRT5000_POWER_PIN,OUTPUT);
  digitalWrite(TCRT5000_POWER_PIN, HIGH);

  int analogSensorValue = analogRead(ANALOG_TCRT5000_PIN);

  //Disable sensor
  digitalWrite(TCRT5000_POWER_PIN, LOW);
  pinMode(TCRT5000_POWER_PIN, INPUT_PULLUP);

That looks to me to be powered on roughly the amount of time you’re suggesting with your ISR approach, possibly even less… I’d guess a little over 200 usecs if the CPU has just woken up.

@dBC, you are looking at the right code. I was indeed assuming that these five lines can be optimized using low level Arduino commands. The less clock cycles are consumed, and the less cycles the emitter stays on, the longer the battery will last, but I am unfortunately not an electronics expert :-S

The question is also how shaving of clock cycles in the sampling measures up against sending frames (now once every pulse=~25s or five minutes), the other logic and the processor deep sleep. I wish I was an engineer with the right equipment, as we say in Dutch: “meten is weten” (which means literally: “measuring is knowing”). Any ideas or intuitive feeling about this? :slight_smile:

For the record; this is how the code posted above performs battery wise.

The yellow graph is the EmonTH 2.0 TCRT5000 pulse counter (also transmitting temperature). Included for reference is the blue graph, which corresponds with a stock EmonTH 2.0 running on the same batteries (from the same package, installed at the same time)

1 Like