2303 views|2 replies

86

Posts

0

Resources
The OP
 

Open Source Tutorial | Design of Smart Ecological Fish Tank [Copy link]

summary:

With the rapid development of science and technology, there are many fish tanks in the domestic market, with inconsistent functions, and most of them are non-intelligent. The functions are not flexible and convenient to use, and the overall performance cannot be improved. In an era when science and technology change our lives, it is imperative to carry out technological transformation of traditional fish tanks, which will bring more happiness to people.


This paper takes STM32 F103C8T6 microcontroller as the core and designs a smart temperature control, smart water change, smart feeding, smart lighting and smart display system based on the Gizwits IoT platform . The system is based on esp8266 WiFi module communication and can be remotely monitored by mobile phone. The hardware circuit structure of this design is simple, divided into a single-chip microcomputer core controller module, NTC temperature sensor to detect the water temperature of the smart fish tank, OLED to display the current value, temperature value and oxygenation rate of the device, etc., the key circuit is used to adjust the oxygenation rate, the threshold of the water temperature parameter, control the feeding and fill light, and the relay is used to drive the water pump to add water to the fish tank. It also realizes the real-time data upload to the mobile phone APP for control through the ESP8266WIFI module, and the various functions of the fish tank can be adjusted and controlled by buttons or mobile phone APP. The design of the smart fish tank system based on the Internet of Things in this paper has certain significance for the development of the contemporary Internet of Things industry. 1 Introduction: The development of smart fish tanks based on the Internet of Things is of great significance. Therefore, according to market demand, the product designed this time adopts STM32, which integrates multiple control functions, including intelligent temperature control, intelligent water change, intelligent oxygen supply, intelligent lighting and intelligent display. The system is connected to the Gizwits mobile phone APP through a WiFi module to realize remote monitoring of the temperature, lighting and water changes of the fish tank through the mobile application, and can display the time, water temperature, current, power and power consumption statistics on the display. In summary, the design and implementation solution of the smart fish tank monitoring system based on the Internet of Things can save the tedious manual management, and transform it into macro control under the passive management mode. When the person monitoring is not there, the control of the feeding and lighting system can be controlled according to the WeChat terminal, and the current and power can also be adjusted. For large aquariums, it can save a lot of manpower and material resources. For the family environment, it can improve the harmony of the family, which is of great significance to the development of modern life. 1.1 The main work completed by this design









Based on the above research background and research significance, this paper introduces in detail the wireless fish tank intelligent monitoring system based on stm32 microcontroller and ESP8266WIFI docking with Gizwits IoT cloud platform to realize the remote control function of the fish tank. The hardware circuit structure is simple, consisting of some sensor modules and system hardware circuits, including ESP8266WIFI communication module, OLED human-computer interaction display module, button circuit control module, relay drive circuit module, water temperature detection AD processing circuit, and six circuit modules such as system current and voltage detection. Among them, the core control microcontroller is STM32F103C8T6, the human-computer interaction module uses OLED12864 to display various parameter data, and uses buttons to adjust each mode as an input device.
This article is structured as follows:
The first part introduces the design background of the system, and introduces the overall design and research purpose of the intelligent fish tank control system based on the Internet of Things.
The second part is to study the communication principles of each module of the system, including the establishment of WIFI module or Gizwits terminal server.
The third part is to complete the schematic diagram and PCB diagram of the entire IoT smart fish tank system.
The fourth part is to complete the introduction and application of the development environment used by the system, and to write the program design of the sub-functions and main functions of each module.
The fifth part is to complete the PCB design of the system, and then complete the welding and physical functional testing of the system.

2.1 System Function Analysis

(1) Based on the STM32 hardware system, combined with ESP8266WiFi communication technology, it connects to the Gizwits Cloud platform to realize remote control of lighting and relays through mobile phone APP.
(2) The system displays basic information such as time, water temperature, current, power, and power consumption in real time, and can be controlled by APP.
(3) The system’s mobile phone terminal can remotely cut off the output control of the device with one click, which is the “emergency stop” function.
(4) LED lighting can achieve brightness adjustment, and oxygenation can achieve rate adjustment. This function can be controlled remotely or by mobile phone.
(5) The human-computer interaction uses an OLED display screen, which has a good user-friendly operation interface.
(6) The device can be connected to the Internet and exchange information with the Gizwits Cloud platform in real time, so that the mobile phone can remotely control the device and monitor the device operation data.

