Watermeter through GPIO and TCRT5000

Moderator: leecollings

Lieuwke
Posts: 15
Joined: Saturday 06 December 2014 19:25
Target OS: Linux
Domoticz version:
Contact:

Watermeter through GPIO and TCRT5000

Post by Lieuwke »

I have connected my Smartmeter and come to the conclusion i am missing another meter in my metercabinet. Water!
I have read a thread on this forum http://www.domoticz.com/forum/viewtopic ... 1&start=20 about the gasmeter reading. I want to try this module: http://www.dx.com/p/tcrt5000-black-and- ... car-140732 and connect it to GPIO
I have ordered it to give it a try. It can't hurt to try since it only cost a couple of bucks.
Watermeter1.jpg
Watermeter1.jpg (218.73 KiB) Viewed 13465 times
I haven't got a very nice watermeter for this purpose, so i am hoping to detect the rotation of one of the red dials. If it doesn't work, well, bad luck.
It will take some time for the hardware to arrive, but i'll keep you posted about any progress that make (or any failures for that matter)
Sony Raspberry Pi B V2.0
Homemade P1 cable on Landis/Gyr E350
C&K/Honeywell Security system connected to Domoticz
AEON Labs USB Z-Wave
TCRT5000 sensor watermeter -> revived..... and in progress....
ThinkPad
Posts: 890
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by ThinkPad »

If you have a smartphone look for a compass/magnetic field app and let the water flow somewhere in your house. Then hold your phone near your meter, and see if you can find a pulsating signal. Maybe the meter has a little magnet in it. Detecting that field is a lot easier than correctly aligning the TCRT5000 module i think.
I am not active on this forum anymore.
BigDog
Posts: 82
Joined: Tuesday 17 September 2013 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.9269
Location: The Netherlands
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by BigDog »

have you got it working?
i have the same watermeter :)

greetz Bob
1X Raspberry4B : Domoticz Version 2023.1 [Linux 5.10.63-v7l+ armv7l]
1X Conbee II : 2.25.3 - 26720700
1X RFXtrx433 USB Firmware:183
1X Mysensors Gateway 1.5 -3
6X ESP8266: Tosmota firmware
Zigbee : 6 Operators, 13 Sensors
jossie67
Posts: 39
Joined: Wednesday 31 December 2014 12:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by jossie67 »

Thinkpad and Bob,

Any news about the water meter

Greetz Jos
Raspberry Pi (3x)
Master Domoticz installed on a Synology
RFXCOM RFXtrx433E USB
RFLink
USB Z-Wave Mini Adapter
Mi-light
QuinLED
Landis+Gyr ZME120ACd
Kamstrup_M401
USB-IR-Schreib-Lesekopf Alecto WS1700
Watermeter with TCRT5000
Kodi
DS18B20
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by D'rMorris »

I've been fiddling around with a water meter as well and this is how I did it:

I've bought the following items:
1. A small pcb (sku213567) to which I can hook multiple TCRT5000's. This PCB has 4 separate signal outputs so hook up to 4 GPIO inputs whereas you only need 1 VCC and 1 ground. I do not own a Piface (yet) but I wanted to figure out how everything works.
I know that measuring is much easier via the piface ;).
Image

2. Multiple TCRT5000's (sku171350):
Image

you can also buy these (sku213949):
Image

The difference between these two is that the latter is normally closed (so contact shows closed when light not reflected) whereas the first one is normally open (so contact shows open when light not reflected). Kinda depends what you want to do with them.

Once I had the GPIO working, it was time to write a script that counts the usage. It really depends on your water meter what the formula in the script should be. The water meter in the screenshot above has several dials and one of those spins 1 time per liter (the one on the top right has scale x 0.1, so 1 revolution per liter).

First I set the water meter divider in the setup to 1000. Then, I wrote this script (there are a lot of print statements, but this shows what's really going on).
What the script does is:
- Retrieve the svalue from the water meter
- In the event of a pulse from the TCRT5000 via the GPIO port, add 1 (liter) to the svalue
- Write the new svalue to the device

I hope it's useful for somebody :).

Code: Select all

commandArray = {}

print('> Monitoring water consumption')

-- Water usage
-- Retrieve value from water meter device:
sWaterUsage = otherdevices_svalues['Water']

-- To have a better readable format, divide number by 1000:
sWaterUsagePrint = tonumber(sWaterUsage / 1000);

-- calculation is done with the unmodified water value
sWaterUsage = tonumber(sWaterUsage);

print(">> Utilities: Water usage until now is " .. sWaterUsagePrint .. " ");

if (devicechanged['GPIO_WATER'] == 'Close')
then
	sWaterUsageTot = (sWaterUsage + 1)
	
	print(">> Utilities: Water usage is now " .. sWaterUsageTot .. " ");
	commandArray['OpenURL']='http://IPADDRESS:PORT/json.htm?type=command&param=udevice&idx=164&svalue='..sWaterUsageTot..''
end

return commandArray
jossie67
Posts: 39
Joined: Wednesday 31 December 2014 12:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by jossie67 »

Hi D'rMorris,

Thanks for sharing your script, I think it a python script?
And what is you GPIO_water on the Pi I want to use GPIO17
Raspberry Pi (3x)
Master Domoticz installed on a Synology
RFXCOM RFXtrx433E USB
RFLink
USB Z-Wave Mini Adapter
Mi-light
QuinLED
Landis+Gyr ZME120ACd
Kamstrup_M401
USB-IR-Schreib-Lesekopf Alecto WS1700
Watermeter with TCRT5000
Kodi
DS18B20
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by sincze »

jossie67 wrote:Hi D'rMorris,

Thanks for sharing your script, I think it a python script?
And what is you GPIO_water on the Pi I want to use GPIO17
Ha, nice solution. Running WIringPi will result in a lot of false interrupts for the tcrt-5000 which have to be compensated.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by D'rMorris »

sincze wrote:
jossie67 wrote:Hi D'rMorris,

Thanks for sharing your script, I think it a python script?
And what is you GPIO_water on the Pi I want to use GPIO17
Ha, nice solution. Running WIringPi will result in a lot of false interrupts for the tcrt-5000 which have to be compensated.
Depends on the frequency of the interrupts...for a gas meter (which has slow revolutions) it is OK. This was (for me at least) just a small project to check if I could get it working.
We're currently looking for a new house, which will have a smartmeter in the future anyway. So, for me it's just for fiddling around a bit. The interrupt handling is also an issue in the current version of the Pi firmware I think. If I have too many interrupts, it will skip some. Or maybe I configured it incorrect :).

@ Jossie: No, it's not python, it's a LUA script and my GPIO_water is 18.
jvandenbroek
Posts: 37
Joined: Wednesday 12 March 2014 16:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by jvandenbroek »

Thanks D'rMorris, using your script successfully for a gas meter! Only moved the devicechanged rule to the top, otherwise it would constantly print the calculations, not just on an interrupt. :lol:

[edit]Well, not that successfully it seems. As stated above, due to the many false interrupts, Domoticz many times fails to catch the correct off (low) interrupt, but instead I get many on interrupts. Maybe putting a large cap on both ends of the line will help a bit, will try that later and post my findings here.[/edit]
[edit2]Tadaa, adding a large 1000uF elco at the TCRT5000 side (D0-GND) fixed the false interrupts :)[/edit2]
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by sincze »

jvandenbroek wrote:Thanks D'rMorris, using your script successfully for a gas meter! Only moved the devicechanged rule to the top, otherwise it would constantly print the calculations, not just on an interrupt. :lol:

[edit2]Tadaa, adding a large 1000uF elco at the TCRT5000 side (D0-GND) fixed the false interrupts :)[/edit2]

Just curious, can you send picture of total setup please?
I solved false interrupts by not using them at all, only polling the pin value :D
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by D'rMorris »

jvandenbroek wrote:Thanks D'rMorris, using your script successfully for a gas meter! Only moved the devicechanged rule to the top, otherwise it would constantly print the calculations, not just on an interrupt. :lol:

[edit]Well, not that successfully it seems. As stated above, due to the many false interrupts, Domoticz many times fails to catch the correct off (low) interrupt, but instead I get many on interrupts. Maybe putting a large cap on both ends of the line will help a bit, will try that later and post my findings here.[/edit]
[edit2]Tadaa, adding a large 1000uF elco at the TCRT5000 side (D0-GND) fixed the false interrupts :)[/edit2]
Haha, yeah that's right. I put it there because for debugging I wanted the pin values to print constantly.

Hey that's cool! I'm just learning how to work with condensators and stuff. Could you post a picture of the setup with the elco?
I have to put it serial to the D0 and GND? Or parallel?

@ Sincze: how do you "poll" the pin value?
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by sincze »

D'rMorris wrote: @ Sincze: how do you "poll" the pin value?
I use wiringPi library

Code: Select all

// What GPIO input are we using?
//      This is a wiringPi pin number
#define IN_PIN                          1
A nice function would be digitalRead in a loop.
int pin_value = digitalRead(IN_PIN);

Please find the script in the zip file. It is based on the interrupt script however... not using interrupts at all. :D due to the amount of fake onces.
It is not a script it is .c 8-)
Attachments
isrcounter.zip
Watermeter Script (Polling)
(2.94 KiB) Downloaded 403 times
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by D'rMorris »

Ah yes, the famous isrcounter :), found that one as well (I use wiringpi as well). Never got around to test it. My issue is that when there are too much interrupts, the gpio does not capture them. Something in the logs with interrupt in queue, skipping interrupt or something. Does the isrcounter fix this as well?
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by sincze »

D'rMorris wrote:Ah yes, the famous isrcounter :), found that one as well (I use wiringpi as well). Never got around to test it. My issue is that when there are too much interrupts, the gpio does not capture them. Something in the logs with interrupt in queue, skipping interrupt or something. Does the isrcounter fix this as well?
For TCRT-5000 position it wiseley just on the glass.
Facing straight down.
Adjust the screw it will give you at least a solid valid on / off (this doesn't prevent jumping of the interrupt, that will happen eventually)

Using the script attached it will poll the pin value in stead of the interrupt catcher.
For water it should be 1 on and 1 off. No such thing will happen < 1 sec. I tried it by filling up the bath tub.

In a case where you watermeter stops right at the edge of on/off the script will compensate a lot of fluctuations for you. (stable pin).

It is my best effort without any additional hardware attached to the tcrt-5000. And has been running nicely for over 58 days now.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
D'rMorris
Posts: 138
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by D'rMorris »

sincze wrote:
D'rMorris wrote:Ah yes, the famous isrcounter :), found that one as well (I use wiringpi as well). Never got around to test it. My issue is that when there are too much interrupts, the gpio does not capture them. Something in the logs with interrupt in queue, skipping interrupt or something. Does the isrcounter fix this as well?
For TCRT-5000 position it wiseley just on the glass.
Facing straight down.
Adjust the screw it will give you at least a solid valid on / off (this doesn't prevent jumping of the interrupt, that will happen eventually)

Using the script attached it will poll the pin value in stead of the interrupt catcher.
For water it should be 1 on and 1 off. No such thing will happen < 1 sec. I tried it by filling up the bath tub.

In a case where you watermeter stops right at the edge of on/off the script will compensate a lot of fluctuations for you. (stable pin).

It is my best effort without any additional hardware attached to the tcrt-5000. And has been running nicely for over 58 days now.
Thanks for the info, will try that. First I have to search what to do with the isrcounter. Any hints on where I have to put it? Do I need to recompile wiringpi?

Thanks so far anyway, you helped me in the right direction :)
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by sincze »

did you install the whole wiringpi including the c compiler? I can help you with the rest.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Bramz
Posts: 8
Joined: Wednesday 01 October 2014 14:28
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: NL
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by Bramz »

Is polling really the right way to go? I always read that it takes up a disproportional amount of processor time if the pulses to be counted are not widely spaced apart.
RPi B, RFXtrx 433e, KaKu switches, P1-Smart Meter cable v2, CO2 sensor, 1Wire-WirelessMultiSensor, SBFspot/PV-output
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by sincze »

Bramz wrote:Is polling really the right way to go? I always read that it takes up a disproportional amount of processor time if the pulses to be counted are not widely spaced apart.
I thought so to.
That is why I tried it out.
The process takes 0.3% of the processor.

Impact almost nothing and having all the fun of a working watermeter without a resistor.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by sincze »

Latest watermeter mount based upon tcrt-5000 sensor
Attachments
Watermeter mount
Watermeter mount
watermeter-20151202_203157.jpg (89.71 KiB) Viewed 11450 times
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
joostnl
Posts: 68
Joined: Wednesday 03 February 2016 19:22
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Watermeter through GPIO and TCRT5000

Post by joostnl »

Can someone write me a step guide to install, Isrcounter.
My script for water is working only i want to make it more accurate
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest