2 Power meters combine to one led pulse

Hi All,

I'm not good in programming so I was wondering if some one already made a script or can help me with it.

I have 2 power (kWh) meters with a S0 output.
I would like to have a script that reads the energy usage from the 2 power meters, and combine them to 1 led pulse output.

On the led output I will put a sensor of a Toon Thermostaat.

Can some one help me?

Hardware:
D1 mini or nodeMCU.
2 kWh meters with S0 output. (or led)
Restistor to at on the S0 output
Led or onboard led.

SO interface explains how to determine the resistor

couldn't find a description of the EN 62053-31 interface

The resistor is not necessary

URL: https://duino4projects.com/reading-pulses-meters-pulse-outputs-using-arduino/

Googling

arduino pulse output power meter

turns up the page you stole took the diagram you posted from.

Links on that page lead to code examples.

a7

Thanks.

Yes this script is counting the pulses from power meters.
https://openenergymonitor.org/forum-archive/node/123.html

But how can I make an output to one led pulse?

Hi,

You are reading energy signals from the S0 output.
What do you want the output LED to do?

Tom... :grinning: :+1: :coffee: :australia:

I would like to combine the 2 power meters.

If power meter 1 does 1000 watts (1000 pulses a minute) and power meter 2 does 1000 watts (1000 pulse per minute) the d1 mini has to combine it to 2000 pulses a minute.

I monitor my solar panels (2 solar inverters in different phases) with a toon thermostaat. This thermostaat has 1 sensor that you put on the led output of 1 power meter. It does not support 2 power meters.

Hi,
What is a "toon thermostaat" ?
And what does it do?

Tom... :grinning: :+1: :coffee: :australia:

A Toon thermostat is a smart device to control the heating of your house.
You can program it. In the morning the room temperature has te be 21 degree and at night 19 degree etc. It is also a screen where you can monitor your solar panels etc.

Unfortunately it is not smart enough to support 2 power meters. :slight_smile:

//Print the values.
Serial.print(power,3); // meter A
Serial.print(" ");
Serial.print(elapsedkWh,3); //meter B
Serial.print(" ");
Serial.println(power + elapsedkWh  ); //A+ B

Thanks 79galinakorczak!

Is the output going to the led? Or will it show it on screen?

This should do it. One LED pulse for each pulse on either meter.

//Number of pulses, used to measure energy.
volatile byte pulseCount = 0;

const byte Meter1Pin = 2; // External Interrupt Pin
const byte Meter2Pin = 3; // External Interrupt Pin
const byte LEDPin = LED_BUILTIN;

void onPulse()
{
  pulseCount++;
}

void setup()
{
  // KWH interrupts attached to external interrupts
  attachInterrupt(digitalPinToInterrupt(Meter1Pin), onPulse, FALLING);
  attachInterrupt(digitalPinToInterrupt(Meter2Pin), onPulse, FALLING);
}

void loop()
{
  bool pulse = false;

  noInterrupts();
  if (pulseCount > 0)
  {
    pulse = true;
    pulseCount--;
  }
  interrupts();

  if (pulse)
  {
    // LED pulse rate is limited to 50 pulses per second, max. 
    // = 50 Wh per second
    // = 3000 Wh per minute
    // = 180 kWh per hour
    // = 180 kW
    // = over 800 Amps at 220 Volts, 1600 Amps at 110 Volts
   // Should be fast enough for any home system
    digitalWrite(LEDPin, HIGH);
    delay(10);
    digitalWrite(LEDPin, LOW);
    delay(10);
  }
}

Wauw! Thanks a lot!
I will try this script as soon as possible.

I uploaded the code to a nodemcu with . When i power the nodemcu the onboard led is flashing about 120 times/minute.

I tried also another simple code, that blinks an external led. That works fine, so the nodemcu is working.
What am I doing wrong?

If you don't have anything connected to the two input pins they are probably picking up noise. It may be necessary to set the pinMode() on those two pins to INPUT_PULLUP.

The number will shows on serial monitor, this is just example how to add two numbers

Thx!
I uploaded the following:

//Number of pulses, used to measure energy.
//Source https://forum.arduino.cc/t/2-power-meters-combine-to-one-led-pulse/854753/10
//Made by johnwasser

volatile byte pulseCount = 0;

