Thread Content
Author: Zhou Xiaolin, Jiao Renyu, Henan Provincial Fisheries Research Institute (450044). Source: \"Application of Electronic Technology\". Abstract: It introduces the implementation method of a water quality monitoring system based on microcontrollers. This method overcomes the shortcomings of traditional instruments, enables intelligent water quality monitoring, and meets the needs of advancements in aquaculture research and environmental monitoring. Keywords: water quality monitoring, microcontroller, automatic control. The ongoing advancement in aquaculture research and the increasing emphasis on environmental protection have led to higher demands for continuous and real-time monitoring of various water quality parameters. For example, in aquaculture research, it is necessary to continuously monitor the water quality of various water bodies such as ponds, reservoirs, and industrial fish farming ponds ; In terms of environmental protection, various unmanned water quality monitoring stations are established to monitor and record changes in water quality in rivers, lakes, groundwater, and along coastal areas; the data is then transmitted in real time to control centers via various communication methods for further processing. Traditional water quality monitoring methods, due to their long testing cycles and inability to provide real-time monitoring, can no longer meet the needs of fisheries research and environmental protection. This system uses a microcontroller as the main controller, combined with the latest peripheral devices, to simultaneously monitor changes in 11 parameters such as dissolved oxygen, temperature, pH value, conductivity, and ammonia nitrogen. These values are displayed on an LCD screen, and they are recorded in EEPROM at set time intervals ; It can also communicate with remote computers via the RS-232 serial port to perform functions such as data transmission, remote control, and remote calibration ; It is also possible to control devices such as alarms, aerators, and circulation pumps through the control interface, thereby achieving automatic control functions. 1 System Principle The block diagram of the system’s hardware structure is shown in Figure 1. The main control chip is the 89C52 from ATMEL Corporation. The main components of the system include: sensors, signal conditioning units, microcontrollers, non-volatile EEPROMs, analog-to-digital converters, real-time clocks, liquid crystal displays, power supply monitoring circuits, keyboards, 8-bit bidirectional I/O ports, 8-bit switch control outputs, and communication interfaces for connecting to a computer. The sensor signals convert changes in various parameters into corresponding weak current or voltage signals; after being conditioned by precision amplifiers to produce standard 0–5V voltages, they are sent to an analog-to-digital converter to be converted into corresponding digital voltage values, which are then fed into a microcontroller for further processing. The microcontroller performs operations such as numerical filtering and compensation based on different sensors, and then sends the results to the LCD display for real-time presentation; at the same time, the data is stored in non-volatile EEPROM at regular intervals according to preset values. These data can be directly read or cleared on the LCD display using the buttons on the device, and they can also be read by a computer via the RS-232 interface. The system utilizes 4 buttons to perform functions such as automatic calibration, zeroing, setting the data acquisition and storage interval, data reading, and data clearing. The power supply can be powered by alternating current or batteries; a dedicated power monitoring circuit monitors the power supply status and switches automatically. When the battery voltage falls below the specified standard voltage, it is displayed on the LCD to indicate that the battery needs to be replaced. 2 Key Components and Technologies 2.1 Sensors 2.1.1 Temperature Sensors Based on the requirements of water quality monitoring, we selected the DS1820 digital thermometer from Dallas Corporation in the United States; it is the size of a transistor and uses single-wire digital transmission. The power for reading and writing temperature data comes from the data line, so no additional power supply is required; each DS1820 has a unique serial number, and multiple DS1820s can be connected on the same bus. These features can meet various needs; for example, without the need to add additional signal lines, multiple DS1820 sensors can be connected in series as required, allowing for the simultaneous monitoring of the temperature of water in the upper, middle, and lower layers, as well as the air temperature. It was found during use that there is a certain error between the measurement values provided by the DS1820 and the actual values, with each error being different. To enable interchange without modifying the program or performing calibration, the error value is stored in the DS1820 through a special transformation in the two bytes TH and TL, which are originally used to store the high and low temperature thresholds. These two bytes are of EEPROM type, so the data is not lost even in the event of a power outage. When the microcontroller reads the measured temperature, it also reads in these values, eliminates the error, and obtains the actual value. This allows the probe or DS1820 to be replaced without the need for re-calibration. 2.1.2 Dissolved oxygen sensor The dissolved oxygen sensor is a self-developed polarographic thin-film electrode. The DC voltage of 0.7V applied to the electrode by the instrument is called the polarization voltage. Oxygen in water or air passes through the membrane and causes the following reactions at the electrode: Cathode: O2 + 2H2O + 4e– → 4OH– Anode: 4Ag + 4Cl– → 4AgCl + 4e– Oxygen is reduced at the cathode, resulting in an electric current being generated at the electrode; at a constant temperature, the magnitude of this current is linearly related to the oxygen concentration in the sample being tested. By plotting the output current on the y-axis and the oxygen concentration on the x-axis, a straight line is obtained that passes through the origin. The slope of the line varies with different temperatures; this is the temperature coefficient of the dissolved oxygen electrode. There are two reasons for the occurrence of a temperature coefficient: first, the oxygen permeation rate through the electrode film changes with temperature; for every 1-degree increase in temperature, this rate changes by about 3%, and as a result, the current generated by the oxygen electrode increases as well. Even if the dissolved oxygen concentration remains constant, changes in temperature lead to variations in the electrode’s sensitivity, thereby causing reading errors ; Secondly, the saturated solubility of dissolved oxygen in water varies with temperature. Since this type of electrode is a sensor sensitive to oxygen partial pressure, the same oxygen partial pressure will produce the same current at different temperatures, but the actual concentration of dissolved oxygen is not the same. To accurately measure dissolved oxygen levels, traditional instruments use thermistors integrated into the circuit for temperature compensation, but this requires repeated tuning of the circuit, and both the compensation range and accuracy are limited. In this system, temperature and dissolved oxygen are measured separately, with compensation performed using software; there is no need to adjust the circuit for temperature compensation. Three methods are employed in software design to compensate for the temperature coefficient: First, based on the actual values of dissolved oxygen in water saturated with air at various temperatures as specified in national standards, a curve relating temperature to saturated dissolved oxygen is created; the resulting fitting equation is stored in the microcontroller to eliminate the second factor affecting the temperature coefficient ; Second, the analog-to-digital conversion values of the probe in water saturated with air at various temperatures are measured; a curve showing the relationship between temperature and these conversion values is created, and a fitting equation is obtained which is stored in the microcontroller, thereby eliminating the first factor that affects the temperature coefficient ; Third, in actual use, the parameters used for saturation correction in air are incorporated into the fitting equation in real time, thereby eliminating errors that occur during probe usage. Compensation for salinity and air pressure has also been added to the software. It is the computing capabilities of microcontrollers that enable temperature changes to be compensated for, a task that is difficult to achieve with traditional instruments. For parameters such as pH value and conductivity, commercial probes are used; depending on the characteristics of each probe, different signal conditioning circuits are designed to convert the signals into a standard input voltage of 0–5V, which is then fed into the system’s A/D converter. 2.2 Main Chips 2.2.1 Control Chip The control chip chosen is the AT89C52 from ATMEL Corporation; it features 8 kilobytes of Flash program memory, which eliminates the need for external storage expansion. This facilitates easy modification of programs during system development, reduces the time required to develop the system, and also allows for program modifications or upgrades as per the user’s needs and the evolution of requirements, ensuring that the system continues to meet the user’s latest demands. 2.2.2 Real-time Clock Chip The real-time clock chip used is the DS12C887 from Dallas Semiconductor in the United States; it includes a crystal oscillator, an oscillation circuit, a charging circuit, and a rechargeable lithium battery. It contains a non-volatile clock, a centennial calendar, an alarm, programmable interrupts, a square wave generator, as well as 114 bytes of non-volatile static RAM for user use. 2.2.3 A/D Conversion The A/D conversion is implemented using the TLC2543 from TI Corporation in the United States. The chip contains a 14-channel multiplexer that allows selection of one channel from 11 external analog inputs or three internal self-test voltages for conversion and output. It features a sample-and-hold circuit, so the main processor only needs to issue a command to read a specific channel. 2.2.4 Monitor: The monitor uses the LCD display module MDLS-16165 from Seiko Electric; it is capable of displaying 16 ASCⅡ characters, as well as custom special characters and graphic symbols simultaneously. It integrates the LCD controller, dot matrix driver, and character memory on a single circuit board, creating a liquid crystal display module that is easy to use; its application has since become standardized. 2.2.5 Data Recording Chip The data recording chip is the X84641, a serial EEPROM device with a streamlined interface and a new design, manufactured by the American company Xicor. It does not require connection logic for a microprocessor or a system bus interface; it interfaces with most microprocessors by directly utilizing the standard microprocessor control signals (OE, WE, CE) along with simple read/write timing. This system sets each batch of measurement data to 32 bytes, including the date and time of the measurement as well as the various parameters measured. Among them, the date and time take up 4 bytes; each parameter, being a floating-point value, also occupies 4 bytes. This allows for storing 7 measurement values, which is sufficient to meet the requirements. In an 8K EEPROM, 240 sets of data can be stored. The remaining 256 bytes are used to store setting information, status, and intermediate state values during software operation; they can also hold records of the 24 times the control device was turned on or off, including the device name as well as the date and time of each turn-on and turn-off. 2.2.6 Serial Communication: To transmit the collected data in real time or connect to computers over long distances, the standard asynchronous communication mode of the 89C52’s serial communication interface is utilized, with the interface chip MAX232 being used to convert it into a standard RS-232 interface. 3 Software Design: The function of the software is to perform A/D conversion on the sensor signals from various channels via precision amplifiers, to carry out compensation processing on the resulting digital values, and finally to display them on an LCD, store them, or transmit them over long distances through communication ports. The flowchart of its main control program and the flowchart of the keyboard analysis module are shown in Figure 2 and Figure 3 respectively. The software of this monitor is developed using a combination of C language and assembly language. For components with strict timing requirements, such as DS1820, TLC2543, X84641, etc., separate modules are written in assembly language to be called by the main program. The main control program, display control program, keyboard program, and the compensation calculations for various data streams ensure accuracy during the compensation processing of these data streams. During the programming process, a modular design is adopted to take into account value transferability, future functional upgrades, and ease of debugging. 4 System Testing and Results During the development process, we first tested the dissolved oxygen probe, developed temperature, dissolved oxygen, and pH modules, and conducted application tests. When measuring dissolved oxygen, a certain flow rate of water is required; however, water in ponds is generally still. Therefore, a small aquarium is attached to the probe, equipped with a water circulation pump, and its operation is controlled by software. Meanwhile, the on/off signal of the aeration machine is sent to this monitoring device, allowing for the simultaneous monitoring and recording of when the aeration machine starts and stops. This facilitates the study of its impact on dissolved oxygen and other parameters. The data collection interval is set at 15 minutes, enabling continuous monitoring and recording for 60 hours, with good results.