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.
  • gohanG Offline
    gohanG Offline
    gohan
    Mod
    wrote on last edited by
    #132

    Are you getting instant power measurements correct?

    1 Reply Last reply
    0
    • xydixX Offline
      xydixX Offline
      xydix
      wrote on last edited by xydix
      #133

      Yes. I guess.
      I don't have anything to compare with but i think it is accurate.
      I have a 1000blink/kwh
      Example:
      Node send state every 20 sec.
      pulsecount: 8 pulses every 20 sec.
      Instant power in W is about 1400W

      8 pulses x 3 = pulses /minute =24
      24 pulses x 60 min = pulses /hour = 1440.

      Edit.
      Now I get a new value every 20 sec, before I didn't get any value (W) from the node at all because it was too high. I only received pulse count and kWh earlier.

      1 Reply Last reply
      0
      • gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by
        #134

        Besides the cap, what exactly did you do?

        1 Reply Last reply
        0
        • xydixX Offline
          xydixX Offline
          xydix
          wrote on last edited by
          #135

          Nothing more.
          I use the same arduino, haven't uploaded anything new to it since i tried it last time.

          What I had to do was lower the sensitivity on the LM393 because at first the signal-LED glowed a bit but when i adjusted it to lower sensitivity and closed the door to get it totaly dark the led blinked exactly as the meeter.

          I have it on a bredboard and connected the cap between GND and to pin 3 so it is connected close to the arduino but i guess it shouldn't matter.

          Have you tried it?

          1 Reply Last reply
          0
          • gohanG Offline
            gohanG Offline
            gohan
            Mod
            wrote on last edited by
            #136

            I can't believe it, IT WORKS!!!!! I added the cap directly under the pins of the LM939 board. Thanks man!

            1 Reply Last reply
            0
            • xydixX Offline
              xydixX Offline
              xydix
              wrote on last edited by
              #137

              I am glad to hear it works for you too.

              1 Reply Last reply
              0
              • gohanG Offline
                gohanG Offline
                gohan
                Mod
                wrote on last edited by
                #138

                There is probably a sw way to correct this problem, I'll think about it

                1 Reply Last reply
                0
                • xydixX Offline
                  xydixX Offline
                  xydix
                  wrote on last edited by xydix
                  #139

                  It waswhat I thought too.
                  As I said earlier, when I tested this my conclusion was, short blink, almost a flash will counted as a pulse (kWh) but it does something wrong with the calculation of instant power usage.
                  A slower blink will correct this.
                  My meeter gives a very short blink.

                  1 Reply Last reply
                  0
                  • gohanG Offline
                    gohanG Offline
                    gohan
                    Mod
                    wrote on last edited by gohan
                    #140

                    Yes, could be that a simple debounce could do the trick but I'll have to look deeper into it. @Yveaux what do you think?

                    1 Reply Last reply
                    0
                    • gohanG Offline
                      gohanG Offline
                      gohan
                      Mod
                      wrote on last edited by
                      #141

                      @xydix Could you try to increase the 10000L to 100000L interval in the OnPulse function and see if it works without the capacitor?

                      1 Reply Last reply
                      0
                      • U Offline
                        U Offline
                        user2684
                        Contest Winner
                        wrote on last edited by
                        #142

                        I tried to build something similar and it is working nicely, thanks for sharing the idea! However, I've noticed the light sensor (alone) consumes 1mA constantly which is quite a lot when used for a battery powered project. Even if I report to the controller once per hour (summing up the power consumption along the way), still the light sensor needs to be always on, meaning I'd probably need to replace batteries after a month or so. Is there any workaround or alternative sensor which I can use or am I doing something completely wrong? Thanks

                        C 1 Reply Last reply
                        0
                        • U user2684

                          I tried to build something similar and it is working nicely, thanks for sharing the idea! However, I've noticed the light sensor (alone) consumes 1mA constantly which is quite a lot when used for a battery powered project. Even if I report to the controller once per hour (summing up the power consumption along the way), still the light sensor needs to be always on, meaning I'd probably need to replace batteries after a month or so. Is there any workaround or alternative sensor which I can use or am I doing something completely wrong? Thanks

                          C Offline
                          C Offline
                          cstewy
                          wrote on last edited by
                          #143

                          @user2684 I had the same issue when I built this with a standalone atmega328p running on 2x AA's. I set it up with wake on interrupt from the It was constantly drawing 1.6mA to power the tsl257 to detect the flashes. My target was 1+ years on 2 x AA's. My solution to achieve this was to sleep for 125ms, wake up, send power to tsl257 to check light state (on/off), if it changed from previous reading then there was a pulse (well half pulse). By measuring every 125ms I can guarantee to capture fast pulses up to 14.4kW. (3600000/125)/2. It is 20kW max draw for residential in my country. Now:
                          Average mA Consumption Sleep 0.1
                          Average mA Consumption Wake 0.064516129
                          Average mA Consumption Transmit 0.002916667
                          Battery Life (2xAAs) = 1.7 years

                          U 1 Reply Last reply
                          0
                          • C cstewy

                            @user2684 I had the same issue when I built this with a standalone atmega328p running on 2x AA's. I set it up with wake on interrupt from the It was constantly drawing 1.6mA to power the tsl257 to detect the flashes. My target was 1+ years on 2 x AA's. My solution to achieve this was to sleep for 125ms, wake up, send power to tsl257 to check light state (on/off), if it changed from previous reading then there was a pulse (well half pulse). By measuring every 125ms I can guarantee to capture fast pulses up to 14.4kW. (3600000/125)/2. It is 20kW max draw for residential in my country. Now:
                            Average mA Consumption Sleep 0.1
                            Average mA Consumption Wake 0.064516129
                            Average mA Consumption Transmit 0.002916667
                            Battery Life (2xAAs) = 1.7 years

                            U Offline
                            U Offline
                            user2684
                            Contest Winner
                            wrote on last edited by
                            #144

                            @cstewy many thanks and very interesting. You basically saying it consumes less by waking up every 125ms rather than being asleep but with the sensor eating up current continuously. Definitely worth trying thanks! Meanwhile I've reduced the number of radio transmission and the batteries lasted for a couple of months but still is not ideal. Thanks! I'll try and report back

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              artipi
                              wrote on last edited by
                              #145

                              Hello, i'm stuck with this sensor, because no Interrupt is really working. I've cut down the code to this:

                              /**
                               * The MySensors Arduino library handles the wireless radio link and protocol
                               * between your home built sensors/actuators and HA controller of choice.
                               * The sensors forms a self healing radio network with optional repeaters. Each
                               * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                               * network topology allowing messages to be routed to nodes.
                               *
                               * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                               * Copyright (C) 2013-2015 Sensnology AB
                               * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                               *
                               * Documentation: http://www.mysensors.org
                               * Support Forum: http://forum.mysensors.org
                               *
                               * This program is free software; you can redistribute it and/or
                               * modify it under the terms of the GNU General Public License
                               * version 2 as published by the Free Software Foundation.
                               *
                               *******************************
                               *
                               * REVISION HISTORY
                               * Version 1.0 - Henrik Ekblad
                               *
                               * DESCRIPTION
                               * This sketch provides an example how to implement a LM393 PCB
                               * Use this sensor to measure kWh and Watt of your house meter
                               * You need to set the correct pulsefactor of your meter (blinks per kWh).
                               * The sensor starts by fetching current kWh value from gateway.
                               * Reports both kWh and Watt back to gateway.
                               *
                               * Unfortunately millis() won't increment when the Arduino is in
                               * sleepmode. So we cannot make this sensor sleep if we also want
                               * to calculate/report watt value.
                               * http://www.mysensors.org/build/pulse_power
                               */
                              
                              // Enable debug prints
                              #define MY_DEBUG
                              
                              // Enable and select radio type attached
                              //#define MY_RADIO_NRF24
                              //#define MY_RADIO_NRF5_ESB
                              //#define MY_RADIO_RFM69
                              //#define MY_RADIO_RFM95
                              
                              //#include <MySensors.h>
                              
                              #define DIGITAL_INPUT_SENSOR 2  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
                              #define PULSE_FACTOR 500       // Number of blinks per of your meter
                              #define SLEEP_MODE false        // Watt value can only be reported when sleep mode is false.
                              #define MAX_WATT 1000000          // Max watt value to report. This filters outliers.
                              #define CHILD_ID 10             // Id of the sensor child
                              
                              uint32_t SEND_FREQUENCY =
                                  15000; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
                              double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
                              bool pcReceived = true;
                              volatile uint32_t pulseCount = 0;
                              volatile uint32_t lastBlink = 0;
                              volatile uint32_t watt = 0;
                              uint32_t oldPulseCount = 0;
                              uint32_t oldWatt = 0;
                              double oldkWh;
                              uint32_t lastSend;
                              //MyMessage wattMsg(CHILD_ID,V_WATT);
                              //MyMessage kWhMsg(CHILD_ID,V_KWH);
                              //MyMessage pcMsg(CHILD_ID,V_VAR1);
                              
                              
                              void setup()
                              {
                                Serial.begin(9600);
                                Serial.println("Start 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();
                                Serial.println("Start setup: last sent: ");
                                pinMode(LED_BUILTIN, OUTPUT);
                                digitalWrite(LED_BUILTIN, LOW);
                              }
                              
                              void presentation()
                              {
                                // Send the sketch version information to the gateway and Controller
                                //sendSketchInfo("Energy Meter", "1.3");
                              
                                // Register this device as power sensor
                                //present(CHILD_ID, S_POWER);
                              }
                              
                              void loop()
                              {
                                
                              }
                              
                              
                              
                              void onPulse()
                              {
                                Serial.println("onPulse:");
                                digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
                                delay(1000);                       // wait for a second
                                digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
                                delay(1000);      
                                pulseCount++;
                                Serial.println("pulseCount:");
                              }
                              

                              The Problem ist, that only on Start the interrupt ist working once, but no LED blinks.

                              Can someone help?

                              Thanks.

                              mfalkviddM 1 Reply Last reply
                              0
                              • A artipi

                                Hello, i'm stuck with this sensor, because no Interrupt is really working. I've cut down the code to this:

                                /**
                                 * The MySensors Arduino library handles the wireless radio link and protocol
                                 * between your home built sensors/actuators and HA controller of choice.
                                 * The sensors forms a self healing radio network with optional repeaters. Each
                                 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
                                 * network topology allowing messages to be routed to nodes.
                                 *
                                 * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
                                 * Copyright (C) 2013-2015 Sensnology AB
                                 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
                                 *
                                 * Documentation: http://www.mysensors.org
                                 * Support Forum: http://forum.mysensors.org
                                 *
                                 * This program is free software; you can redistribute it and/or
                                 * modify it under the terms of the GNU General Public License
                                 * version 2 as published by the Free Software Foundation.
                                 *
                                 *******************************
                                 *
                                 * REVISION HISTORY
                                 * Version 1.0 - Henrik Ekblad
                                 *
                                 * DESCRIPTION
                                 * This sketch provides an example how to implement a LM393 PCB
                                 * Use this sensor to measure kWh and Watt of your house meter
                                 * You need to set the correct pulsefactor of your meter (blinks per kWh).
                                 * The sensor starts by fetching current kWh value from gateway.
                                 * Reports both kWh and Watt back to gateway.
                                 *
                                 * Unfortunately millis() won't increment when the Arduino is in
                                 * sleepmode. So we cannot make this sensor sleep if we also want
                                 * to calculate/report watt value.
                                 * http://www.mysensors.org/build/pulse_power
                                 */
                                
                                // Enable debug prints
                                #define MY_DEBUG
                                
                                // Enable and select radio type attached
                                //#define MY_RADIO_NRF24
                                //#define MY_RADIO_NRF5_ESB
                                //#define MY_RADIO_RFM69
                                //#define MY_RADIO_RFM95
                                
                                //#include <MySensors.h>
                                
                                #define DIGITAL_INPUT_SENSOR 2  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
                                #define PULSE_FACTOR 500       // Number of blinks per of your meter
                                #define SLEEP_MODE false        // Watt value can only be reported when sleep mode is false.
                                #define MAX_WATT 1000000          // Max watt value to report. This filters outliers.
                                #define CHILD_ID 10             // Id of the sensor child
                                
                                uint32_t SEND_FREQUENCY =
                                    15000; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
                                double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
                                bool pcReceived = true;
                                volatile uint32_t pulseCount = 0;
                                volatile uint32_t lastBlink = 0;
                                volatile uint32_t watt = 0;
                                uint32_t oldPulseCount = 0;
                                uint32_t oldWatt = 0;
                                double oldkWh;
                                uint32_t lastSend;
                                //MyMessage wattMsg(CHILD_ID,V_WATT);
                                //MyMessage kWhMsg(CHILD_ID,V_KWH);
                                //MyMessage pcMsg(CHILD_ID,V_VAR1);
                                
                                
                                void setup()
                                {
                                  Serial.begin(9600);
                                  Serial.println("Start 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();
                                  Serial.println("Start setup: last sent: ");
                                  pinMode(LED_BUILTIN, OUTPUT);
                                  digitalWrite(LED_BUILTIN, LOW);
                                }
                                
                                void presentation()
                                {
                                  // Send the sketch version information to the gateway and Controller
                                  //sendSketchInfo("Energy Meter", "1.3");
                                
                                  // Register this device as power sensor
                                  //present(CHILD_ID, S_POWER);
                                }
                                
                                void loop()
                                {
                                  
                                }
                                
                                
                                
                                void onPulse()
                                {
                                  Serial.println("onPulse:");
                                  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
                                  delay(1000);                       // wait for a second
                                  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
                                  delay(1000);      
                                  pulseCount++;
                                  Serial.println("pulseCount:");
                                }
                                

                                The Problem ist, that only on Start the interrupt ist working once, but no LED blinks.

                                Can someone help?

                                Thanks.

                                mfalkviddM Offline
                                mfalkviddM Offline
                                mfalkvidd
                                Mod
                                wrote on last edited by mfalkvidd
                                #146

                                @artipi using Serial.print and delay from within an interrupt service routine will mess things up. Interrupt service routines must be executed quickly.

                                From https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/:

                                Since delay() requires interrupts to work, it will not work if called inside an ISR.

                                You need to do the blinking inside loop().

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  artipi
                                  wrote on last edited by
                                  #147

                                  Ah, this explains many things. Thank you, now its working:)!

                                  1 Reply Last reply
                                  1
                                  • alowhumA Offline
                                    alowhumA Offline
                                    alowhum
                                    Plugin Developer
                                    wrote on last edited by
                                    #148

                                    @artipi can you share your code?

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      artipi
                                      wrote on last edited by
                                      #149

                                      @alowhum: Its the original code. Nothing changed. I've only made some tests with my version...

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        patrikr76
                                        wrote on last edited by patrikr76
                                        #150

                                        Hey guys

                                        So i am trying to use this sketch with the sleep mode set to true 'cause i need to run it on battery.
                                        It works fine running with usb power on it and sleep mode on false.
                                        But with sleep mode true i am getting nothing in myscontroller after the initial startup.
                                        All i changed is the sleep mode from false to true.
                                        Running it on a clone nano with some chinese "flame detector" sensor.
                                        Been trying to figure out if it has something to do with how it reports when in sleep mode but it should still report whatever the send frequency is set to right?
                                        I was using a tv remote to fake impulses, with seems to work on usb power, but not on battery.
                                        Any suggestions?

                                        Best regards
                                        Patrik

                                        mfalkviddM 1 Reply Last reply
                                        0
                                        • P patrikr76

                                          Hey guys

                                          So i am trying to use this sketch with the sleep mode set to true 'cause i need to run it on battery.
                                          It works fine running with usb power on it and sleep mode on false.
                                          But with sleep mode true i am getting nothing in myscontroller after the initial startup.
                                          All i changed is the sleep mode from false to true.
                                          Running it on a clone nano with some chinese "flame detector" sensor.
                                          Been trying to figure out if it has something to do with how it reports when in sleep mode but it should still report whatever the send frequency is set to right?
                                          I was using a tv remote to fake impulses, with seems to work on usb power, but not on battery.
                                          Any suggestions?

                                          Best regards
                                          Patrik

                                          mfalkviddM Offline
                                          mfalkviddM Offline
                                          mfalkvidd
                                          Mod
                                          wrote on last edited by mfalkvidd
                                          #151

                                          @patrikr76 just to make sure we are on the same page, could you clarify which sketch you are using? This thread has discussed lots of sketches and it would be a pity if we’re looking at different code :)

                                          In any case, the debug log from the node will give the best information on what is happening.

                                          It could also be useful to only change one thing. Right now you change sleep mode and switch to battery, right? How does the node behave with sleep mode on, but still running on usb power? How does the node behave with sleep mode off, but running on battery?

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


                                          11

                                          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