TCRT5000: ESP8266 is not getting every impulse

Hi everyone,
I use a TCRT5000 to read the IR-diode from my EMH power meter. The manual of the power meter says, every light impulse is 2 ms and 10000 Imp/kWh.
So I installed the TCRT5000 in front of the IR diode. With help of the poti and the onboard output-LED I was able to change the sensitivity of the reading-diode to the correct level. The output LED on the board blinks regularly, depending on my energy consumption.
Somehow, not every impulse from the TCRT5000 gets to my ESP8266. I double-checked it with an additional LED that is connected to the ESP and the logs. Just 1 of 3 or 1 of 5 impulses of the TCRT5000 is registered by the ESP on no regular basis.

A pullup resistance is not necessary because the TCRT has one integrated.
On the same ESP I use almost the same code to read a gas meter with a reed switch. I filter this input with a delay of 10 ms. Deactivation of the filter did not change a thing.

Do you have a hint for me? Here is my config.

globals:
# Stromzähler
  - id: total_pulses_power
    type: int
    restore_value: false
    initial_value: '0'

# Stromzähler Pin D2
binary_sensor:
  - platform: gpio
    id: internal_pulse_counter_power
    pin:
      number: GPIO4
#      mode: INPUT_PULLUP
    name: "Live-Impuls-Power"
#    filters:
#      - delayed_on: 1ms
    on_press:
      then:
        - lambda: id(total_pulses_power) += 1;
        - output.turn_on: led_power
    on_release:
      then:
        - output.turn_off: led_power

sensor:
# Stromzähler
  - platform: template
    name: "Stromverbrauch"
    device_class: power
    unit_of_measurement: "Wh"
    state_class: "total_increasing"
    icon: "mdi:flash"
    accuracy_decimals: 3
    lambda: |-
      return id(total_pulses_power) * 0.1;

output:
# Stromzähler Pin D4
  - platform: gpio
    pin: GPIO2
    id: 'led_power'

Has anyone an idea why the ESP8266 does not see every output but some? Are 2ms too short? Is the mistake that I count the gas meter’s pulses on the same ESP?

Have you tried removing the commands to turn the LED on/off?

Thank you for your reply. Yes, I checked it, it did not change a thing.

So to be clear: the output LED on the board blinks in sync with the pulses generated by your smart meter, it’s just that the ESP isn’t counting all of the pulses?

Have you considered using a pulse counter instead? It seems to fit your setup better.

I installed a normal switch, it works perfectly, even on short signals. So I think that the TCRT5000 is broken. I ordered a new one and check this.

I tried the pulse counter and pulse meter on my gas meter project and had some issues. So I came back to the binary sensor.
On this setup I haven’t used pulse counter nor pulse meter.

Today I have received new TCRT5000. Unfortunately it didn’t help, my problem continues.
I tested a new thing: When I change the potentiometer on the TCRT5000 to “very sensitive”, the ESP sees the high-signal. On “not sensitive” the ESP sees the low-signal.
What does this mean? It means, that the wiring, TCRT5000 and ESP are ok.
Could it be, that 2 ms high-signal are simply too short for either TCRT5000 or ESP? Is there a way to make the high-signal “longer”? I’m not too familiar with MCs…

Again, I would suggest trying to get the pulse counter or meter to work. Given that its internal filter is configured by default to ignore pulses shorter than 13us, a 2ms pulse width doesn’t sound like it should be a problem.

Hi Robert, thank you for your help. Problem solved. I tried the pulse meter and it works! Sadly I have no idea what went wrong, because my gas meter works better with binary sensor config.

Here is my config now: Home Assistant: Digitalen Stromzähler mit ESPHome auslesen | Smart Home | 2022 | bejonet

1 Like