Design and Implementation of an Intelligent Water Regime Detection System

An intelligent water regime detection system was designed for water detection. In the designed system, water level is detected by a pressure sensor and water pH is detected by a pH meter. After being processed by the AD chip TLC2543, the data are sent to the MCU via serial communication and the detection result is displayed on OLED screen or Bluetooth mobile phone. The software adopts time-sharing and power-down operation modes, and combines the relay to turn on/off the MCU peripheral circuit to reduce power consumption. The measurement deviations of water level, pH, and voltage were respectively less than 2 mm, 0.1, and 0.01 V and the minimum operating current was less than 6 mA. The low-power, high-precision and intelligent water regime detection is realized by the designed system. Water is closely related to human life. According to China’s Standard for Drinking Water Quality, the pH of drinking water should be between 6.5 and 8.5 and the optimum pH of drinking water is 7.5. In daily life, the pH is generally detected with pH indicator or pH test paper, but the detection precision is not high and the detection result may be affected by contamination. Therefore, it is of great significance to design a detector that can quickly, conveniently, and accurately detect water regime indicators, such as pH [1]. In the study, we designed and produced the prototype of an intelligent detection system, which could quickly realize the detection of water level and pH with high precision and low power consumption in an easy operation way.

Water is closely related to human life. According to China's Standard for Drinking Water Quality, the pH of drinking water should be between 6.5 and 8.5 and the optimum pH of drinking water is 7.5. In daily life, the pH is generally detected with pH indicator or pH test paper, but the detection precision is not high and the detection result may be affected by contamination. Therefore, it is of great significance to design a detector that can quickly, conveniently, and accurately detect water regime indicators, such as pH [1] . In the study, we designed and produced the prototype of an intelligent detection system, which could quickly realize the detection of water level and pH with high precision and low power consumption in an easy operation way.

System scheme
The system consists of a microcontroller, a pH detection module, a water level detection circuit, an AD conversion circuit, an OLED display circuit, a Bluetooth module, a power supply circuit, as shown in Figure 1.  The system adopts STC12C5A60S2 as MCU. The MCU is characterized by the strong arithmetic operation, fast processing speed, flexible software programming, and simple arithmetic and logic control and widely applied in various fields due to its low cost, low power consumption, hibernation function and fast operation speed. Its power-down mode current is less than 0.1 μA, which is suitable for the low power consumption requirements of this system [2] .
A water pressure sensor is used to detect water level in the system. The main sensing element in the sensor is a pressure-sensitive film, which is connected to a flexible resistor. When the pressure to be measured is changed, the film deforms as pressure decreases or increases and the resistance of flexible resistor becomes larger or smaller. The change in the resistance value is reflected as a voltage signal of 0-5 V and then the signal is converted into a digital signal by AD chip and transmitted to the MCU for processing [3] .
A pH composite electrode is used to measure water pH in the system. It is a plastic shell-fillable composite electrode composed of a glass electrode and a reference electrode. The composite electrode is a chemical sensor for converting H + decay rate of a solution into a certain potential signal and widely applied in pH measurement. The electrode is rechargeable and fully shielded, so that it can effectively prevent the interferences from external electric field, oxidants, reducing agents and other impurities. Before pH measurement, positioning and slope calibration must be performed with a standard buffer solution with known pH [4] .
2 System hardware design

MCU minimum system
In the STC12C5A60S2 microcontroller, the MCU is integrated with a dedicated reset circuit. When the frequency of external crystal oscillator is below 12 MHz, the RST reset pin can be directly connected to a resistor with the resistance of 1000 Ω for protective earthing without a capacitor. It has four 16-bit timers, two on-chip resources such as timer/counters compatible with the traditional 8051 microcontroller and is characterized by low power consumption and hibernation function [4] . The MCU minimum system circuit is shown in Figure 2.

Water level detection circuit
The system adopts MP3V5004 air pressure sensor. It has a maximum error rate of 5.0% in the temperature range from 0°C to 85°C and is suitable for microcontrollerbased systems. The barometer introduces air pressure signal from the bottom end of water meter, and the air pressure value detected is an analog signal, which is converted into a 12-bit digital signal by AD chip and sent to MCU for processing with AD5 pin. The water level is linear with air pressure. The higher the water level is, the larger the air pressure is. The water level detection circuit is shown in Figure 3.

pH detection module
The system adopts a pH acquisition sensor module, which consists of E-201-C lightning magnetic pH composite electrode and DS18b20 temperature compensation circuit. The electrode outputs an analog signal via the BNC and the circuit amplifies this signal. During pH detection, the pH value is converted to an analog voltage signal of 0~5 V. The AD chip reads the output voltage, which is converted into a 12-bit digital signal and sent to MCU. The water pH is measured finally by MCU processing according to the standard curve.