const byte Meter1Pin = 5; // External Interrupt Pin //D1 GPIO5
const byte Meter2Pin = 4; // External Interrupt Pin //D2 GPIO4
const byte LEDPin = LED_BUILTIN;

void onPulse()
{
  pulseCount++;
}

void setup()
{
  // KWH interrupts attached to external interrupts
  attachInterrupt(digitalPinToInterrupt(Meter1Pin), onPulse, FALLING);
  attachInterrupt(digitalPinToInterrupt(Meter2Pin), onPulse, FALLING);
  pinMode (5 , INPUT_PULLUP); //D1 GPIO5
  pinMode (4 , INPUT_PULLUP); //D2 GPIO4
}

void loop()
{
  bool pulse = false;

  noInterrupts();
  if (pulseCount > 0)
  {
    pulse = true;
    pulseCount--;
  }
  interrupts();

  if (pulse)
  {
    // LED pulse rate is limited to 50 pulses per second, max. 
    // = 50 Wh per second
    // = 3000 Wh per minute
    // = 180 kWh per hour
    // = 180 kW
    // = over 800 Amps at 220 Volts, 1600 Amps at 110 Volts
   // Should be fast enough for any home system
    digitalWrite(LEDPin, HIGH);
    delay(10);
    digitalWrite(LEDPin, LOW);
    delay(10);
  }
}

After uploading the led is still flashing. (Nothing connected) (Tried first pin1 and 2, some problem)
I think pin5 in the script is D1 GPIO5 of the nodemcu and pin6 = GPIO6?
If I connect GPIO 5 and 6 to ground with a resistor the led is still flashing.

I think this is better, but the led is still flashing.

//Number of pulses, used to measure energy.
//Source https://forum.arduino.cc/t/2-power-meters-combine-to-one-led-pulse/854753/10
//Made by johnwasser

uint8_t LED_Pin = D4;       // declare LED pin on NodeMCU Dev Kit

volatile byte pulseCount = 0;

const byte Meter1Pin = D1; // External Interrupt Pin //D1 GPIO5
const byte Meter2Pin = D2; // External Interrupt Pin //D2 GPIO4
const byte LEDPin = LED_BUILTIN;

void onPulse()
{
  pulseCount++;
}

void setup()
{
  pinMode(LED_Pin, OUTPUT);   // Initialize the LED pin as an output
  pinMode (D1 , INPUT_PULLUP); //D1 GPIO5
  pinMode (D2 , INPUT_PULLUP); //D2 GPIO4
  // KWH interrupts attached to external interrupts
  attachInterrupt(digitalPinToInterrupt(Meter1Pin), onPulse, FALLING);
  attachInterrupt(digitalPinToInterrupt(Meter2Pin), onPulse, FALLING);
}

void loop()
{
  bool pulse = false;

  noInterrupts();
  if (pulseCount > 0)
  {
    pulse = true;
    pulseCount--;
  }
  interrupts();

  if (pulse)
  {
    // LED pulse rate is limited to 50 pulses per second, max. 
    // = 50 Wh per second
    // = 3000 Wh per minute
    // = 180 kWh per hour
    // = 180 kW
    // = over 800 Amps at 220 Volts, 1600 Amps at 110 Volts
   // Should be fast enough for any home system
    digitalWrite(LEDPin, HIGH);
    delay(10);
    digitalWrite(LEDPin, LOW);
    delay(10);
  }
}

Hi,
Do you have anything connected to the inputs?
What happens if you gnd the inputs to the controller?

Can you please post a picture of your project, so we can see your component layout?

Tom... :grinning: :+1: :coffee: :australia:

You should use the assigned names for pins, not the pin number:

  pinMode (Meter1Pin , INPUT_PULLUP);
  pinMode (Meter2Pin , INPUT_PULLUP);

The Arduino functions like pinMode() and attachInterrupt() ALWAYS use Arduino Pin Numbers. Your NodeMCU has pins labeled D1, D2, D3... so use those names.

The Arduino numbers do not match physical pin numbers (counting counterclockwise around the chip) or the numbers used in Direct Register Access (like GPIO5).

D1 and D2 are the Wire/TWI/I2C pins (SDA&SCL). As long as you are not using Wire.h they should be fine.

If you have a real Arduino clone available you could try the sketch on it. Perhaps there is something strange in the ESP8266 core.