Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Announcements
  3. 💬 Power Meter Pulse Sensor

💬 Power Meter Pulse Sensor

Scheduled Pinned Locked Moved Announcements
183 Posts 40 Posters 45.0k Views 37 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • asgardroA asgardro

    Done that... reset everything..still the same

    here is my code

    #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!)
    #define PULSE_FACTOR 1000 // Nummber of blinks per KWH of your meeter
    #define SLEEP_MODE false // Watt-value can only be reported when sleep mode is false.
    #define MAX_WATT 10000 // Max watt value to report. This filetrs outliers.
    #define CHILD_ID 1 // Id of the sensor child

    unsigned long SEND_FREQUENCY = 5000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
    bool pcReceived = true;
    volatile unsigned long pulseCount = 0;
    volatile unsigned long lastBlink = 0;
    volatile unsigned long watt = 0;
    unsigned long oldPulseCount = 0;
    unsigned long oldWatt = 0;
    double oldKwh;
    unsigned long lastSend;
    MyMessage wattMsg(CHILD_ID,V_WATT);
    MyMessage kwhMsg(CHILD_ID,V_KWH);
    MyMessage pcMsg(CHILD_ID,V_VAR1);

    void setup()
    {
    // Fetch last known pulse count value from gw
    request(CHILD_ID, V_VAR1);

    // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
    // If no pullup is used, the reported usage will be too high because of the floating pin
    pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP);

    attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING);
    lastSend=millis();
    }

    void presentation() {
    // Send the sketch version information to the gateway and Controller
    sendSketchInfo("Energy Meter", "1.0");

    // Register this device as power sensor
    present(CHILD_ID, S_POWER);
    }

    void loop()
    {
    unsigned long now = millis();
    // Only send values at a maximum frequency or woken up from sleep
    bool sendTime = now - lastSend > SEND_FREQUENCY;
    if (pcReceived && (SLEEP_MODE || sendTime)) {
    // New watt value has been calculated
    if (!SLEEP_MODE && watt != oldWatt) {
    // Check that we dont get unresonable large watt value.
    // could hapen when long wraps or false interrupt triggered
    if (watt<((unsigned long)MAX_WATT)) {
    send(wattMsg.set(watt)); // Send watt value to gw
    }
    Serial.print("Watt:");
    Serial.println(watt);
    oldWatt = watt;
    }

    // Pulse cout has changed
    if (pulseCount != oldPulseCount) {
      send(pcMsg.set(pulseCount));  // Send pulse count value to gw 
      double kwh = ((double)pulseCount/((double)PULSE_FACTOR));     
      oldPulseCount = pulseCount;
      if (kwh != oldKwh) {
        send(kwhMsg.set(kwh, 4));  // Send kwh value to gw 
        oldKwh = kwh;
      }
    }    
    lastSend = now;
    

    } else if (sendTime && !pcReceived) {
    // No count received. Try requesting it again
    request(CHILD_ID, V_VAR1);
    lastSend=now;
    }

    if (SLEEP_MODE) {
    sleep(SEND_FREQUENCY);
    }
    }

    void receive(const MyMessage &message) {
    if (message.type==V_VAR1) {
    pulseCount = oldPulseCount = message.getLong();
    Serial.print("Received last pulse count from gw:");
    Serial.println(pulseCount);
    pcReceived = true;
    }
    }

    void onPulse()
    {
    if (!SLEEP_MODE) {
    unsigned long newBlink = micros();
    unsigned long interval = newBlink-lastBlink;
    if (interval<10000L) { // Sometimes we get interrupt on RISING
    return;
    }
    watt = (3600000000.0 /interval) / ppwh;
    lastBlink = newBlink;
    }
    pulseCount++;
    }

    V Offline
    V Offline
    voxeg hult
    Banned
    wrote on last edited by
    #181

    @asgardro Thanks for your nice prompt feedback.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      ramisthand76
      Banned
      wrote on last edited by
      #182

      Pulse Power Measurement: Measuring Instantaneous Power of a Short Pulse. ... Thermopile sensors are often used to measure single shot pulse energy;

      1 Reply Last reply
      0
      • K keithellis

        I've been building one of these pulse meters up, it seems to be working on the bench very nice. Just got to build a case and get a power supply of the Arduino. But I have designed a case to hold the LM393 sensor onto the meter. I removed the light sensor and re-soldered it flush to the board making it easier to mount on the meter. Its a simple box but works quite well.

        IMG_0001.JPG

        IMG_0005.JPG

        IMG_0006.JPG

        The files are on thingiverse here

        Hope this is useful.

        F Offline
        F Offline
        FredC
        wrote on last edited by
        #183

        @keithellis Lovely idea.
        I've followed suit and knocked up one but with the sensor facing the other way, so that it faces the meter, and the preset pot is and LEDs are facing away from the meter.

        That way the sensor side of the case can be stuck to the face of the meter, and the pot adjusted without removing it from the meter. The flashing light on DO flashes in sync with the LED on the meter. Theres a little ring that holds the sensor flush with the face of the case so it can lie flat on the front of the meter.

        Also, its a good idea to use black / dark coloured PLA so as to block out the any stray light that may illuminate the sensor (such as when the meter man comes to read it and shines a bright torch to see the dials).

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        17

        Online

        11.7k

        Users

        11.2k

        Topics

        113.1k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular