How to Use a Raspberry Pi and OCR to Read a Water Meter
By Ron
Overview:
This article describes how a Raspberry Pi 3 B+ computer uses Optical Character Recognition (OCR) to read a Neptune R900iTM residential water meter and determine water consumption. The project uses a USB camera to capture an image of the water meter display at user-determined intervals. The captured images are processed with OCR software to convert numerical images into mathematical values. The delta in these values is then used to calculate water consumption. A python program developed expressly for this project automates the entire process. The consumption data uploads to a website for remote retrieval or viewing.
Background:
This project was created because it is difficult to physically access the water meter for a manual visual reading. Water consumption data is available from the water company via an email report but only the monthly total consumption is reported. A goal of the project is to design a system that would query the water meter at any time and calculate the water consumption for the prior 24 hours.
The Neptune R900iTM residential water meter is popular with water companies because it is accurate, does not require an external power source, and uses radio frequency to wirelessly transmit consumption data. The data is transmitted to the private computer network owned by the water company. Unlike other meters, the Neptune R900i does not have a simple two-wire electrical interface through which the Raspberry Pi could connect for data retrieval. The meter only transmits data via radio frequency using a proprietary protocol. One could purchase a separate portable Neptune radio frequency transponder for data retrieval, but these cost thousands of dollars.
Methods:
The only viable way of using the Raspberry Pi to automate the retrieval of consumption data from the Neptune R900iTM was to use OCR software to scan periodic photographs of the meter display, taken by a USB camera. The OCR software chosen for the project was the Seven Segment Optical Character Recognition (SSOCR) developed by Erik Auerswald at the University of Kaiserslautern.
https://www.unix-ag.uni-kl.de/~auerswal/ssocr/
OCR Software:
Auerswald’s SSOCR software was a good choice for this project because it was specifically designed to read seven segment displays, runs on the Raspberry Pi’s Linux operating system, and is open-source. As the name implies, seven segment displays use 7 segments to define a number. The individual segments, a to g, are turned on to display numbers 0 to 9.
The SSOCR software uses a region of interest (ROI) based on X and Y coordinates to define where a number is located in an image. During prototyping, there was a problem using 1 ROI that included all 9 digits, the comma, and the decimal point. The SSOCR software would have difficulties interpreting the comma and the digits next to it. Errors were received and the numbers were unreliable. To overcome this problem, 3 ROIs were defined to identify 3 separate numbers and the comma and the decimal point were bypassed completely. This worked well. The numbers found were then concatenated into one final number with a Python program.
The python program uses 17 major steps to read the water meter, calculate the water consumption, and post the data to a database on this web site. Each step will be described later in the article.
Hardware:
The first part of the project was to mount a USB camera near the water meter to take pictures of the meter display. Since the water meter was located in a region of mild temperatures, it was located outside of the house, 46 cm below grade, in a concrete box.
In order to view water data on the water meter display, the meter must be energized and taken out of a state of hibernation. This is done by shining a minimum of 600 lumens of light onto the meter’s solar panel. The light source could be a flashlight or bright sunlight. When the meter “wakes-up”, it will first display the serial number, and then the water data. The first data screen that appears is the consumption in cubic metres and this is the total volume recorded since the meter was installed. After a few seconds, the meter will show the second data screen which is the current flow rate in liters per minute. The meter then oscillates every few seconds between the total consumption screen and the flow rate screen.
A Logitech C922 USB camera and an 800-lumen LED car taillight bulb are installed in a custom camera housing mounted over the water meter. The camera housing is fabricated from 4 inch PVC pipe fittings. When the LED bulb is turned on, the water meter is energized and the camera can then view the water data on the meter display.
A Widgetlords Pi-SPI-8KO relay board controls the 24 VDC power to the LED bulb. The relay board and the Raspberry Pi are both located inside the house, 9 metres from the water meter. A Bluerigger active USB extension cable, 10 metres long connects the camera to the Raspberry Pi. When connecting USB devices with cables longer than 4.5 metres, it is necessary to use an active extension cable that provides a signal booster at one end of the cable to prevent signal loss. A USB hub is installed to ensure adequate power for the camera.
Software:
The python program shown below runs every 24 hours with the Linux Crontab command.
Conclusion:
This project is a good example of how to use the Raspberry Pi for physical computing to interact with a device in our everyday life. Using inexpensive hardware and a few lines of python code, information contained in a water meter can be extracted to provide a better understanding of water consumption.