Power detection circuit
As shown in Figure 4, P1.7 pin is connected to the MCU. The MCU controls the high and low levels of its pins and then realizes the on-off control of 8050 triode to supply power. Through the partial voltage of the two resistors, the power supply is changed to 1/2 VCC and connected to AD2 pin of AD chip. The AD chip converts it into a 12bit digital signal, which is sent to MCU. The MCU receives the signal and multiplies it to obtain the current power voltage, which is then displayed on OLED screen.

OLED display circuit
The system adopts high-brightness and low-power OLED screen SSD1306 module. The module shows pure color and has good visual effect in sunlight. It uses 5-V power supply and 4-wire SPI communication mode. It is characterized by simple operation, abundant functions and various control instructions. The MCU can control the brightness, contrast, and switch boost of OLED through instructions. The OLED display circuit is shown in Figure 5.

AD conversion circuit
The system adopts serial A/D converter TLC2543, which completes 12-bit A/D conversion process with the switched capacitor successive approximation technology. The serial input structure chip can be conveniently connected to the MCU to save I/O resources. It is characterized by10-s fast conversion in the operating temperature range, 11 analog input channels, 3 built-in self-test modes and single-and double-polarity output [5] . In the chip, reference voltage is Vref and input voltage is Vin. The output voltage is expressed as: The system needs to measure pH, water pressure and power supply voltage of 0~5 V, so Vref is set as 5.0 V. The 12-bit AD chip means that there are 2 12 state outputs. The voltage (resolution) indicated by each output state is expressed as: The maximum value of the conversion output is calculated as: The deviation of AD conversion voltage during the measurement is less than 0.01 V, which ensures the measurement accuracy of the system.

Bluetooth module
The HC06 Bluetooth module is selected in the system. It is a low-cost transceiver chip with short transmission distance and low power consumption. It can achieve secure and simple pairing with Bluetooth mobile phone and enhance communication security. In the working mode, Bluetooth module is connected with MCU via serial communication mode and sends water regime data. The Bluetooth mobile phone successfully matched receives data by wireless communication and displays data on its screen. In order to reduce the power consumption of the system, Bluetooth module and OLED module are powered via relays and they are not powered when the microcontroller is dormant.

System software design
The functions of the detection system can be designed according to the following three parts: detection of water level, water pH and power supply voltage, displaying results through OLED and Bluetooth mobile phone, and turning on/off hardware circuit excluding MCU via the relay. Therefore, time-sharing and power-down modes are adopted in software design [6] . In the working mode, the pressure sensor detects water level; the pH meter detects water acidity and alkalinity, and the partial resistors sample power voltage. Then, the three data are converted into 12-digit values by TLC2543 chip and sent to STC MCU for processing. Finally, the detection results are displayed. When it is not in the working mode, the MCU enters hibernation, the relay is switched off and does not supply power to all peripheral circuit to reduce power consumption.

System testing
As shown in Figure 7, the prototype of the detection system is composed of water meter part and circuit part. The water meter has water level scale. An solution can be added into the meter via its top and in a pH meter can be placed from the top. A ventilation hole is set on the Start System initialization MCU works and the relay is switched on.
Water level detection circuit acquires the data, and A/D converts.
pH detection module acquires the data, and A/D converts.
Power detection circuit acquires the data, and A/D converts.
OLED display, Bluetooth communication and mobile display.
MCU enters hibernation, and the relay is switched off.
MCU wake up? N Y Figure 6. Program flow chart.
bottom of the meter and connected to an air pressure sensor. The circuit is housed in a square box with switches, wake-up buttons, voltage and current sensing terminals, and an OLED panel. In the working mode, the first line on OLED displays "water regime detection system"; the second line displays "water level" and the unit "mm"; the third line displays "pH"; the fourth line displays "battery voltage" and the unit "V". The detection experiments of the prototype system were carried out with pure water and white vinegar, and various water data were obtained and recorded. The system was tested for 5 times and water level, pH, voltage and current were detected. All measurements reached a stable value within 5 s and the tests could be completed within 1.5 min. The measurement results are displayed. The detected water levels are shown in Table 1. The water pH detection results are shown in Table 2. When detecting, the water level remains at 100 mm. The power supply voltage and current detection results are shown in Table 3. The current was directly measured with a multimeter.

Conclusion
In the detection system, an air pressure sensor is used to detect water level with the deviation of less than 2 mm and a pH meter is used to detect water pH with the deviation of less than 0.1. In addition, a resistor divider is used to sample power supply voltage with the deviation of less than 0.01 V. OLED screen and Bluetooth mobile phone are used to display test results. Time-sharing and power-off processing modes are adopted in the system. The minimum operating current is less than 6 mA. Based on these four key parameters, the functional requirements of water regime detection system are realized. The water regime detection system has high intelligence and simple operation and realizes low power consumption and high precision.