Ended upp with the following hookup,with an Active High circuit (following the left figure).
GND ---\
|
O 10k
|
D3 ----+------ 41
3v3 -----------42
```
This is my code:
```cpp
/*
Pulse counter to measure used kWh and calculate current W usage from a GM3D
*/
// According to EN62052-31 pulse lenght are ≥100ms <120 msec (ON)
byte minPulseWidth = 99;
unsigned long pulseTime=0;
volatile unsigned int pulseCount=0;
volatile unsigned long pulsePower=0;
void blink() {
if ( (millis() - pulseTime) > minPulseWidth) {
pulseCount++;
//GM3D outputs 100 pulses/kWh (60m*60s*1000ms*10 = 36'000'000)
pulsePower = 36000000 / (millis() - pulseTime);
pulseTime = millis();
}
}
void setup() {
pinMode(D3, INPUT);
attachInterrupt(D3, blink, RISING);
}
void loop() {
String data = "power:" + String(pulsePower)
+ ",count:" + String(pulseCount)
Spark.publish("data", data);
delay(5000);
}
```
The results looks pretty promising.
Thank you for all help!