2.2 Overall system design

This idea was determined by comparing and analyzing the hardware module selection options. The overall system structure block diagram is shown in Figure 2.1, and the entire system is divided into the following components: STM32 core control, button adjustment, OLED display, ESP8266 perception layer distribution network, relay drive circuit, fill light LED lighting system, and power supply voltage stabilization circuit.
When the system is running, the controller reads the AD value output by the temperature detection circuit composed of temperature sensing elements through the program to read the current output temperature value C. The four relays control the heating circuit, the fill light circuit, and the oxygen supply circuit respectively, and output a certain current and voltage signal. The temperature test uses a probe-type DS18B20 sensor. The input voltage and current of the system are collected by the DACMP2303 conversion circuit and then converted to voltage through the internal AD conversion, and then the device power is calculated. When the system is running, the controller accesses the ESP8266WiFi module through the serial port, uploads it to the Gizwits Cloud terminal server through the GAgent protocol, and displays it through the mobile phone APP after the microcontroller data is processed. When the user wants to adjust the manual control of the heating or fill light, he only needs to send instructions through the mobile phone APP to realize the remote control function. Finally, the system scans the buttons, responds to the button input and controls the OLED display to display various related data information to complete the human-computer interaction.


2.3 Selection of main components 2.3.1 Main control microcontroller

Solution 1: The main feature of the STM32F103C8T6 microcontroller is its fast running speed. This is due to its core architecture Cortex-M3, which is the most classic architecture in the ARM series. The STM32 series microcontrollers happen to use this architecture, which not only improves the running speed of the microcontroller, but also fundamentally improves the performance of the microcontroller. From the perspective of memory, the STM32 series microcontrollers have at least 16K of memory, and are also equipped with AD converters, I2C interfaces, and SPI interfaces, which simplifies circuit connections.
Solution 2: In the current main controller, the architecture of the STC89C52 microcontroller is still the 8051 architecture unique to the traditional 51 series microcontrollers. Basically, the programs and pins of each 51 series microcontroller are universal. From the perspective of the microcontroller pins, this microcontroller has 32 I/O ports that can be developed and used, and the functions of the pins are also very clear, which can help developers to quickly design circuits and reduce the difficulty of system development from both software and hardware aspects. However, this microcontroller can only accommodate 8K of code, which will reduce the system running speed.
Conclusion: The running speed of STC89C52 microcontroller will affect the overall system, while the software and hardware of STM32F103C8T6 microcontroller are simpler and meet the system requirements, so STM32F103C8T6 solution is preferred.

2.3.2 Selection of display module model

Solution 1: LCD1602 is a liquid crystal display with a display capacity of 32 characters, including uppercase and lowercase letters, symbols, simple graphics and other contents. When using LCD1602, the display area of the display can be controlled directly by voltage. If you want to know more about LCD1602, you can refer to the manual of the display. From the manual, you can find the code of the display and directly call and modify it. You can also learn about the circuit and pin functions of LCD1602. However, this module cannot display text and pictures, and many data information cannot be displayed completely. Therefore, from the perspective of software and hardware and display content, other design solutions must be sought.
Solution 2: This system design uses a 0.96-inch OLED (Organic Light-Emitting Diode), which is the abbreviation of organic light-emitting diodes, and an LCD display. Considering low power consumption and interactive friendliness, LCD display must be the first choice. Although traditional character-type LCDs can meet the above two requirements, compared to portability, the use of OLED displays will be more superior and very suitable for portable devices. This design uses OLED to support a maximum of 64 characters, with 4 lines and 16 characters per line. In addition to supporting all ASCII codes, it also comes with a font library. It is very convenient to display information. The displayed characters support two different colors: yellow and blue.
Conclusion: OLED12864 has more advantages in display and meets the requirements of this system, so option 2 is selected.

2.3.3 Selection of wireless communication solutions

The ESP8266 series wireless module is a cost-effective WiFiSOC module. It can quickly connect to the Internet and realize "IoT technology" in just five steps. The WiFi module uses a low-power 32-bit CPU and can be used as a processor with a main frequency of up to 160MHz. It has a built-in 10-bit high-precision ADC conversion module, with cache capabilities, easy to use, and simple development logic. The key is that the data transmission is relatively stable and can be connected to the Gizwits Cloud terminal server for remote monitoring. The following table is the working instructions of ESP8266.




2.3.4 Temperature sensor solution selection

In order to detect the temperature in the fish tank in real time, we need some waterproof temperature sensors. This design uses NTC temperature sensor, which is a thermistor and probe. The principle is: the resistance value decreases rapidly with the increase of temperature. The actual size is very flexible. They can be as small as 0.010 inches or very small diameters. The maximum size is almost unlimited, but usually less than half an inch. The general structure consists of NTC thermistor, probe (metal shell or plastic shell, etc.), extension wire and metal terminal or connector. The measured data is very stable and the error is very small.

Figure 2-3 NTC temperature sensor
Its characteristics are generally high sensitivity, high resistance and B value accuracy, good consistency and interchangeability, and the use of double-layer encapsulation technology, with good insulation sealing and resistance to mechanical collision and bending.

2.3.5 Selection of relay drive scheme

In order to drive the relay to work more effectively, the system adds a ULN2003 driver chip. The main function of this chip is to amplify the input current and then drive the 5V and 12V relays, because the module circuit driven by the relay requires a larger current and voltage to work. This chip can be used to set pulse drive stepper motors, drive motors or DC motors. The more effective and best choice is to drive relays to control equipment, such as water pumps, voltage and current transformers, etc. And when used directly, the chip is roughly the same as some other similar chips in principle, so it can be used and tested directly.
Figure 2-4 ULN2003 chip logic diagram



3 System Hardware Circuit Design

The STM32F103C8T6 microcontroller can be said to be the control center of the system. External devices need to be directed and coordinated by the microcontroller through internal programs to ensure the completion of specific functions. Building together modules that can realize their own functions can effectively reduce the complexity of system production.

3.1 STM32F103C8T6 MCU Minimum System

The schematic design of the minimum system board of this system is shown in Figure 3.1. It consists of the chip controller, oscillation circuit, crystal oscillator circuit and serial port download circuit in the minimum system.
Figure 3-1 Minimum system unit circuit

3.1.1 Crystal Oscillator Circuit

In the single-chip microcomputer, the position of the crystal oscillator circuit is irreplaceable. This part of the circuit plays a decisive role in whether the system can be successfully started. The crystal oscillator circuit and the crystal oscillator inside the single-chip microcomputer are connected to form a crystal oscillator circuit, which can make the single-chip microcomputer have a higher operating speed. It can be said that the crystal oscillator circuit provides an important foundation for the operation of the single-chip microcomputer.
The STM32F103C8T6 microcontroller has an 8MHZ crystal connected to the OSCIN and OSCOUT pins. You can see it on the microcontroller. The 20PF capacitor is used to ensure faster and more stable operation of the microcontroller. The crystal oscillator circuit is shown in Figure 3.1.
Figure 3-2 Crystal oscillator circuit

3.1.2 Reset Circuit

There is also a white button on the microcontroller, which is the reset circuit button. It can support the microcontroller to complete the program initialization and directly execute the system from the beginning. The RST reset pin of the STM32F103C8T6 microcontroller is connected to the corresponding resistor and capacitor, and the reset can be controlled by pressing the button. In the voice classification trash can system, a direct and convenient button reset method is selected, with a resistance of 10K and a capacitor of 10μF. Pressing the connected button can restart the system. Figure 3.2 shows the reset circuit.

Figure 3-3 Reset circuit

3.1.3 Power supply circuit

The power module circuit is shown in Figure 3.6. This system requires two voltages. Since the voltage required by the OLED12864 display and WiFi communication module is 3.3V~5V, and the MCU works at 3.3V, and since the main control MCU is powered by 3.3V, the AMS1117 three-terminal regulator module is selected to generate 3.3V voltage. Capacitors E1 and C22 are input capacitors, and their function is to prevent voltage inversion after power failure. C23 and E2 are output filter capacitors, and their function is to suppress self-oscillation and stabilize the output voltage.
Figure 3-4 Power supply circuit
However, the system needs a 12V voltage to power the relay module. The voltage and current power required by the relay-controlled device is relatively large, so an MP2303 external power adapter is used, and then the voltage is stepped down to meet the needs of the entire device. The module input voltage is 4.7v-28v, the output voltage is directly adjusted from 0.8V to 25v, and the output current is continuously outputted at no less than 3A.
Figure 3-5 MP2303 module voltage reduction principle diagram


3.2 EEPROM storage circuit design

The EEPROM storage module of this circuit adopts AT24C04 chip, which is used to store various electrical parameters and record the parameters of the threshold values of various sensors, so as to save the data in case of power failure.
Figure 3-6 EEPROM storage circuit

3.3 ESP8266WiFi Circuit Design

The ESP866 circuit design is shown in Figure 2.2. The GPIO port is a general IO port with an internal pull-up and two working modes: floating GPIO0 is working mode, and pulling GPIO0 down is download mode. Tantalum capacitor E1 is used between VCC and GND to ensure that the WiFi module maintains better performance for a long time.
Figure 3-7 ESP8266WiFi circuit


3.4 Design of relay drive circuit

ULN2003 is used to drive the control relay, which not only simplifies the complex circuit, but also amplifies the current output by the MCU pin, thus improving the load capacity of the system. When using this IC, many people like to connect a diode in parallel at both ends of the driving inductive load for freewheeling or fast discharge. In fact, this is not necessary at all. The freewheeling diode is integrated inside the IC. Here is a classic driving circuit for driving the relay circuit, as shown below:

Figure 3-8 ULN2003 drive circuit
There are two points to note:
First of all: the COM pin, i.e. pin 9, must be connected to the positive terminal of the driver power supply (not the positive terminal of the chip power supply).
Second: The GND pin (i.e. the ground pin of the chip) must form the same potential as the negative pole of the driving power supply.
Figure 3-9 Relay control circuit


3.5 Design of temperature detection circuit

The temperature detection circuit adopts internal AD conversion. In the circuit design, a 100nf capacitor is used to filter the collected signal first. A probe-type NTC temperature sensor is connected to the P7 port. The analog signal collected by the probe is filtered and transmitted to the microcontroller. After AD conversion, the analog signal is converted into a digital signal, and the temperature is displayed on the display.

Figure 3-10 Temperature detection circuit


3.6 Current sampling circuit design

As shown in the figure below: R15 constantan wire is used as a sampling resistor, and after passing through the LM358 differential amplifier circuit, R14, R17, R13, and R18 amplify the input current, and R16 and C12 perform RC filtering on the output, Rp18=Rp13, Rp14=R17. Vout=Rp18/Rp17*(Vin+-Vin-). The output current is transmitted to the PA5 pin of the microcontroller, and then the current size is displayed on the OLED display after the internal AD data processing of the microcontroller.
Figure 3-11 Current acquisition circuit


3.7 Key Circuit Design

In order to meet the needs of adjusting various parameters by buttons, a total of four buttons are designed, which are connected to the four interfaces PA0, PB12, PB13, and PB14 respectively. Button 1 is used to control the switching of the OLED display interface to adjust the temperature, oxygenation rate, etc. Button 3 can set the increase of parameters such as temperature, fill light intensity, and oxygenation rate. Button 4 is used to reduce the parameter value. Button 2 is the confirmation button. After each adjustment, button SW2 will store the current changes in the system.

Figure 3-12 Button control circuit


3.8 Alarm Circuit Design

A passive buzzer circuit is added to the system, which is mainly used to alarm when the system is abnormal. Usually, a square wave signal is input through the BUZZER pin. The circuit also uses an NPN transistor as a switch for driving. The high level of its base makes the transistor saturated and turned on, making the buzzer sound, while the low level of the base turns off the transistor and the buzzer stops sounding.
Figure 3-13 Button control circuit



4 System software design

The hardware part of the portable wind-solar hybrid system has been introduced in the hardware circuit chapter of the first three chapters. Now we will introduce the next step of software development. The program code programming software KEIL and C language play a major role in the software part of the system to achieve the purpose of software programming.

4.1 Introduction to Software Development Environment

In this design, a compiler software developed by Keil, a German company, for arm core controllers is selected. The software integrates the most advanced technology in the industry. Keil5 software is particularly convenient to use. It occupies a 64-bit system type, is compatible with WIN7/WIN8/WIN10, and the download speed of SWD mode is five times that of Keil4. Its features include integrated development environment, debugger and simulation environment. It perfectly supports Cortex-M, Cortex-R4, ARM7 and ARM9 series devices, and there are a large number of projects that allow users to quickly become familiar with powerful built-in features.

4.2 Main program design

In order to meet the real-time requirements of water temperature, current, power consumption and power collection, this program uses a cyclic scanning method to read data from the NTC temperature sensor. The system starts by initializing the functions of each module. After the initialization is completed, the system parameters (oxygenation rate, water level threshold, current limit, lighting brightness, purification rate and one-key water change operation) can be adjusted by pressing buttons. When the actual measured water temperature is lower than the threshold, the relay closes and the heating rod starts to heat the water temperature, and vice versa. When the system load current is greater than the current limit threshold, the buzzer alarms and the load electrical appliances stop working. After the system parameters are set, press the button to exit and automatically save the parameters, and there is a power-off saving effect. The system WiFi sends the data to the mobile phone APP and the terminal control center wirelessly. After the transmission is completed, the cache is automatically cleared and the cycle ends.


Figure 4-11 Main program flow chart





4.4 System subprogram design 4.4.1 IIC communication program design

Serial communication is mainly implemented using three lines: CS, SCLK and SDA. Among them, CS is an optional chip, SCLK is a synchronous clock signal, and SDA is a data transmission signal. At the beginning of the timing, the CS segment is high, and SCLK is a rectangular pulse fluctuation. When CS is low, SCLK is also low. When CS is high, SCLK will generate a pulse signal. At the same time, STD starts to select the clock byte. After several cycles, RW reads the data, and RS sends the data to a higher level for data selection. Finally, it is filtered to the second storage area, and the second byte change is performed to generate a timing signal. Finally, the CS chip select returns to a low level, the pulse signal stops, and STD stops the byte bit selection. Figure 4-1 is a serial communication timing diagram:
Figure 4-2 Serial communication timing diagram



4.4.2AD acquisition program design
When using the STM32 microcontroller to collect voltage, it can be roughly divided into two types, one is DMA acquisition, and the other is timing acquisition. This system uses DMA to collect voltage. The acquisition process is designed as follows. For ADC sampling, the first step is to initialize the ADC, determine the level of the ADC channel, convert the acquisition time window into the corresponding time and clock, define the results of the three voltages, currents and temperatures, sample each signal 8 times, and then store the threshold into the chip through STMFLASH, so the system collects 3 data in total. If the scheduled ADC interrupt occurs, the system will enter the interrupt service program, and then transmit and process the data of the voltage and current acquisition of the current device.

Figure 4-3 Voltage acquisition flow chart

4.4.3 WiFi communication program design

In this design, the ESP8266WiFi serial port communication protocol is the Gizwits platform standard access protocol (4.2.0). The device's communication information is 9600 baud rate, 8 data bits, no parity, 1 stop bit, and the transmission byte order is big-endian encoding. The communication interaction form is one question and one answer. Each command needs to be confirmed by the receiver with an ACK response. The timeout is 200ms, and it will be resent after the timeout. After the WiFi module is powered on, it needs to query the MCU for device information. After the information is successfully obtained, the WiFi module can work normally. The basic communication protocol flow chart is shown below.
Figure 4-4 WiFi
AIoT device self-service development platform:
Gizwits AIoT self-service development platform provides development capabilities covering the entire life cycle of IoT device access to operation management, from product definition, development and debugging, application development, production testing, cloud development, operation management, data services, etc. Through fool-proof self-service tools, complete SDK and open API, the technical threshold for IoT device development is minimized, and it has served more than 320,000 developers.


5 System debugging analysis 5.1 Software debugging

The development environment of the software program is KEIL5. For new projects, choose the right model of MCU and continuously provide the system to ensure the stability of system operation. The MCU selected is C8T6 model, so you must remember to modify the size of the crystal oscillator in the Target selection column to ensure the accuracy of the time.

Figure 5-1 MCU model selection
After repeatedly checking and modifying the code through breakpoint debugging and single-step debugging, you can compile the code to view the results of program debugging. After programming, you will see the prompt "0 error". If you see this prompt result, it means that the program is correct. As shown in Figure 5.2.
Figure 5-2 Program compilation passed

After the program is compiled, the next step is to burn the program of the microcontroller into it through the serial port burning software. The first step is to open Fly-Mcu, set BOOT0 and BOOT1 to low level, and then set the serial port software to reset DTR low level and enter the Bootloader with RTS high level.
Figure 5-3 Program burning design


5.2 Hardware Debugging

For the production of this system, the first step is to weld the hardware, then write the code, and finally run the physical object. Therefore, the separate debugging of the software and hardware is the basis for the final adjustment of the physical object.
The adjustment and testing of system hardware mainly starts with the system circuit and program. When designing the circuit, you can use AD software to draw the circuit according to the pin characteristics of each component and the system function, and then perform physical welding according to the circuit. If you have patience, you can use a multi-board to test while welding, which can greatly reduce the error rate of hardware welding. General hardware debugging can follow the following steps to get twice the result with half the effort:
(1) Step 1: Use circuit diagram drawing software (the software used in this design is Altium Designer, a highly intelligent professional drawing software launched by PROTEL) to draw the overall circuit diagram of the system, as shown in the figure below, and then carefully check whether the components and circuit connection directions in the software are correct;
(2) Step 2: Draw the PCB diagram against the schematic diagram to ensure the correctness of the PCB diagram and the consistency with the circuit drawn on the schematic diagram;
(3) The third step: look up component information, compare the actual function and pins of each component, and check the schematic diagram and PCB diagram at the same time;
(4) Design rules, pay attention to the line width of the power line and the safe distance between components. Set the +12V power line width to 2mm, the +5V line width to 1.5mm, the +3.3V line width to 1.2mm, and the remaining signal lines to 0.2mm.
(5) Arrange the components according to the EMC design specifications, connect the power line first, then the signal line, and finally copper-plated the GND, and then the signal interface is treated with teardrops. The PCB wiring is shown below.
(6) Step 4: After the physical installation is completed, you can use a multimeter or other tool to test the local circuit and the overall circuit to prevent short circuits and promptly correct component circuit errors and errors in the overall circuit.
Figure 5-4 PCB layout and connection design
Figure 5-5 PCB copper plating design

Figure 5-6 PCB 3D model

5.3 Physical Testing

(1) The device is powered by the power system. The display shows the current time, the current water temperature of the water cluster tank, the temperature of the ambient air, as well as the current power supply current, device power and power consumption of the device, as shown in the figure below.
Figure 5-7 Power supply display view
(2) NTC detection and threshold display of water temperature sensor of water cluster tank.
Figure 5-8 Water temperature threshold debugging
(3) Debugging the oxygen filling rate.

Figure 5-9 Oxygen filling rate setting
(4) Adjust the lighting in the aquarium.
Figure 5-10 LED lighting brightness setting
(5) Current limiting protection design: when the device current exceeds 5A, the system will stop working urgently.

Figure 5-11 System protection current setting
(6) The water pump controls the water inlet and outlet, and can realize APP remote control and one-click water change.
Figure 5-12 DC water pump equipment
(7) The following is the display interface of the Gizwits public version mobile app.
Figure 5-13 Remote APP login and operation interface
(8) The following is the terminal server data history query interface of the Gizwits IoT platform.
Figure 5-14 Historical data information query on PC
(9) The following is a full-scale physical picture of the work.


Friends who need code and demonstration video, please download it by yourself. If you can't download it, please leave a message in this post and send you a private message! !
Source code and demonstration video link: Link:

链接已隐藏,如需查看请登录或者注册
Extraction code: mqdw

This post is from RF/Wirelessly

Latest reply

It should be good, let's take a look first   Details Published on 2022-11-25 15:16
 

14

Posts

1

Resources
2
 
I really want to make one, but the fish tank at home is too small. But I think this system can be used for greenhouse control.
This post is from RF/Wirelessly
 
 

175

Posts

0

Resources
3
 

It should be good, let's take a look first

This post is from RF/Wirelessly
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

快速回复 返回顶部 Return list