logo elektroda
logo elektroda
X
logo elektroda

How to connect ESP32 to FF LE-03D CT energy meter for pulse reading?

prezmulti 1473 28
Best answers

How do I connect an ESP32 to the F&F LE-03D meter so it can reliably read the pulse output without miscounting?

Connect the meter’s open-collector pulse output to an ESP32 GPIO with a shared GND, and read it with an interrupt on the falling edge [#21805729][#21805843] Because the ESP32’s internal pull-up is about 50 kΩ, it is better to use an external pull-up resistor, with 2 kΩ suggested and 4.7 kΩ also recommended as a starting value [#21805922][#21805964][#21805985] Do not add an RC capacitor filter, because that will smooth the pulses and can cause undercounting [#21805985] The miscounts are likely caused by the long cable acting like an antenna and picking up interference, so keep the wire as short as possible; shortening it to about 20 cm helped significantly in one test [#21805847][#21806290] The meter’s pulse output is specified as open collector, up to 27 V DC / 27 mA, with 300 imp/kWh and 35 ms pulse time, so no photoresistor or optocoupler is needed for this direct pulse input connection [#21805786][#21805991][#21806273]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21805620
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    Connection of ESP32 to F&F LE-03D CT energy meter

    I already have the code written and it counts the pulses, but I don't know how to connect this to the meter so that it reads the pulses from the meter
  • ADVERTISEMENT
  • #2 21805729
    kmarkot
    Level 31  
    Posts: 1364
    Help: 126
    Rate: 354
    Connect from the pulse output of the counter to the ESP under GND and the selected input D (GPIO).
  • #3 21805769
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    Yes, I know, but there is a problem with this connection because it miscounts the pulses coming out of the counter.
    Single pulses ok, but the problem is with a large number of pulses.
    There is a high current consumption at times (injection device) per day of more than about 1000 - 1300 kWh
  • #4 21805784
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    You have not written how this meter issues pulses according to the energy consumed. No one is going to look to the user manual for a hint.
  • #5 21805786
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    Counter data:
    pulse output
    type: open collector
    maximum voltage: 27 V DC
    maximum current: 27 mA
    pulsing constant: 300 imp/kWh
    pulse time: 35 ms
    operating temperature: -25 ÷ 55 °C
  • #6 21805799
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    This should not cause a speed problem. After all, 300 pulses pro kWh is very low. It's more likely to be other causes of incorrect counting. How do you adjust the 27 V signals to the logic level of the ESP?
  • #7 21805804
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    First directly connected S0- output to GND, S0 to ESP pin in my case 14 / second option via resistor with ceramic capacitor (there was already a similar topic on the forum somewhere)

    Directly overestimates the measurement and through the resistor underestimates the measurement.
  • ADVERTISEMENT
  • #8 21805823
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    And does this pin have a pull-up resistor?
  • #9 21805833
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    The ESP32 has internal pull-up resistors that can be activated by software (e.g. in Arduino via INPUT_PULLUP), which simplifies the connection of buttons and sensors: simply connect a pin to GND or an open-drain output signal; multiple pins (e.g. GPIO2, 4, 5, 12, 13, 14, 15, 25, 26, 27).

    In my code pinMode(PULSE_PIN, INPUT_PULLUP).
  • #10 21805838
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    How do you count these pulses? The easiest way is to use the interrupt function. What is the length of the wires between the counter and the ESP?
  • ADVERTISEMENT
  • #11 21805843
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    attachInterrupt(digitalPinToInterrupt(PULSE_PIN), onPulse, FALLING);


    Yes, I have in my code

    Cable length: 2 m, 2 x 0.5 mm
  • #12 21805847
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    The extra interrupt (i.e. extra pulses) can be caused by signal interference. Two metres is already a piece of antenna.
  • #13 21805856
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    So do I have to do the ESP right at the counter, and do I use an additional resistor with a capacitor?

    How many milliseconds to set?
    if (now - lastPulseTime > 20) - I tried various
  • #14 21805861
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    prezmulti wrote:
    if (now - lastPulseTime > 20)

    And that didn't pass the test and change the measurement results to some extent?
  • ADVERTISEMENT
  • #15 21805868
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    It didn't change, I can't remember exactly, but with all the tests I did, there was a misrepresentation of about 30% to the meter readings.

    For a test I connected through a second meter but directly a heating furnace of about 10 kW and the esp without any additional resistor or capacitor) showed a measurement flush with the meter at 150 ms

    Added after 1 minute:

    The fact was that I had a short section of cable
  • #16 21805922
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    It seems to me that using an internal pull-up resistor is not a very good idea. The value of this resistor is about 50 kΩ, which means a small current flows in the loop. According to the SO standard, the ideal current is 10-20 mA.
  • #17 21805956
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    So now what can I do according to you? I've recently started my adventure with ESP, I'm also not so super familiar with it
  • #18 21805964
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    First try using an external resistor of ≈ 2 kΩ and see if that does anything. I don't know if this is an international standard, but according to the descriptions, some meters have this output circuit.
    Attachments:
    • How to connect ESP32 to FF LE-03D CT energy meter for pulse reading? Screenshot 2026-01-11 212946.png (65.91 KB) You must be logged in to download this attachment.
  • #19 21805977
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    Ok. If I have time tomorrow, I'll give it a try

    And another question: because I was thinking of using a phototransistor to peak the pulses from the diode on the counter. Is this a good idea?
  • #20 21805985
    michal.zd
    Level 31  
    Posts: 1615
    Help: 83
    Rate: 263
    prezmulti wrote:
    Directly overestimates the measurement and through the resistor underestimates the measurement

    The use of a resistor and capacitor as long as there is a connection as I think (no diagram, you would paint) amounts to a low pass filter. It's not surprising that it underestimates. I'm surprised it overestimates directly without that filter.
    Maybe you have too long wires from the meter to your module. Together with the rather high resistance inside the pullup (I don't remember how many kiloohms, colleagues above stated) the wires pick up interference, or even oscillations occur. Adding
    inot wrote:
    an external resistor of ≈ 2 kΩ

    It should help, but I would start with a larger value, such as 4.7k.
    prezmulti wrote:
    do I use an additional resistor with a capacitor ?

    no.
  • #21 21805989
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    An optocoupler can be used, but then an additional voltage is needed.
  • #22 21805991
    michal.zd
    Level 31  
    Posts: 1615
    Help: 83
    Rate: 263
    prezmulti wrote:
    using a phototransistor to peak the pulses from the diode on the counter. Is this a good idea ?

    You have a ready-made output, unnecessary complications.

    Added after 1 [minute]:

    inot wrote:
    You can use an optocoupler

    You can, but you also don't need one.
  • #23 21806048
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    prezmulti wrote:
    read the pulses from the diode on the counter

    How do you understand this? Present it visually.
  • #25 21806088
    inot
    Level 38  
    Posts: 3505
    Help: 434
    Rate: 785
    It doesn't make sense. What would you illuminate the photo-optic element with?
  • #26 21806095
    kmarkot
    Level 31  
    Posts: 1364
    Help: 126
    Rate: 354
    >>21805729
    I have a flow meter built for the CO system the cable from the wemos D1 to the flow sensor is 1.2m long and counts well there are no other electromagnetic fields nearby.
  • #28 21806273
    ArturAVS
    Moderator
    Posts: 26009
    Help: 2295
    Rate: 7712
    prezmulti wrote:
    as someone glued a photoresistor, sub

    Photoresist is too slow in such an application. @michal.zd @inot You are well advised. By the way, you can use e.g. KWS-303WF and have the measurement data ready.
  • #29 21806290
    prezmulti
    Level 7  
    Posts: 42
    Rate: 5
    I forged the cable to 20 cm, helped considerably, but the ESP underestimates 4 kWh per 100 kWh on the meter
    That is, ESP 96 kWh and the meter 100 kWh

    Added after 4 [hours] 23 [minutes]:

    Another trial with millisecond change went promisingly. On two meters, 50 kWh each. We'll see tomorrow morning how it goes.

FAQ

TL;DR: ESP32 has 8 hardware pulse-counter channels; “On the ESP32, this sensor is highly accurate.” Wire the meter’s S0 pulses to a safe, logic‑level input and use filtering. Pulse Counter Sensor — ESPHome [Pulse Counter Sensor — ESPHome] Why it matters: This FAQ shows makers how to safely read S0 pulses from an F&F LE‑03D CT with an ESP32, avoiding damaged GPIOs and bad readings.

Quick Facts

  • LE‑03D family S0 output is open‑collector, <30 V DC, <27 mA; pulse width approx. 90 ms. [Licznik LE‑03d—Kontaktuj.pl]
  • Example meter constant: 800 imp/kWh; read the device label to compute kWh from pulses. [Licznik LE‑03d—Kontaktuj.pl]
  • ESP32 PCNT peripheral: up to 8 channels; hardware counting improves accuracy. [Pulse Counter Sensor — ESPHome]
  • For S0 pulse meters, use 50–100 ms input filtering to reject bounce/noise. [Pulse Counter Sensor — ESPHome]

What’s the safe way to connect an ESP32 to the LE‑03D CT S0 pulse output?

Treat S0 as an open‑collector loop, not a logic pin. Use a 3.3 V source and an optocoupler: drive the opto LED through a resistor from SO+ to SO−, then connect the opto transistor to an ESP32 GPIO with a 10 kΩ pull‑up to 3.3 V and common ground. This isolates the ESP32 from up to 30 V loops and respects the meter’s <27 mA S0 rating and ~90 ms pulse. [Licznik LE‑03d—Kontaktuj.pl]

Can I just wire the counter’s pulse output to ESP32 GND and a GPIO?

A forum reply suggests connecting the counter’s pulse output between ESP32 GND and a chosen GPIO. That can work only if the pulse is already at safe logic level and you enable a pull‑up. If the loop runs above 3.3 V, add isolation or level limiting. “Connect from the pulse output of the counter to the ESP under GND and the selected input D (gpio).” [Elektroda, kmarkot, post #21805729]

Do I need a pull‑up resistor, or can I use ESP32’s internal pull‑up?

For a direct, 3.3 V‑only connection, enable the ESP32’s internal pull‑up on the GPIO and count falling edges. External 10 kΩ to 3.3 V also works if your framework doesn’t control pulls. Configure count mode and add input filtering to stabilize readings from S0 pulses. [Pulse Counter Sensor — ESPHome]

What input filter should I set for S0 pulses from this meter?

Use 50–100 ms to match typical S0 pulse durations and reject glitches. The LE‑03D family lists ~90 ms pulses, so a 50–100 ms digital filter avoids double counts while preserving events. Set rising disabled and count on the falling edge if you filter. [Pulse Counter Sensor — ESPHome]

How many S0 channels can an ESP32 count at once?

Up to eight channels when you use the ESP32’s hardware pulse counter (PCNT). This offloads counting from the CPU and maintains accuracy at higher rates. That’s enough for multiple meters or multi‑tariff inputs on one board. [Pulse Counter Sensor — ESPHome]

How do I convert pulses to kWh for the LE‑03D family?

Read the constant on the meter label (example: 800 imp/kWh). Compute energy as kWh = pulses ÷ (imp/kWh). Example: 800 pulses equals 1.0 kWh at 800 imp/kWh. Store the constant in firmware so calculations match your exact model. [Licznik LE‑03d—Kontaktuj.pl]

What is an S0 pulse output, in plain terms?

It’s a two‑wire open‑collector interface defined by a standard. The meter briefly sinks current to signal each energy quantum. Typical limits are 27 V and 27 mA, so you must provide the loop voltage and a pull‑up or use galvanic isolation. [S0 Pulse Outputs — Carrel Electrade]

What happens if I connect a 12–27 V S0 loop straight to an ESP32 pin?

You risk destroying the GPIO. S0 loops can be up to 27 V and tens of milliamps. ESP32 pins tolerate only 3.3 V. Use an optocoupler or level shifter, then feed a clean 3.3 V signal to the ESP32. [S0 Pulse Outputs — Carrel Electrade]

Is there a quick 3‑step setup to start counting pulses on ESP32?

  1. Wire S0 through an optocoupler to an ESP32 GPIO with a 10 kΩ pull‑up to 3.3 V.
  2. In firmware, enable PCNT on that GPIO, count falling edges, set a 50–100 ms filter.
  3. Divide accumulated pulses by the meter’s imp/kWh constant to get kWh. [Pulse Counter Sensor — ESPHome]

What statistic matters for planning my project’s inputs?

ESP32 provides eight hardware pulse‑counter channels. Design your input map around that ceiling. Quote: “On the ESP32, this sensor is even highly accurate because it’s using the hardware pulse counter.” [Pulse Counter Sensor — ESPHome]

What did the original poster ask in the thread?

They had code counting pulses but did not know how to connect the ESP32 to the F&F LE‑03D CT pulse output. This FAQ addresses wiring, isolation, filtering, and conversion to kWh so that code can work with real hardware. [Elektroda, prezmulti, post #21805620]

What is Tuya?

Tuya is an IoT platform and ecosystem used by many smart‑home devices, offering cloud services, mobile apps, and embedded SDKs for connectivity and control. [About Tuya — Tuya]

What is Arduino Nano?

Arduino Nano is a compact, breadboard‑friendly microcontroller board compatible with Arduino tooling, widely used in education and prototyping for simple sensor and control tasks. [Arduino Nano — Wikipedia]

What is OpenBeken?

OpenBeken is an open‑source firmware that replaces cloud‑tied firmware on certain Wi‑Fi IoT devices, enabling local control, MQTT, and customization without vendor lock‑in. [OpenBeken — GitHub]

What is CAN bus?

Controller Area Network (CAN) is a robust multi‑master serial bus for real‑time communication in vehicles and industry, with message arbitration and error handling at the data‑link layer. [Controller Area Network — Wikipedia]
Generated by the language model.
ADVERTISEMENT