Gas meter with Hall Sensor, counting via ADC (A0)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Gas meter with Hall Sensor, counting via ADC (A0)

#1 Post by Metatron » 05 Dec 2022, 16:58

Hello,

after experimenting with reed contacts, I found out, that I get a far more reliable measurement from a hall sensor (Type 49E) for the rotating magnet of some gas meters.
With reed contacts, I always got some bouncing, and other effects.
I now get a nice kind of sine wave, only the negative part of it. I want to count the number of negative waves, triggering for instance a pulse counter, but preferably over A0 input, with a software defined threshold.
I want to be adjustable about the values for the triggers, as I want to be able to cover tolerances between different gas meters. I.e. I don't want a hardware solution with resistors triggering a digital GPIO.

So. please, can I use the ADC/A0 input and maybe a rule, to realise something like:
"if you get lower then -0,51 and then higher than -0,49 then trigger pulse counter"?

Some ideas/hints would be very nice.

Kind Regards, Metatron

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#2 Post by TD-er » 05 Dec 2022, 17:51

How many pulses per second do you expect?

User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#3 Post by Metatron » 05 Dec 2022, 17:59

One pulse is one liter of gas.
This is the signal:
unnamed (1).png
unnamed (1).png (39.42 KiB) Viewed 3695 times
Sampling 1s to HA with esphome.

However, I want to prevent the traffic and solve it on esp side. I have some experience with espeasy.
I won't get much faster, but slower down to standstill at any position - if no gas is used.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#4 Post by TD-er » 05 Dec 2022, 18:14

Given it is more than a second between pulses, you could try what was discussed here: viewtopic.php?p=60251#p60251
It is a very similar question to what you're trying to do.

User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#5 Post by Metatron » 06 Dec 2022, 08:48

Thank you!

That looks promising, I will read it through!

Regards, Metatron

User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#6 Post by Metatron » 06 Dec 2022, 09:00

I would like to use the pulse counter.
Count I trigger the pulse counter by a rule command without hardware?
Or do I need to trigger it with a gpio connected to another one?

I don't like the idea to send the pulses directly to my smart home software. If this is unavailable, e.g. for maintenance, I loose pulses.

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#7 Post by chromo23 » 06 Dec 2022, 09:40

you could use an unused gpio for the pulse counter and pulse this gpio with a rule.

something like:

Code: Select all

On analog#value Do
 If %eventvalue% > something and [var#1] = 1
  LongPulse_mS,14,1,100
  Let,1,0
 Else
  Let,1,1
 Endif
Endon
Edit:
You don’t necessarily need the pulse counter. you could also store the value in an dummy-device:

Code: Select all

On analog#value Do
 If %eventvalue% > something and [var#1] = 1
  TaskValueSet,Dummy,Value,[Dummy#Value]+1
  Let,1,0
 Else
  Let,1,1
 Endif
Endon

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#8 Post by TD-er » 06 Dec 2022, 10:03

Yep generating a pulse, only to count it on the same device is wasting resources and very prone to error as everything done on the ESP8266 is done in software.
Better store it in a variable, or if you need to keep it after a reboot (without power loss) you can use a dummy task and use taskValueSet to store it in the dummy.

User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#9 Post by Metatron » 06 Dec 2022, 11:06

Thank you all for the valuable input. I will see, how I can use this.

Please don't forget, the pulse counter produces not only the sum, but 3 values.
And furthermore, there are codes and automations for all kind of smart home software systems, do deal with the output of the espeasy pulse counter.

So if I plan to build some of these readers, everyone can easily implement it in his/hers system.

User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#10 Post by Metatron » 06 Dec 2022, 11:09

PS: Everyone using the standard reed solution could also easily switch to the hall version, as it produces the same output, just better without bouncing.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#11 Post by TD-er » 06 Dec 2022, 11:18

What other values do you need?
If it is about the duration between pulses, this can also be done in rules.
Simply count the nr. of pulses and have a loop timer set to every minute (or whatever interval you need) and calculate the power usage based on the nr of counts. (make sure not to divide by zero ;) )

Anyway, I get it that you may want to have an analog version of the pulse counter plugin :)

User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#12 Post by Metatron » 07 Dec 2022, 08:50

Hello,

yes, in theory, this would be the most comfortable solution to transfer any cyclic analog signal to cylce counts.
However, with the suggestions here, I believe I can make it work with rules!
Thank you!

Jksukino
New user
Posts: 1
Joined: 14 Feb 2023, 16:14

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#13 Post by Jksukino » 16 Feb 2023, 07:33

Hey Metatron! Dit you get it working in the end? I'm trying the same thing with a hall effects sensor. Could you maybe share your code? I'm not that great with it and it would help immensely.

bidrohini
Normal user
Posts: 101
Joined: 03 Nov 2022, 16:24

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#14 Post by bidrohini » 16 Feb 2023, 15:26

You have to connect the output of the hall sensor to the ADC/A0 input on your microcontroller. You may need to add some additional circuitry, such as a voltage divider, to ensure that the input voltage stays within the range of the ADC.

Write a function to read the ADC value and convert it to a voltage. The voltage will vary with the position of the rotating magnet and will generate a sine wave. The negative peaks of the wave will correspond to the point where the magnet is closest to the sensor.

Set a threshold voltage that will trigger the pulse counter. This threshold voltage should be set to a value that is slightly below the negative peak of the sine wave. You can make this threshold voltage adjustable by adding a potentiometer or some other variable resistor to your circuit.

User avatar
Ath
Normal user
Posts: 3418
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#15 Post by Ath » 16 Feb 2023, 15:46

bidrohini wrote: 16 Feb 2023, 15:26 You have to connect the output of the hall sensor to the ADC/A0 input on your microcontroller. You may need to add some additional circuitry, such as a voltage divider, to ensure that the input voltage stays within the range of the ADC.

Write a function to read the ADC value and convert it to a voltage. The voltage will vary with the position of the rotating magnet and will generate a sine wave. The negative peaks of the wave will correspond to the point where the magnet is closest to the sensor.

Set a threshold voltage that will trigger the pulse counter. This threshold voltage should be set to a value that is slightly below the negative peak of the sine wave. You can make this threshold voltage adjustable by adding a potentiometer or some other variable resistor to your circuit.
This is a really strange answer :o
/Ton (PayPal.me)

User avatar
Metatron
Normal user
Posts: 39
Joined: 20 Mar 2021, 09:38

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#16 Post by Metatron » 16 Feb 2023, 18:30

I think the answer sketches the idea, it is ok.
I have not had the time, yet, to implement it.
As soon as I have, I will post the result.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Gas meter with Hall Sensor, counting via ADC (A0)

#17 Post by TD-er » 16 Feb 2023, 21:14

Well, it is indeed a rather strange answer, as we have the ADC plugin in ESPEasy since the very beginning...
The ADC plugin even has plugin ID nr 2, just indicating how early in the project it was added.

So I really wonder what @bidrohini means to suggest here as this is a forum for the ESPEasy project and thus writing code for it is absolutely not needed.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 19 guests