Translated from Türkçe by AI ·
Most of these plugs have an HLW8012 or its clone BL0937, 8 legs, and the pins you described match exactly. I used the same chip modules in water pump panels at the municipality, and this is how it works:
- CF (your pin 5): pulse output whose frequency is proportional to active power.
- CF1 (pin 4): depending on the SEL pin, a pulse proportional to either current or voltage.
- SEL (pin 6): selection pin going from the logic board to the chip. On HLW8012 SEL=1 is current, on BL0937 it’s the opposite, and if you mix these up the values come out nonsense.
It’s easy to read: connect the two pins to an interrupt, count pulses in a 1 second window. For power, roughly:
volatile uint32_t cfPulses = 0;
void IRAM_ATTR onCF() { cfPulses++; }
// setup:
attachInterrupt(digitalPinToInterrupt(PIN_CF), onCF, RISING);
// every second:
noInterrupts(); uint32_t n = cfPulses; cfPulses = 0; interrupts();
float power_w = n * powerFactor; // kalibrasyonla bulunacak
energy_wh += power_w / 3600.0;
Find the powerFactor value with a known load: plug in a 100 W heater or an incandescent bulb, divide the counted pulses by the real power. For voltage, do the same by changing SEL and using CF1.
Safety: when uploading the code, unplug the socket from the mains, program the ESP32-C3 via USB, then disconnect and plug it back in. Connecting to the mains while USB is attached means connecting your computer to the mains. Do the calibration by watching the log over Wi-Fi.
Send a energy_wh counter that increases, together with power_w, to Hermetry; getting the daily consumption from the counter later is much cleaner.
Bu prizlerin çoğunda HLW8012 ya da onun kopyası BL0937 var, 8 bacak ve tarif ettiğin pinler tam uyuyor. Ben belediyede su pompası panolarında aynı entegreli modüller kullandım, şöyle çalışıyor:
- CF (senin 5. pin): frekansı aktif güçle orantılı darbe çıkışı.
- CF1 (4. pin): SEL pinine göre ya akım ya gerilimle orantılı darbe.
- SEL (6. pin): lojik karttan entegreye giden seçim pini. HLW8012’de SEL=1 akım, BL0937’de tersi, bunu karıştırınca değerler saçma çıkıyor.
Okuması kolay: iki pini kesmeye bağla, 1 saniyelik pencerede darbe say. Güç için kabaca:
volatile uint32_t cfPulses = 0;
void IRAM_ATTR onCF() { cfPulses++; }
// setup:
attachInterrupt(digitalPinToInterrupt(PIN_CF), onCF, RISING);
// her saniye:
noInterrupts(); uint32_t n = cfPulses; cfPulses = 0; interrupts();
float power_w = n * powerFactor; // kalibrasyonla bulunacak
energy_wh += power_w / 3600.0;
powerFactor değerini bilinen bir yükle bul: 100 W’lık bir ısıtıcı ya da akkor ampul tak, sayılan darbeyi gerçek güce böl. Gerilim için de aynısını SEL’i değiştirip CF1’den yap.
Güvenlik: kodu yüklerken prizi şebekeden çek, ESP32-C3’ü USB ile programla, sonra kapat ve tak. USB bağlıyken şebekeye takmak, bilgisayarını şebekeye bağlamak demek. Kalibrasyonu da Wi-Fi üzerinden log izleyerek yap.
Hermetry’ye power_w ile birlikte artan bir energy_wh sayacı gönder, sonradan günlük tüketimi sayaçtan almak çok daha temiz oluyor.

