pulse counter with CNY70

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
dannybloe
Normal user
Posts: 36
Joined: 16 Dec 2015, 16:29

pulse counter with CNY70

#1 Post by dannybloe » 29 Jan 2016, 14:48

Hi folks,

I could use some tips. I'm considering to build a pulse counter for my water meter using a CNY70 (http://www.vishay.com/docs/83751/cny70.pdf) based on what Jasper is describing (http://jasper.sikken.nl/gwemeter/index.html):
Image

However, following his advise, Vout is roughly within the range of 3.3V(reflection) and 2.5V (no reflection). What would be the best way to hook this up to an ESP using ESPEasy? Is that possible or do I need to put a Schmitt trigger in front of it to make a nice 0/3.3V switch or can I reduce the range to <1V and connect it to the analog pin (ADC, can only go to 1V)?

Tips are greatly appreciated :)

Cheers,
Danny

BobS
Normal user
Posts: 15
Joined: 18 Jan 2016, 21:29

Re: pulse counter with CNY70

#2 Post by BobS » 29 Jan 2016, 22:35

Hi Danny,

i use a schematic based on a CNY70 reflective sensor and ESPeasy for my watermeters and that works very good.

Some remarks if you change the location of the foto transistor and the resistor (transistor on the 3v3 and resistor to ground) it works better. You may also need to check with several value for both resistors to obtain the best result.

I use a schmitt trigger in my schematic to prevent false pulses when the meter stops richt on the edge of the pulse.

Using the analog input will not work in combination with ESPeasy because you need a high sampling frequency with some logic behind it to detect the pulses.

I made a small single sided print layout with some smd components and a connector for an ESP-01 and that works for some months now.
No problem with counting the pulses and sending them to domoticz incremental pulse counter.

Schematic in picture below:

Succes,
Bob.
Attachments
Watermeter schema en layout.jpg
Watermeter schema en layout.jpg (42.29 KiB) Viewed 24493 times

BobS
Normal user
Posts: 15
Joined: 18 Jan 2016, 21:29

Re: pulse counter with CNY70

#3 Post by BobS » 29 Jan 2016, 22:42

Het lukt me niet om meer dan één plaatje tegelijk te laden dus daarom apart.

Koudwatermeter:
Koudwatermeter_c.jpg
Koudwatermeter_c.jpg (172.15 KiB) Viewed 24492 times

BobS
Normal user
Posts: 15
Joined: 18 Jan 2016, 21:29

Re: pulse counter with CNY70

#4 Post by BobS » 29 Jan 2016, 22:42

En de warmwatermeter:
Warmwatermeter_a.jpg
Warmwatermeter_a.jpg (134.32 KiB) Viewed 24492 times

dannybloe
Normal user
Posts: 36
Joined: 16 Dec 2015, 16:29

Re: pulse counter with CNY70

#5 Post by dannybloe » 29 Jan 2016, 23:00

Wow.. that looks good.. you r0ck! I'm gonna try that.

dannybloe
Normal user
Posts: 36
Joined: 16 Dec 2015, 16:29

Re: pulse counter with CNY70

#6 Post by dannybloe » 31 Jan 2016, 15:25

Ok, I think I have a test setup working now for my water meter.

@Bob, how did you exactly configure stuff in ESPEasy and Domoticz for the water meter? Formula's, dividers etc? Like how do you make sure the counting is counting the right stuff?

Thanks
Danny

dannybloe
Normal user
Posts: 36
Joined: 16 Dec 2015, 16:29

Re: pulse counter with CNY70

#7 Post by dannybloe » 31 Jan 2016, 17:11

To reply myself.

I figured out that one cycle on the meter is exactly 1 liter (0,001m3). So I assume that it generates 2 pulses (from no reflection > metallic disk > no reflection). I cannot verify that easily because the meter is covered by the sensor board when it is all in place.

So, in ESPEasy I created a pulse counter on GPIO-2 and linked it to the device in Domoticz. In Domoticz I created a dummy incremental counter (type water) and in the settings I set RFX divider to 2000 (1 count is 0,0005m3). So... I noted the current meter value and let's see if my assumptions are all correct.

Did I miss something here? I have the feeling that I'm not using the full pulse-counter potential of ESPEasy but I'm not sure. The documentation in the wiki regarding pulse counters is not very helpful. I want to understand what it actually does. I assume it counts pulses and sends them all when it contacts Domoticz and then resets the count until the next upload.

So, any tips remarks is helpful and appreciated of course :)

Danny

BobS
Normal user
Posts: 15
Joined: 18 Jan 2016, 21:29

Re: pulse counter with CNY70

#8 Post by BobS » 31 Jan 2016, 21:10

Hi Danny,

To answer some of your questions:

I have two meters (cold and warm) cold gives two pulses/rotation warm gives one pulse/rotation.
This can be influenced by the way the cny70 is positioned on the meter.

The ESPeasy pulsecounter uses interrupts on the negative edge to count pulses.
You can set a debounce timer in msec, I set mine at 1 or 2 ms just to be save.
After sending the count to Domoticz the counter is reset.
The total is not reset and keeps counting until the esp is restarted, but this is not sent to Domoticz

Since I have two meters and we can only set one divider in Domoticz I uset that to 1000 and use the formula option in ESPeasy to divide the cold water pulses by 2. Formula in esp = %value%/2. If you have only one meter your setup looks fine.

One problem you may encounter when using an esp-1 is that both gpio0 and gpio2 inputs are used at reset to determine how to restart.
I used esp-12e on a little pcb where gpio4 and gpio5 are on the pins where esp-1 has gpio0 and gpio2.
With the latest ESPeasy versions I can now also use OTA to update the firmware.

Bob.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: pulse counter with CNY70

#9 Post by tozett » 01 Feb 2016, 08:14

+1 for putting this on the wiki.
Wonderful REAL-World example, working and nice photos..

dannybloe
Normal user
Posts: 36
Joined: 16 Dec 2015, 16:29

Re: pulse counter with CNY70

#10 Post by dannybloe » 01 Feb 2016, 08:16

Yeah, when my setup is working properly I'll try to write some paragraphs there. Unless someone else is ahead of me :)

dannybloe
Normal user
Posts: 36
Joined: 16 Dec 2015, 16:29

Re: pulse counter with CNY70

#11 Post by dannybloe » 01 Feb 2016, 16:55

BobS wrote:Hi Danny,

One problem you may encounter when using an esp-1 is that both gpio0 and gpio2 inputs are used at reset to determine how to restart.
I used esp-12e on a little pcb where gpio4 and gpio5 are on the pins where esp-1 has gpio0 and gpio2.
With the latest ESPeasy versions I can now also use OTA to update the firmware.

Bob.
I am not entirely sure if I understand this correctly. I'm using one of those Lolin board (nodemcu v3 clones) and I think it is a 12E. I did notice a strange thing today though (connected to GPIO-2). I turned it off and then back on and then both leds were on (I have the same two led setup as in your situation so you can see if the disc is visible or not, very handy) and the device didn't respond at all. I couldn't get to the ESPEasy config, webserver didn't respond. As if it was in some kind of limbo. Reset didn't work either, well it did reset but same limbo state. But... as soon as I used a bit of water (the disc moved underneath the sensor), then the device would boot. Could this be related somehow? That perhaps the disc was just in between something or that GPIO-2 was high at boot up (or low) causing the ESP not to start properly?

BobS
Normal user
Posts: 15
Joined: 18 Jan 2016, 21:29

Re: pulse counter with CNY70

#12 Post by BobS » 01 Feb 2016, 17:40

@Danny:
If you use a nodemcu like board you can beter use one of the other gpio inputs (I use gpio4).
When gpio2 is low at reboot I noticed the ESP can hang. :mrgreen:
The combination gpio0 high, gpio2 low is an undefined startup condition.

It should not be possible for both leds to light up at the same time, the Schmitt trigger should prevent that.
I read somewhere about the esp that when it is reset it can output a clock signal to gpio2, that might explain why both leds are on.

dannybloe
Normal user
Posts: 36
Joined: 16 Dec 2015, 16:29

Re: pulse counter with CNY70

#13 Post by dannybloe » 01 Feb 2016, 17:43

Yes, indeed. I started reading into this and I think you are right. I'll switch it to another pin. Thanks for the info.

dannybloe
Normal user
Posts: 36
Joined: 16 Dec 2015, 16:29

Re: pulse counter with CNY70

#14 Post by dannybloe » 02 Feb 2016, 19:22

I have the stuff working right now. Interesting to see how much water you actually use... quite confronting :shock:

dlefol
Normal user
Posts: 26
Joined: 11 Nov 2015, 23:28

Re: pulse counter with CNY70

#15 Post by dlefol » 05 Feb 2016, 11:00

Hello,

I would be interested to know what kind of accuracy you get with this setup.
I have a pulse counter based on TCRT5000 a bit like detailed here (but using ESPEasy): https://www.mysensors.org/build/pulse_water.

I am really struggling for the last month or so to get something accurate out of this setup. I've been playing with the position of the sensor and the debounce time, but still get regularly 50% inaccuracy on the readings... quite frustrating.

BobS
Normal user
Posts: 15
Joined: 18 Jan 2016, 21:29

Re: pulse counter with CNY70

#16 Post by BobS » 05 Feb 2016, 12:45

Hi,
The accuracy I get is very high. Virtually no miscounts with normal water flow even when watering the garden .
The only miscounts I get is when the contact between ESP and Domoticz is lost and ESP resets.

Important difference between cny70 and the tcrt5000 is the physical layout. The cny70 is compact with transmitter and receiver ca. 2mm apart and you can mount the housing directly to the surface of your meter to prevent stray light coming in. The transmitter and receiver in the tcrt5000 are much farther apart and open to light from the side.

I don't know if the print in your link uses a Schmitt trigger but that also helps to get a good signal with sharp edges and provides debounce.

dannybloe
Normal user
Posts: 36
Joined: 16 Dec 2015, 16:29

Re: pulse counter with CNY70

#17 Post by dannybloe » 05 Feb 2016, 12:51

Exactly... it is very accurate and doesn't seem to miss anything.
Regarding an unresponsive Domoticz.. I hope that the ESP's internal buffered count is only reset to 0 when the json call to Domoticz returns an OK. In all other cases it should keep counting until the next successful Domoticz update. I haven't confirmed if that is indeed happening but I do hope it does. Maybe one of the devs can confirm this. Then you only miss counts when the ESP is offline or reboots.

totof60
New user
Posts: 3
Joined: 09 May 2016, 09:56

Re: pulse counter with CNY70

#18 Post by totof60 » 09 May 2016, 09:58

Hi

I realized the same sensor as Bob.
But I sometimes pulses calculated without water consumption.
Even when I put the debounce 3000!

Is this a bug in easyesp?

dduley
Normal user
Posts: 93
Joined: 06 Feb 2016, 17:56

Re: pulse counter with CNY70

#19 Post by dduley » 09 May 2016, 16:59

dannybloe wrote:Hi folks,

I could use some tips. I'm considering to build a pulse counter for my water meter using a CNY70 (http://www.vishay.com/docs/83751/cny70.pdf) based on what Jasper is describing (http://jasper.sikken.nl/gwemeter/index.html):
Image

However, following his advise, Vout is roughly within the range of 3.3V(reflection) and 2.5V (no reflection). What would be the best way to hook this up to an ESP using ESPEasy? Is that possible or do I need to put a Schmitt trigger in front of it to make a nice 0/3.3V switch or can I reduce the range to <1V and connect it to the analog pin (ADC, can only go to 1V)?

Tips are greatly appreciated :)

Cheers,
Danny
Hi All,

I just saw this thread. I am doing the exact same thing on my property. I have a water meter that has a switch closure every 10 gallons of water.
The image of the opto isolated circuit is a good start but the implementation is very poor design practice. The whole point of the opto isolator is to isolate the sensor, switch closure door or window sensor, etc from the CPU. The image above has the 3.3V rail and GND connected to both sides of the circuit. This violates any hope of isolation. This places your 3.3V rail and Ground on a cable that could be many meters long. This will introduce noise and could cause your ESP module to reset unexpectedly. This risk would increase with cable length. The best way to do this is to use a separate power supply. I prefer 12 or 24V supply because if the cable is very long you could have enough DC loss to prevent lighting your LED if you only use 3.3V.
There are a few issues I have come across with using the ESPEasy for pulse counting. The count is lost if the module gets reset. Water meters are often not near the house or main structure so WIFI can be a bit iffy out there. This causes MQTT connection failures. After 30 connection failures the current code resets the processor thereby resetting the count. If the WIFI is spotty and you are getting connection errors then the count data is not updating to your Home automation software (OpenHab or Domotics etc) if the count is not updated often enough to get every count. Then you have data loss. This is exactly what I am seeing with my system.
I have been told that in version R106 of ESPEasy the 30 connection loss reset will be an option. It still would be great if the module did not loose that count value through a reset.

Never put the CPU Ground or VCC on any cable more than a few inches long. Opto Isolation is a great way to isolate your processor from the noisy real world but you should never have any connections from the isolated side to the non-isolated side.

Best regards

Dave

totof60
New user
Posts: 3
Joined: 09 May 2016, 09:56

Re: pulse counter with CNY70

#20 Post by totof60 » 13 May 2016, 11:56

it's not for isolating , it's for count !

dduley
Normal user
Posts: 93
Joined: 06 Feb 2016, 17:56

Re: pulse counter with CNY70

#21 Post by dduley » 13 May 2016, 17:27

totof60 wrote:it's not for isolating , it's for count !
Thanks totof60,

I see now that it is a retro reflective sensor in the diagram. its drawn as an optoisolator and that confused me. I get excited when I see optoisolation circuits. I work in the offshore instrumentation industry and we rely heavily on opto isolation to prevent common mode voltage issues and to prevent noise on serial signal lines. Most of the techs and engineers I run into in the field have no idea how optoisolation is supposed to work. I have seen isolators thrown into circuits with no attention to the isolated vs non isolated side.
I was basing my comments on my own water meter which has a switch closure for every 10 gallons. The meter is 10 meters or so away from the ESP that is counting the pulses. I had to opto isolate that signal to prevent issues with the operation of the ESP.
I assume your meter has a spinning disc with a dark side and a white side that you are reading with a retroreflective sensor.

Thanks for pointing out my error!

regards

Dave

piman33240
New user
Posts: 3
Joined: 29 Aug 2019, 19:47

Re: pulse counter with CNY70

#22 Post by piman33240 » 29 Aug 2019, 19:52

420/5000
Hello
I want to follow my consumption of water with a nodemcu + esp easy and a cny70 resistor 220 + 10k
I control with espeasy R120 relay, I have the temperature of my ds18b20 that goes back in domoticz but the counter does not move.
domoticz, hardware, dummy then create a virtual water sensor

in formula if i put 1 in the count line i have my counter that increments by 1 but it never stops

Capture4.PNG
Capture4.PNG (33.41 KiB) Viewed 17266 times
Capture6.PNG
Capture6.PNG (720.57 KiB) Viewed 17266 times

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: pulse counter with CNY70

#23 Post by grovkillen » 29 Aug 2019, 21:39

Would you be willing to upgrade to a never version?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

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

Re: pulse counter with CNY70

#24 Post by TD-er » 29 Aug 2019, 21:40

And make sure to have this pulse counter plugin as one of the first plugins

piman33240
New user
Posts: 3
Joined: 29 Aug 2019, 19:47

Re: pulse counter with CNY70

#25 Post by piman33240 » 29 Aug 2019, 22:10

grovkillen wrote: 29 Aug 2019, 21:39 Would you be willing to upgrade to a never version?
I have not been able to install newer versions

piman33240
New user
Posts: 3
Joined: 29 Aug 2019, 19:47

Re: pulse counter with CNY70

#26 Post by piman33240 » 29 Aug 2019, 22:25

TD-er wrote: 29 Aug 2019, 21:40 And make sure to have this pulse counter plugin as one of the first plugins
it works , thank you

Post Reply

Who is online

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