Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Arduino & monitoring electricity meter using pulses

  • 05-04-2014 9:06pm
    #1
    Registered Users, Registered Users 2 Posts: 2,501 ✭✭✭


    I'm trying to monitor usage on my electricity meter using the pulse output on it. This should be relatively straight forward, but I'm getting intermittent/no results and I'm a little stumped.

    Safety first - before I started sticking wires into the meter I obtained and checked the documentation and got my electrician to confirm the terminals I was connecting to were not live - as the documentation said. Sticking wires into the wrong part of the meter is *very bad*, so don't try this unless you know what you are doing.

    The connectivity is like this : arduino 5v -> meter input terminal -> switch inside meter -> meter output terminal -> arduino digital pin

    The basic model is that you supply 5v (between 5 & 30 volts according to the manual) and every time the meter measures 1kW it completes the circuit and you can measure 5v on the relevant pin on the arduino. You can tell the meter is measuring 1kW also because it flashes a LED on the meter itself.

    The documentation out there on the web is relatively limited - possibly because there's so little to the circuit. Some diagrams suggest using a 10k resistor. I've tried with & without.

    One of the configurations at least produced some results, but it wasn't consistent. Not even slightly consistent. The others didn't even make a squeak - nothing on the serial console at all.

    One of the possibilities I've considered (not referenced in the articles I've read before) is that there is enough interference or cross-over or something from the mains cables to mess up the signal. However, since we're measuring power at the mains, it's kind of a done deal that we're going to be near mains cables.

    Has anyone managed to wire up an arduino to the pulse output on a meter and got any experience or hints to pass on?

    z

    [edit] the 5v is coming from the arduino and it's getting power over USB from the laptop - is it possible that the USB power is the problem and 5v direct to the arduino might help?


Comments

  • Registered Users, Registered Users 2 Posts: 2,320 ✭✭✭Chet T16


    Can you post your code?

    What inconsistencies would you say you're getting?


  • Registered Users, Registered Users 2 Posts: 2,501 ✭✭✭zagmund


    Thanks for replying. Actually, while looking for a bit of code to reference a while back, I came across another bit, tried it & it worked. Result. I had tried other snippets from the Arduino playground and a couple of other sources. The inconsistencies were in terms of results coming back sometimes but not others. Meaning - I could see a pulse on the LED on the meter, but nothing on the console.

    The code below worked for me using this layout -
    S+
    +5V
    S-
    +---< R1 >
    GND R1 = 10K
    |
    |
    IRQ0
    PIN2 arduino
    Above diagram isn't rendering properly, but the connection to PIN2 is taken off at the '+' in the diagram before the resistor (if that makes any difference).
    /*
    * FILE: KWh monitoring
    * AUTHOR: Rob Tillaart
    * DATE: 2010 03 31
    * URL: http://playground.arduino.cc/Main/EEM12L-32AKWhMonitoring
    *
    * PURPOSE: prototype KWh monitoring
    *
    * Digital Pin layout ARDUINO
    * =============================
    * 2 IRQ 0 - to KW meter EEM12L-32A
    *
    * This KWh meter gives a pulse every 0.5 Watt
    */

    //
    // KWH SENSOR CODE
    //
    // TODO - make a class
    //
    volatile unsigned long rpk = 0; // raw pulse KWH counter (private)
    volatile unsigned long rpk_old = 0; // value of last read (private)
    volatile boolean CS_KWH = false; // Critical Section for KWH meter (private)

    // The interrupt routine
    void Kirq()
    {
    rpk++; // just increment raw pulse counter.
    if (rpk > 1000000000) // reset pulse counter after 10e9 pulse = 500.000 KW
    {
    if (false == CS_KWH) // in critical section? // assumption IRQ-call is handled atomic on arduino.
    {
    rpk -= rpk_old;
    rpk_old = 0;
    }
    }
    }

    // returns KWH's since last reset
    float readKWH1()
    {
    return rpk/2000.0; // one pulse = 0.5 watt.
    }

    // returns KWH's since last call
    float readKWH()
    {
    CS_KWH = true; // Start Critical Section - prevent interrupt Kirq() from changing rpk & rpk_old ;
    long t = rpk; // store the raw pulse counter in a temp var.
    long k = t - rpk_old; // subtract last measure to get delta
    rpk_old = t; // remember old value
    CS_KWH = false; // End Critical Section
    return k/2000.0; // return delta, one pulse = 0.5 watt.
    }

    //
    // SETUP
    //
    void setup()
    {
    Serial.begin(9600);

    // KWH interrupt attached to IRQ 0 = pin2
    attachInterrupt(0, Kirq, FALLING);
    }

    //
    // MAIN LOOP
    //
    void loop()
    {
    delay(1000);
    float KWH = readKWH();
    float SUM = readKWH1();
    Serial.print("KWH: ");
    Serial.print(KWH, 4);
    Serial.print(" ");
    Serial.println(SUM, 4);
    }

    //
    // END OF PROGRAM
    //


  • Registered Users, Registered Users 2 Posts: 2,320 ✭✭✭Chet T16


    That code seems slightly over complicated to me. Unless you're doing a lot of other stuff at the same time you don't need to use an interrupt. That said, there's no harm.

    I don't know how the switched pulse output works on the meter but maybe it's an idea to attach a multimeter in continuity mode to the terminals to make sure it's working correctly. Or even a simple battery + buzzer circuit.


  • Registered Users, Registered Users 2 Posts: 5,401 ✭✭✭DublinDilbert


    I'd imagine the output of the meter is an isolated "dry" contact of some sort. So probably a 10k pull up to 5v on the arduino will give you a nice square wave out.

    As poster above says you can use an interrupt or poll (repeatedly check) in software it's status.


  • Registered Users, Registered Users 2 Posts: 2,501 ✭✭✭zagmund


    Thanks for the feedback to date. I'll be monitoring 9 meters, so the device will be busy enough. From what I've read on the openenergymonitor.org pages, interrupts & directly reading registers will be required rather than reading the pins. I can't find the page at the moment, but they had a sketch there for reading up to 12 devices in this way.

    z


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,320 ✭✭✭Chet T16


    It depends how long the contacts are closed. If it's the same as whatever is driving the LED then I can't see any problem in checking each input pin sequentially


  • Registered Users, Registered Users 2 Posts: 1,974 ✭✭✭whizbang


    i dont know enough about the Arduino, but

    - do you need to debounce the input in software?
    - would it be better to use the rising edge as trigger?


  • Registered Users, Registered Users 2 Posts: 2,320 ✭✭✭Chet T16


    whizbang wrote: »
    i dont know enough about the Arduino, but

    - do you need to debounce the input in software?
    - would it be better to use the rising edge as trigger?

    From my (limited) reading it sounds like it's a solid state output so shouldn't need debouncing. Either way I'd be ignoring anything for half a second after seeing a rising edge.


  • Registered Users, Registered Users 2 Posts: 2,501 ✭✭✭zagmund


    Here's the blog that got me going down this route - http://blog.mrossi.com/2013/10/arduino-pulse-counting-with-multiple.html.

    It's pretty much exactly what I need to be doing. I just have to work out how to wire it up properly to get multiple meters, but I have the basics working with a single meter.

    I had been meaning to investigate emoncms which is referenced in the blog above. It looks like they have now improved the install for this and made it very easy. I installed it and was feeding temperature readings into it within 30 minutes or so. I will be feeding electricity meter readings in once I get myself a second arduino network shield - my current spare one is kaput.

    In terms of frequency of reading - when the washing machine is on the LED blinks 3, 4, 5 times a second so I *think* interrupts are the way to go. Alternatively, if I can't capture all the pulses I can at least take it that consumption is very high (without worry about the specifics) when there are more than 2 per second, or more than 60 per minute or some similar threshold

    z


Advertisement