Introduction

With the development of the economy and society, the demand for hygiene, environmental conditions, and resources in public places is increasing1,2.Ensuring the sanitary safety of public places, especially in enclosed venues, is of great concern3. Public places such as public toilets, community reading rooms, waiting halls of airports and railway stations, and smoking rooms often have poor air circulation and witness frequent human movement, making them hotspots for rapid virus transmission4,5. Therefore, enhancing the sanitary safety of public places is crucial to effectively control the spread of viruses.

Coronavirus type 2 (SARS-CoV-2) emerged in Wuhan, China, in late 2019 and has spread rapidly around the world for nearly two years6,7, The disease caused by this coronavirus has been named coronavirus disease (COVID-19) by the World Health Organization8, It is characterized by symptoms of viral pneumonia, which can cause harm to a variety of organs, including the kidneys9. During the epidemic, many countries and research institutions will put forward solutions to public health security that are suitable for the basic national conditions of their own countries and regions. Ghulam10Et al. designed a smart entrance disinfection door based on a disinfectant spray station and ultraviolet irradiation mechanism to ensure that people entering any space have less chance of carrying viruses. Olumuyiwa11et al. the novel coronavirus equation controlled by an ordinary differential eight-dimensional system was established and analyzed by et al., and by considering individuals in the population with the first vaccination dose and the second vaccination dose, the quantitative threshold of the control recurrence number was obtained to reduce the spread of the disease in the population. Saiful12Et al. propose a mathematical model based on the Lotka-Volterra equation, using data on suspected, infected, and recovered people to provide differential equation values to estimate future consequences, further reducing transmission through social distancing and being isolated. Therefore, there are many ways to prevent the transmission of COVID-19 to avoid the transmission of a large number of viruses, and Table 1 lists several effective prevention methods.

In this paper, an intelligent disinfection control system based on the STM32 single-chip microprocessor was designed. The proposed system utlizes the STM32 microcontroller as the core controller, enabling composite control of disinfectant concentration and liquid level through proportion integration differentiation (PID) control and logical increase/decrease ratio control. Furthermore, a dynamic crowd density calculation algorithm based on the You Only Look Once (YOLO) algorithm is used to accurately identify human targets, dynamically obtain the crowd density, and regulate the spraying strategy and access control time. The proposed system enables the prediction of the full-cycle crowd density, regulation of the spraying strategy, dynamic optimization of the closed-loop disinfection model, and intelligent control of the disinfection process.

Table 1 Effective ways to prevent the spread of COVID-19.

Overall system design

The proposed intelligent disinfection control system based on the STM32 single-chip microprocessor comprises seven modules: image acquisition, spraying control, disinfectant liquid level control, access control, voice broadcast, data storage, and system display. The system utilizes the YOLO algorithm to adjust the crowd density in the current area. Closed-loop disinfection is achieved through PID control-based regulation of the spraying devices. Access control time regulation and disinfection control are implemented based on dynamic changes in the crowd density. The proposed system achieves composite control of disinfectant concentration and liquid level through PID control-based logical increase/decrease ratio control. The system structure is illustrated in Fig. 1.

Fig. 1
figure 1

System structure.

System hardware design

Minimum system of the STM32 single-chip microcontroller

An STM32F407 microcontroller is used as the main control chip, and the peripheral circuit comprises a crystal oscillator, a storage circuit, and a reset circuit. The minimum system circuit of the microcontroller is shown in Fig. 2.

Fig. 2
figure 2

Minimum system of the microcontroller.

Image acquisition module

Image acquisition is achieved using an OV7670 image chip. The SIO_C and SIO_D pins of the OV7670 image chip are connected to the PC6 and PC7 pins of the STM32 microcontroller, respectively.STM32 communicates with the OV7670 by using the serial camera control bus (SCCB) protocol for read and write operations, enabling image data acquisition and output15. The image data are cached and retrieved through the first-in-first-out (FIFO) interface and then temporarily stored in the external static random-access memory (SRAM). Circuit diagram of the OV7670 image acquisition chip in Fig. 3.

Fig. 3
figure 3

Circuit diagram of the OV7670 image acquisition chip.

Access control module

The access control module comprises the ULN2003 driver chip, 28BYJ-48 motor, electromagnetic lock, and other hardware components. When the door lock comes in contact with the Hall sensors placed at both ends of the buckle plate, electromagnetic induction is generated, resulting in a low-level output as the locking signal. Upon receiving the locking signal, the microcontroller initiates the reverse excitation of the stepper motor to complete the locking action. On the contrary, if the user triggers the unlock button, the motor drive module produces a high-level output to drive the motor to complete the unlocking action. The motor drive circuit is illustrated in Fig. 4.

Fig. 4
figure 4

Motor drive circuit.

Disinfectant liquid level control module

For liquid-level signal collection, the main controller uses pressure and flow sensors. When the liquid level is lower than the predefined threshold, the controller enters the high-value selector and utilizes the PID control strategy to control the opening of the pure water valve, causing the liquid level to rise. The flow rate of the pure water (X) is measured using the pure water flow sensor, and the controller adjusts the flow rate of the original disinfection liquid to be K times X. Subsequently, the controller enters the low-value selector and opens the original liquid valve. When the liquid level exceeds the set value, the controller utilizes the low-value selector to reduce the flow rate of the original liquid by controlling the original liquid valve. Then, the flow rate of the original liquid (Y) is multiplied by 1/K and fed into the high-value selector, which controls the opening of the pure water valve to decrease its flow rate. This process achieves the composite control of the logical increase and decrease of the liquid level and flow rate. The process flow of the logical increase and decrease control process for the disinfectant is depicted in Fig. 5.

Fig. 5
figure 5

Process flow of the logical increase and decrease control process for the disinfectant.

An MPX4250 pressure sensor is used to detect the water level; it outputs a measurement voltage of 0–5 V corresponding to a relative water level of 0–0.5 m and has a conversion accuracy of 1 mm/mV. The liquid level detection circuit is illustrated in Fig. 6.

Fig. 6
figure 6

Liquid level detection circuit.

The flow sensor has three interfaces: the motor interface, power supply ground (GND), and signal output port. The signal output port is connected to the microcontroller’s pin PC0. The flow detection circuit is shown in Fig. 7.

Fig. 7
figure 7

Flow detection circuit.

Disinfectant liquid level control is achieved by controlling the solenoid valve by using a relay, which controls the opening of the water valve. Relay high-level triggering is employed in this paper. The IN end of the relay is connected to the PB2 pin of the microcontroller, the NO end is connected to the positive pole of the power supply, the COM end is connected to the positive pole of the solenoid valve, and the negative pole of the power supply is connected to the negative pole of the solenoid valve. Furthermore, in the non-triggered state, the COM end is connected to the NC end. When the limit switch is triggered, the pin level changes due to the connection between the COM end and the NO end. After reading the level change, the action is completed.

Voice broadcast module

The voice broadcast module comprises an XF-S4240 voice synthesis board and an audio power amplifier circuit. The XF-S4240 voice synthesis board uses a 3.3 V DC power supply and is connected to the main controller through a serial peripheral interface (SPI) data communication interface. When the RDY pin of the XF-S4240 hardware is at a high level, the main controller is in the working state of synthesizing texts, and vice versa. The reset pin (RST) is externally connected to a reset button; during the normal operation of the main controller, this pin is at a high level.

The audio power amplifier circuit employs the LM4667MM switch-type low-frequency power amplifier. The power supply voltage is 3.3 V DC, the output terminal is connected to the speaker, and an exclusive-OR gate control circuit is embedded to provide the shutdown control function. The amplifier is operational when the SEL pin is connected to the low level and the SD pin is connected to the high level. The circuit diagram of the audio amplifier is shown in Fig. 8.

Fig. 8
figure 8

Audio amplifier circuit.

Intelligent spraying control module

The intelligent spraying module utilizes four misting nozzles installed at four corners of the ceiling of a public toilet. When the hourly crowd density is obtained, and the camera detects no presence of individuals, access control and the spraying program are activated simultaneously. The spraying time is the same as the access control time, and a single closed-loop flow control system controls the amount of sprayed disinfectant by using the PID control algorithm. The detection and transmission unit uses a YF-S201 series flow sensor installed at the water pump’s outlet.

The output duty cycle of the flow sensor is 50%, and the output pulse frequency can be expressed as follows:

$$f = 7.5 \times Q$$
(1)

where f is the output pulse frequency, and Q is the unit flow rate (L/min). The output frequency F can be calculated as follows:

$$F = 7.5 \times Q \times S$$
(2)

where S is the unit time, the output frequency F is fed into the microcontroller to calculate the current flow Q, which is then sent to the PID for calculations, making the flow output more accurate.

Software design

Overall system software design

Upon receiving the processed image data, the main controller analyzes the data to determine the real-time crowd density. By comparing the dynamic changes in crowd density with the customized crowd density threshold, the system optimizes the access control time and model parameters and determines an optimal access control time and spraying strategy. The main program initializes image acquisition, secure digital (SD) card storage, spraying information control, access control information control, voice information control, and data display interfaces. The overall software design flowchart of the system is illustrated in Fig. 9.

Fig. 9
figure 9

Overall software design flowchart of the system.

Image acquisition module

The image acquisition module uses an OV7670 camera to capture real-time image information. The YOLO algorithm is used to optimize the recognition accuracy of the image information and obtain accurate crowd density. The captured images are preprocessed to ensure that the three-channel color components of the image are equal. A grayscale processing formula (Eq. (3)) is used to improve the operational speed16,17:

$${\text{Gray}} = R*0.299 + G*0.587 + B*0.114$$
(3)

To enhance image features and reduce image data size, the image is binarized by setting the pixel points to either 0 or 255. The following binarization algorithm (Eq. (4)) is used:

$$g(x,y) = \left\{ {\begin{array}{*{20}c} {255} & {g(x,y) \ge T} \\ 0 & {g(x,y) < T} \\ \end{array} } \right.$$
(4)

Where g(x, y) is the current pixel and T is the custom pixel.

One-dimensional (Eq. (5)) and two-dimensional Gaussian filtering (Eq. (6)) algorithms are used to smoothen the binarized image and reduce image noise, respectively18:

$$G(x,y) = \frac{1}{{\sqrt {2\pi \sigma } }}e^{{ - \frac{{x^{2} }}{{2\sigma ^{2} }}}}$$
(5)
$$G(x,y) = \frac{1}{{\sqrt {2\pi \sigma ^{2} } }}e^{{ - \frac{{x^{2} + y^{2} }}{{2\sigma ^{2} }}}}$$
(6)

The YOLOv3algorithm19,20, which includes a feature pyramid network (FPN), is used to optimize the recognition accuracy of crowd size. The FPN addresses multiscale challenges encountered in object detection and greatly improves detection accuracy without increasing the computational load of the original model. Darknet-53 is used as the classification network to enhance the detection speed. The binary cross entropy (BCE) loss function is adopted, and logistic regression is used in the classifier. The YOLOv3 feature extraction network with Darknet-53 is shown in Fig. 10.

Fig. 10
figure 10

YOLOv3 feature extraction network with Darknet-53.

When performing pedestrian detection using the YOLOv3 algorithm, we opted to train it using images containing pedestrians from the VOC2007 dataset21. The training set comprises 2095 images, while the testing set consists of 2097 images. During training, we set the training batch size to 6 and the number of training epochs is set to 50. The model learned a plethora of human body features, enabling it to accurately identify pedestrians in images. Upon testing with the test set, the model achieved the expected accuracy level as set in this document.

Access control model

For access control, the access control module selects time intervals based on the crowd density per unit of time; its workflow is as follows. First, the current crowd density P is determined. If P is less than or equal to the set lower limit N1, access control T1 is selected. If P is greater than the lower limit N1 but less than the upper limit N2, access control T2 is selected. If P is greater than the upper limit N2, access control T3 is selected. For example, when the detected crowd density P is less than 10 people/h, a 20-s access control is performed every hour for when the image acquisition module finds that no one is inside the toilet. When P is greater than 30 people/h, a 40-s access control is performed every 30 min when the image acquisition module detects that no one is inside the toilet. When P is between 10 and 30 people/h, the access control time is 40 s. The model of access control time corresponding to crowd density can be expressed using Eq. (7):

$$H = \left\{ {\begin{array}{*{20}c} {T_{1} } & {P < N_{1} } \\ {T_{2} } & {N_{1} < P < N_{2} } \\ {T_{3} } & {P> N_{2} } \\ \end{array} } \right.$$
(7)

where T1, T2, and T3, respectively represent the time limits of 20, 30, and 40 s for closing after access control, and H represents the current time limit for closing after access control. The flow diagram of access control is shown in Fig. 11.

Fig. 11
figure 11

Flow diagram of access control.

Spraying control module and control algorithm

To achieve intelligent spraying control, the spraying control module adjusts the number of working nozzles according to the current crowd density; its workflow is as follows. First, the current crowd density P is determined. When P is less than or equal to the set lower limit N1, the first nozzle located on the left corner of the public toilet ceiling is activated during T1. When P is greater than the lower limit N1 but less than the upper limit N2, the first nozzle located on the left side and the first nozzle on the right side of the public toilet ceiling are activated during T2. When P is greater than the upper limit N2, all four nozzles are activated during T3. For example, the set value is first defined, and P is determined, and when the image acquisition module detects 10 people/h, nozzle 1 is activated for 20 s during access control. When the image acquisition module detects a crowd density of 30 people/h, nozzles 1, 2, 3, and 4 are activated for 40 s during access control. The spraying control model corresponding to crowd density can be expressed using Eq. (8):

$$G = \left\{ {\begin{array}{*{20}c} {D_{1} } & {P < N_{1} } \\ {D_{1},D_{2} } & {N_{1} < P < N_{2} } \\ {Q} & {P < N_{2} } \\ \end{array} } \right.$$
(8)

where D1 and D2, respectively, represent the activation of one and two misting nozzles, Q represents the activation of all four nozzles, and G denotes the number of nozzles currently activated. The program flowchart of the spraying control model is depicted in Fig. 12.

Fig. 12
figure 12

Flowchart of the spraying control program.

Software design of the disinfectant liquid level control module

The disinfection liquid level control system for logical increase and decrease is controlled using the STM32 microcontroller and developed using the C language. The control program mainly includes the data acquisition program, PID control program, and regulating valve control program. When the disinfectant liquid level is lower than the predefined threshold value, the calculated difference is fed into the digital PID algorithm for calculations, and the speed of water injection via the regulating valve is controlled to achieve precise liquid level control. The flow diagram of the disinfectant liquid level control module for logical increase and decrease is shown in Fig. 13.

Fig. 13
figure 13

Flow diagram of the disinfectant liquid level control system for logical increase and decrease.

Software simulation

The MATLAB/Simulink simulation software22,23,24 was used to establish the disinfectant liquid level control system for modeling and controller parameter optimization. First, the simulation model for the disinfectant liquid level control system was established, as shown in Fig. 14. Next, the PI controller parameters were set as follows: KP = 0.65 and Ki = 0.45. Finally, the simulation results were obtained.

Fig. 14
figure 14

Simulation model of the disinfection liquid level control system.

In the simulation stage, a composite control of logical increase and decrease of the liquid level and flow rate was performed, which yielded a stable waveform. Upon adding a random disturbance with an amplitude of − 0.1 or 0.1 to the simulation, stability deteriorated in the presence of the disturbance. The simulation results are shown in Fig. 15.

Fig. 15
figure 15

System simulation results.

As can be observed from the output response of the control model shown in Fig. 15, the maximum overshoot of the pure water flow rate was 28%, with a control time of 50s. The maximum overshoot of the original disinfectant liquid was 4%, with a control time of 25s. Furthermore, when a random disturbance was added, the disinfectant liquid level fluctuated; however, the system met the requirements.

Experimental result

The VGA camera, OV7670 is used to get images dynamically, and show it on the TFT display. Which can be connected to directly to STM32 using SCCB. The device hardware photos is shown in Fig. 16.

Fig. 16
figure 16

OV7670 collects experimental results.

Disinfectant liquid level control module gets the liquid level information(W) using the ultrasonic sensor of HC-SR04. Subsequently, The target liquid level and ratio facor of dilution concentration were setting 15 cm and 2.When the liquid level is lower than the predefined threshold of 15 cm, the controller enters the high-value selector and utilizes the PID control strategy to control the opening of the pure water valve, causing the liquid level to rise. The flow rate of the pure water (3.7 L/min) is measured using the pure water flow sensor, and the controller adjusts the flow rate of the original disinfection liquid to be 2 Multiply by (3.7 L/min). Subsequently, the controller enters the low-value selector and opens the original liquid valve, the test results are shown in Fig. 17a-b. When the liquid level exceeds the set value, the controller utilizes the low-value selector to reduce the flow rate of the original liquid by controlling the original liquid valve. Then, the flow rate of the original liquid (1.2 L/min) is multiplied by 1/2 and fed into the high-value selector, which controls the opening of the pure water valve to decrease its flow rate. After 5 s, the water valve is closed, the test results are shown in Fig. 17c-d.

Fig. 17
figure 17

Experimental results of the logical increase and decrease control process for the disinfectant.

The experimental results of YOLOv3 were shown in nine sets of photos taken by STM32 (Fig. 18). The green frame corresponds to the pedestrian, and the traffic flow information is obtained by detecting the number of pedestrians, dynamically obtaining the crowd density. The experimental results show that the detection frame positioning is more accurate, so YOLOv3 has a good ability to identify pedestrians, in addition, YOLOv3 has a good detection frame positioning. It can be seen from Table 2 that YOLOv3 has the best detection speed and mAP, which makes YOLOv3 suitable for real-time use, which proves that it is more accurate than other algorithms in detecting pedestrians.

Fig. 18
figure 18

YOLOv3 partial experimental result.

Table 2 Compared with the experimental results of other models.

First, the crowd density was set threshold (P) of 10 ~ 60 people/h. If the population density is 9 people/h, through the threshold comparison is less than or equal to the set lower limit of 10 ~ 60 people/h, a 20-s access control is performed every hour for when the image acquisition module finds that no one is inside the toilet and turn on motor and spray disinfectant, the test results are shown in Fig. 19a-b. If the population density is 26 people/h, than 10 ~ 60 people/h, a 40-s access control is performed every 30 min when the image acquisition module detects that no one is inside the toilet the test results are shown in Fig. 19c-d. When 65 people/h is between 10 and 60 people/h, the access control time is 40 s, the test results are shown in Fig. 19e-f.

Fig. 19
figure 19

Access control and spraying based on crowd density of experimental results.

Conclusion

In this study, an intelligent disinfection system was developed using the single-chip microprocessor technology, sensor detection technology, and YOLO algorithm. By using the YOLO algorithm, the accuracy of human target recognition was improved, the dynamic crowd density was obtained, and the spraying strategy was adjusted to realize sanitary safety in crowded public places such as public toilets. An access control model was designed to achieve closed-loop disinfection control. By comparing the dynamic changes in crowd density with the user-defined crowd density threshold, the access control time and model parameters were optimized, and the optimal access control time limit was obtained. The proposed intelligent disinfection system based on the STM32 single-chip microprocessor realized dynamic optimization and intelligent control of the closed-loop disinfection model for public toilets, effectively reducing the risk of virus transmission.