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. My Project
  3. Gas Meter Reading Using a Magnetometer

Gas Meter Reading Using a Magnetometer

Scheduled Pinned Locked Moved My Project
77 Posts 10 Posters 23.3k Views 12 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.
  • dynamiteD dynamite

    @dpcr Nice adjustment of your Original code. Based on your Original version I have started coding as well as I like the simpleness of just adding a sensor to the meter without taking care of the direct position.
    My current code can be found at github via the following link:

    https://github.com/rspaargaren/Read_Gasmeter/blob/Workinprogress/Read_Gasmeter.ino

    Basic differences are:

    • I have removed the fram reference but this could be added again if you use it.
    • I have added a different setup sequence for fixing the top and bottom. In my case it waits until four changes in direction have occured. So no direct gas flow have to flow after a restart.
    • The number of pulses between a change in direction is fixed independent of a change in top or bottom. So in my case every half a cycle will give ten pulses and a full cycle 20 pulses.
    • The results are submitted to the gateway after a intervall but also after half a cycle.
    • The top and bottom is checked after each cycle. So in case of major difference the interval is changed.
    • During normal run, the reading of the y value is executed within the loop. So basically the arduino has time to do some other stuff as well in between the readings.

    The code is currently working but requires some clean up. Also I would like to make an option to store the values at the gateway and maybe change the hardware to an ESP version so I can have multiple ways of output. Like MQTT.
    This is the current output in Grafana:

    0_1493840069318_upload-83a800b9-0b52-4b3a-a54e-829249fcf012

    dpcrD Offline
    dpcrD Offline
    dpcr
    wrote on last edited by
    #39

    @dynamite I just scanned quickly over your code. So there is no need to store the top and bottom values? What do you do on a power failure? I look forward to hearing from you more.

    Do you have any pics of your hardware?

    dynamiteD 1 Reply Last reply
    0
    • dpcrD dpcr

      @dynamite I just scanned quickly over your code. So there is no need to store the top and bottom values? What do you do on a power failure? I look forward to hearing from you more.

      Do you have any pics of your hardware?

      dynamiteD Offline
      dynamiteD Offline
      dynamite
      wrote on last edited by dynamite
      #40

      @dpcr At the moment I do not store the top and bottom value permanently. In case of a power failure I will "loose" to the max two rounds of the wheel on pulses as it uses that to calibrate the top and bottom. That could be reduced to potentially only one cycle. Which is in my case 0,01m3 to 0,02 m3 of gas indication.
      After the power failure the process starts in the calibration loop which is ended only after the required cycles have registered. So this could last 30 sec in case you are having a shower but can last a week if you are away...

      I will post a picture of my setup later.

      Now I am thinking of it. If you do not care about the accuracy that much you do not need the top and bottom values at all. You just need to detect the rice and fall. That still gives you double the accuracy than a reed contact or Hall effect. The sketch for that will be very simple and after power down you can continue most probably without loss of pulses.

      dpcrD 1 Reply Last reply
      0
      • dynamiteD dynamite

        @dpcr At the moment I do not store the top and bottom value permanently. In case of a power failure I will "loose" to the max two rounds of the wheel on pulses as it uses that to calibrate the top and bottom. That could be reduced to potentially only one cycle. Which is in my case 0,01m3 to 0,02 m3 of gas indication.
        After the power failure the process starts in the calibration loop which is ended only after the required cycles have registered. So this could last 30 sec in case you are having a shower but can last a week if you are away...

        I will post a picture of my setup later.

        Now I am thinking of it. If you do not care about the accuracy that much you do not need the top and bottom values at all. You just need to detect the rice and fall. That still gives you double the accuracy than a reed contact or Hall effect. The sketch for that will be very simple and after power down you can continue most probably without loss of pulses.

        dpcrD Offline
        dpcrD Offline
        dpcr
        wrote on last edited by
        #41

        @dynamite Great idea (top and bottom). We were kicking that around when we made this but wanted to err on the side of missing little to no gas flow. We have a pilot light on our water heater the draws around .1 lpm and I want to capture that as well.

        I agree with you on the accuracy of using a magnetometer over a hall or reed switch, but they (hall or reed) are much easy to program. Too bad there isn't a library for converting a sine wave to pulses, don't forget that sometimes it doesn't look like a sine wave.

        I'm curious to see how you mounted your magnetometer to your gas meter, mine seems a little too bulky and obtrusive. I did manage to buy another magnetometer and dip it in some stuff called PlastiDip. Its used for insulating the handles of tools. I just haven't switched them out yet to see how well it works.

        dynamiteD 1 Reply Last reply
        0
        • dpcrD dpcr

          @dynamite Great idea (top and bottom). We were kicking that around when we made this but wanted to err on the side of missing little to no gas flow. We have a pilot light on our water heater the draws around .1 lpm and I want to capture that as well.

          I agree with you on the accuracy of using a magnetometer over a hall or reed switch, but they (hall or reed) are much easy to program. Too bad there isn't a library for converting a sine wave to pulses, don't forget that sometimes it doesn't look like a sine wave.

          I'm curious to see how you mounted your magnetometer to your gas meter, mine seems a little too bulky and obtrusive. I did manage to buy another magnetometer and dip it in some stuff called PlastiDip. Its used for insulating the handles of tools. I just haven't switched them out yet to see how well it works.

          dynamiteD Offline
          dynamiteD Offline
          dynamite
          wrote on last edited by dynamite
          #42

          @dpcr Hi the reason that it is sometimes not a sine wave is the reason why I used a fixed number of pulses between the top of bottom. So in case the flow is very low as for your pilot light it will detect every puls. In case you have a very heavy flow pulses can be skipped as long as the change is detected then in my case 10 pulses are submitted to the gate way. I was detecting in your original sketch sometimes extra pulses were submitted as the sine was little bit rising or the opposite dropping.

          The code for just detecting rise and fall can be quite straigh foreward. I might make a second version like that...just for the record.

          My Setup is quite straight forward. A small box with the arduino pro mini and radio. A cable to the magneto sensor. In my case water proof is not required. I have applied the sensor by Velcro strap so I can remove the setup in case of "Maintenance".

          0_1494089653533_IMG_7279.JPG

          YveauxY dpcrD 2 Replies Last reply
          0
          • dynamiteD dynamite

            @dpcr Hi the reason that it is sometimes not a sine wave is the reason why I used a fixed number of pulses between the top of bottom. So in case the flow is very low as for your pilot light it will detect every puls. In case you have a very heavy flow pulses can be skipped as long as the change is detected then in my case 10 pulses are submitted to the gate way. I was detecting in your original sketch sometimes extra pulses were submitted as the sine was little bit rising or the opposite dropping.

            The code for just detecting rise and fall can be quite straigh foreward. I might make a second version like that...just for the record.

            My Setup is quite straight forward. A small box with the arduino pro mini and radio. A cable to the magneto sensor. In my case water proof is not required. I have applied the sensor by Velcro strap so I can remove the setup in case of "Maintenance".

            0_1494089653533_IMG_7279.JPG

            YveauxY Offline
            YveauxY Offline
            Yveaux
            Mod
            wrote on last edited by
            #43

            @dynamite I seem to have the same meter; the BK-G4 :

            0_1494093064638_upload-7b4dd65e-d3af-43fc-ac01-4c8357b57059

            The 'official' place to stick a reed sensor is a hole on the bottom-right, as you can see in the picture.
            I had a spare reed switch from a Senseo coffee machine, which perfectly fits the hole and works perfect!

            Maybe if you stick the compass sensor here, the signal will be more consistent/repeatable, as it should be more or less the same with each revolution.

            http://yveaux.blogspot.nl

            dynamiteD 1 Reply Last reply
            1
            • dynamiteD dynamite

              @dpcr Hi the reason that it is sometimes not a sine wave is the reason why I used a fixed number of pulses between the top of bottom. So in case the flow is very low as for your pilot light it will detect every puls. In case you have a very heavy flow pulses can be skipped as long as the change is detected then in my case 10 pulses are submitted to the gate way. I was detecting in your original sketch sometimes extra pulses were submitted as the sine was little bit rising or the opposite dropping.

              The code for just detecting rise and fall can be quite straigh foreward. I might make a second version like that...just for the record.

              My Setup is quite straight forward. A small box with the arduino pro mini and radio. A cable to the magneto sensor. In my case water proof is not required. I have applied the sensor by Velcro strap so I can remove the setup in case of "Maintenance".

              0_1494089653533_IMG_7279.JPG

              dpcrD Offline
              dpcrD Offline
              dpcr
              wrote on last edited by
              #44

              @dynamite I noticed some pulses missing as well. It looks like the newer sketch catches them. I also checked the volume used with our gas suppliers volume used and it was pretty close. We added an error correction variable to try to be more accurate. When I get a chance I'm going to try your sketch, it looks interesting.

              dynamiteD 1 Reply Last reply
              0
              • YveauxY Yveaux

                @dynamite I seem to have the same meter; the BK-G4 :

                0_1494093064638_upload-7b4dd65e-d3af-43fc-ac01-4c8357b57059

                The 'official' place to stick a reed sensor is a hole on the bottom-right, as you can see in the picture.
                I had a spare reed switch from a Senseo coffee machine, which perfectly fits the hole and works perfect!

                Maybe if you stick the compass sensor here, the signal will be more consistent/repeatable, as it should be more or less the same with each revolution.

                dynamiteD Offline
                dynamiteD Offline
                dynamite
                wrote on last edited by
                #45

                @Yveaux Hi thanks for the suggestion. Basically the position I am using now gives me a very accurate signal. It is more the small changes in the Sine curve which could result in miss reading. But I have added some filtering by appying a running average.

                I have tried other position just to see the results. Basically if you stick it to close to the magnet used, like the official reed position it will go in overload and magnetic reading is maximized for a period.

                1 Reply Last reply
                0
                • dpcrD dpcr

                  @dynamite I noticed some pulses missing as well. It looks like the newer sketch catches them. I also checked the volume used with our gas suppliers volume used and it was pretty close. We added an error correction variable to try to be more accurate. When I get a chance I'm going to try your sketch, it looks interesting.

                  dynamiteD Offline
                  dynamiteD Offline
                  dynamite
                  wrote on last edited by dynamite
                  #46

                  @dpcr Hi i am looking forward for your experience, as far as I have experienced now, and it took me quite some debugging I did not miss a pulse. :-)

                  @Yveaux @dpcr My next testing is to apply this sensor for the watermeter.

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

                    For water meters I saw people using those lines trackers that are used on small robots

                    dynamiteD 1 Reply Last reply
                    0
                    • gohanG gohan

                      For water meters I saw people using those lines trackers that are used on small robots

                      dynamiteD Offline
                      dynamiteD Offline
                      dynamite
                      wrote on last edited by
                      #48

                      @gohan Yes i have Seen them as Well that would be the easy way out ;-)

                      I am just curious wether i am picking up a workable signal when i stick this sensor to it. If so it would make installation quite simple.

                      YveauxY 1 Reply Last reply
                      0
                      • dynamiteD dynamite

                        @gohan Yes i have Seen them as Well that would be the easy way out ;-)

                        I am just curious wether i am picking up a workable signal when i stick this sensor to it. If so it would make installation quite simple.

                        YveauxY Offline
                        YveauxY Offline
                        Yveaux
                        Mod
                        wrote on last edited by
                        #49

                        @dynamite said in Gas Meter Reading Using a Magnetometer:

                        I am just curious wether i am picking up a workable signal when i stick this sensor to it

                        Yes, works like a charm! At least for my sensor

                        http://yveaux.blogspot.nl

                        dynamiteD 1 Reply Last reply
                        0
                        • YveauxY Yveaux

                          @dynamite said in Gas Meter Reading Using a Magnetometer:

                          I am just curious wether i am picking up a workable signal when i stick this sensor to it

                          Yes, works like a charm! At least for my sensor

                          dynamiteD Offline
                          dynamiteD Offline
                          dynamite
                          wrote on last edited by dynamite
                          #50

                          @Yveaux nice! and what code are you using? or are you referring to putting the ir sensor to the meter?

                          1 Reply Last reply
                          0
                          • dynamiteD dynamite

                            @dpcr Nice adjustment of your Original code. Based on your Original version I have started coding as well as I like the simpleness of just adding a sensor to the meter without taking care of the direct position.
                            My current code can be found at github via the following link:

                            https://github.com/rspaargaren/Read_Gasmeter/blob/Workinprogress/Read_Gasmeter.ino

                            Basic differences are:

                            • I have removed the fram reference but this could be added again if you use it.
                            • I have added a different setup sequence for fixing the top and bottom. In my case it waits until four changes in direction have occured. So no direct gas flow have to flow after a restart.
                            • The number of pulses between a change in direction is fixed independent of a change in top or bottom. So in my case every half a cycle will give ten pulses and a full cycle 20 pulses.
                            • The results are submitted to the gateway after a intervall but also after half a cycle.
                            • The top and bottom is checked after each cycle. So in case of major difference the interval is changed.
                            • During normal run, the reading of the y value is executed within the loop. So basically the arduino has time to do some other stuff as well in between the readings.

                            The code is currently working but requires some clean up. Also I would like to make an option to store the values at the gateway and maybe change the hardware to an ESP version so I can have multiple ways of output. Like MQTT.
                            This is the current output in Grafana:

                            0_1493840069318_upload-83a800b9-0b52-4b3a-a54e-829249fcf012

                            dpcrD Offline
                            dpcrD Offline
                            dpcr
                            wrote on last edited by
                            #51

                            @dynamite Just checking in, how is your set up working? We just had some major problems with too many extra pulses. It looks like something you experienced earlier, we added some smoothing to the readMag output similar to what you have in your sketch and it seems to working fine. Any updates?

                            dynamiteD 1 Reply Last reply
                            0
                            • jumpingJ Offline
                              jumpingJ Offline
                              jumping
                              wrote on last edited by
                              #52

                              Hello,
                              I have a BK-G4L gas meter and I want to build a Mysensor node and measure the gas flow: what is the best solution, a reed switch or a magnetometer?
                              and for a magnetometer based sensor, do I need HMC5883 or HMC5983?
                              thanks

                              Raspberrry PI3 - Domoticz
                              ESP8266 GW - MySensors 2.1.1

                              dynamiteD 1 Reply Last reply
                              0
                              • jumpingJ jumping

                                Hello,
                                I have a BK-G4L gas meter and I want to build a Mysensor node and measure the gas flow: what is the best solution, a reed switch or a magnetometer?
                                and for a magnetometer based sensor, do I need HMC5883 or HMC5983?
                                thanks

                                dynamiteD Offline
                                dynamiteD Offline
                                dynamite
                                wrote on last edited by
                                #53

                                @jumping Hi I have used the magnetometer. (GY-282 HMC5983)

                                I these are the +/- of both the systems:

                                • More easy to locate on your gas meter
                                • Higher accuracy of output (more pulses per cycle)
                                • Code is more complex

                                Read Sensor

                                • Simple code
                                • Exact installation from position
                                • 1 puls per round
                                jumpingJ 1 Reply Last reply
                                0
                                • dpcrD dpcr

                                  @dynamite Just checking in, how is your set up working? We just had some major problems with too many extra pulses. It looks like something you experienced earlier, we added some smoothing to the readMag output similar to what you have in your sketch and it seems to working fine. Any updates?

                                  dynamiteD Offline
                                  dynamiteD Offline
                                  dynamite
                                  wrote on last edited by dynamite
                                  #54

                                  @dpcr Hi, I need to recalibrate to see if the reading is still OK. Somewhere during a total reset I have lost track. But it is on my to do list to get everything up and running again.
                                  As far as I could recollect an overshoot had no influence on my code as the number of pulses for a total cycle is consistent within my code.

                                  On the Y reading from the sensor I do have a running average smoothing.
                                  Basically every cycle is splitted into rising and falling part. Each splitted into a fixed number of steps. Based on the current reading of y the number of pulses is calculated within that step. So the amount of pulses within a rise or fall can never be more than the number of steps within that cycle.

                                  I am thinking of making the code more simple and only give a pulse on the changes and maybe one in the middle. That would give me about 4 pulses per cycle.

                                  dpcrD 1 Reply Last reply
                                  0
                                  • dynamiteD dynamite

                                    @jumping Hi I have used the magnetometer. (GY-282 HMC5983)

                                    I these are the +/- of both the systems:

                                    • More easy to locate on your gas meter
                                    • Higher accuracy of output (more pulses per cycle)
                                    • Code is more complex

                                    Read Sensor

                                    • Simple code
                                    • Exact installation from position
                                    • 1 puls per round
                                    jumpingJ Offline
                                    jumpingJ Offline
                                    jumping
                                    wrote on last edited by
                                    #55

                                    @dynamite thanks for your answer! do you use a adafruit FRAM in your node?

                                    Raspberrry PI3 - Domoticz
                                    ESP8266 GW - MySensors 2.1.1

                                    dynamiteD zboblamontZ 2 Replies Last reply
                                    0
                                    • jumpingJ jumping

                                      @dynamite thanks for your answer! do you use a adafruit FRAM in your node?

                                      dynamiteD Offline
                                      dynamiteD Offline
                                      dynamite
                                      wrote on last edited by
                                      #56

                                      @jumping No I do not. Basically I use my gateway to store and retrieve the pulse value.

                                      1 Reply Last reply
                                      0
                                      • jumpingJ jumping

                                        @dynamite thanks for your answer! do you use a adafruit FRAM in your node?

                                        zboblamontZ Offline
                                        zboblamontZ Offline
                                        zboblamont
                                        wrote on last edited by
                                        #57

                                        @jumping If you have dismissed the possibility of using the authorised reed switch fair enough, but I got the following one, my meter is a BK-G4MT http://store.meterprovida.com/store/category/28/product/metur002.aspx
                                        I have no affiliation with the company, simply a very happy customer, especially at that price. My gas provider was a bit iffy about anything but the dedicated device...

                                        dynamiteD 1 Reply Last reply
                                        0
                                        • zboblamontZ zboblamont

                                          @jumping If you have dismissed the possibility of using the authorised reed switch fair enough, but I got the following one, my meter is a BK-G4MT http://store.meterprovida.com/store/category/28/product/metur002.aspx
                                          I have no affiliation with the company, simply a very happy customer, especially at that price. My gas provider was a bit iffy about anything but the dedicated device...

                                          dynamiteD Offline
                                          dynamiteD Offline
                                          dynamite
                                          wrote on last edited by
                                          #58

                                          @zboblamont That is a quite nice price indeed.

                                          zboblamontZ 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