Page 1 of 1

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

Posted: 05 Dec 2022, 16:58
by Metatron
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

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

Posted: 05 Dec 2022, 17:51
by TD-er
How many pulses per second do you expect?

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

Posted: 05 Dec 2022, 17:59
by Metatron
One pulse is one liter of gas.
This is the signal:
unnamed (1).png
unnamed (1).png (39.42 KiB) Viewed 3954 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.

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

Posted: 05 Dec 2022, 18:14
by TD-er
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.

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

Posted: 06 Dec 2022, 08:48
by Metatron
Thank you!

That looks promising, I will read it through!

Regards, Metatron

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

Posted: 06 Dec 2022, 09:00
by Metatron
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.

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

Posted: 06 Dec 2022, 09:40
by chromo23
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

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

Posted: 06 Dec 2022, 10:03
by TD-er
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.

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

Posted: 06 Dec 2022, 11:06
by Metatron
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.

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

Posted: 06 Dec 2022, 11:09
by Metatron
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.

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

Posted: 06 Dec 2022, 11:18
by TD-er
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 :)

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

Posted: 07 Dec 2022, 08:50
by Metatron
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!

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

Posted: 16 Feb 2023, 07:33
by Jksukino
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.

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

Posted: 16 Feb 2023, 15:26
by bidrohini
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.

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

Posted: 16 Feb 2023, 15:46
by Ath
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

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

Posted: 16 Feb 2023, 18:30
by Metatron
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.

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

Posted: 16 Feb 2023, 21:14
by TD-er
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.