Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 7, No. 1, 2023 137 Classroom Energy‐saving Control System Design Yong Deng, Junjie Peng Southwest Petroleum University, Chengdu, 610065, China Abstract: With the continuous development of science and technology, the degree of automation of various products in life is increasing. However, the impact on energy consumption and environment is getting bigger and bigger, and energy saving and emission reduction is gradually becoming a hot topic in the society. The huge loss of electrical energy in colleges and universities makes the development of energy-saving control technology particularly important. In this paper, we design an energy-saving control system for college classrooms based on STM32 main controller, which mainly collects the light intensity and personnel distribution information of classrooms through photoresistor sensors and infrared pyroelectric sensors, and combines software programming to realize effective and group control of classroom lights, so as to achieve the purpose of energy saving. On this basis, a simple upper computer monitoring interface is built to display the collected information, which facilitates real-time monitoring and management of the classroom. The system is analyzed and introduced in detail in three main aspects in the paper. Firstly, the selection of the main controller and its main hardware circuit modules are introduced; secondly, the software process design is centered around the system; finally, using simulation, analysis and online debugging, the light intensity and personnel distribution information collected can be used to control the lamps and lanterns at the corresponding locations of the personnel to turn on. In summary, this paper designs a classroom energy-saving control system to meet the current situation of large energy consumption in college classrooms, which can realize the effective lighting of the corresponding positions according to the changes of natural light environment and different positions of the personnel in the classroom, and verifies the feasibility of this scheme. It provides an idea to effectively reduce the waste of power resources and achieve the purpose of energy saving and emission reduction in colleges and universities. Keywords: STM32, Energy saving control, Sensor, Illuminance. 1. Introduction 1.1. Research Background With the development of science and technology, the degree of automation of various products in life is increasing. However, with the continuous growth of energy consumption and environmental impact, energy saving and emission reduction gradually becomes a hot topic in society. The huge power loss in colleges and universities makes the development of intelligent lighting technology particularly important. That is to say, the detection of multiple sensors can be used to collect the brightness of the current light and the distribution of people in the classroom to accurately determine the lighting needs of the area and achieve networking and intelligence. Usually, the school's logistics department is mainly responsible for managing the hardware equipment and facilities of the teaching buildings, and its work focuses on the procurement of educational facilities and equipment, the management of educational assets, and the maintenance and repair of hardware facilities. Educational facilities and equipment are assigned and used by the academic affairs department of each college, but there are no special management rules for public educational equipment such as classrooms, which leads to the phenomenon that multiple departments are in charge or multiple departments are not in charge. Especially for the management of various types of general equipment in classrooms (such as lighting equipment, etc.), there is no unified plan for the regular management required for them, except for the maintenance and repair, which belongs to the logistics department. 1.2. Purpose and significance of the study Colleges and universities play an important role in energy conservation efforts. As an important place, classrooms play an important role in the process of establishing a "conservation-oriented campus". For major universities, the focus of classroom energy saving work is mainly on the intelligent control of classroom lighting. Today's university classrooms are generally open management mode, which means that students are not designated to study or work outside of teaching hours, and the management and maintenance of the classroom is mainly dependent on the building management. The building manager is responsible for the safety and hygiene of the classroom, and there is no method or system to manage the energy loss of the classroom. In practice, the building manager has no way of knowing how often each classroom is used because the building manager is assigned by the school's logistics department and the students' classes are planned and scheduled by the academic department. This makes classroom management difficult and leads to chronic lighting in some classrooms and the consequence of not being able to maintain them in a timely manner once there is damage. Traditional lighting management has become obsolete and this loss of energy is not only contrary to today's concept of energy conservation, but also from the perspective of easy management and maintenance, it is of great practical importance to develop and improve a classroom energy control system. 2. System Introduction This system is a classroom energy saving control system with STM32 main controller as the core. The function of its main part is to achieve effective control of the corresponding 138 areas of classroom lighting by collecting light level signals through sensors and combining with personnel distribution, so as to achieve the purpose of energy saving. In its hardware system, photoresistor sensors and infrared pyroelectric sensors are used to collect signals; the control platform uses a central controller based on the STM32 system. In its software system, Visual Studio is used to design the upper computer monitoring interface, which is mainly composed of natural illumination and actual lighting status monitoring in the classroom; classroom current personnel distribution detection and other related interfaces, thus realizing real-time monitoring. 2.1. Program Analysis This design mainly collects the real-time parameters of natural light illumination in the classroom and the current distribution of people, and realizes the grouping control of lights in the classroom according to these two parameters. If the natural light illumination is greater than the preset value, no matter whether there is no one, the lights are not turned on; if there is an area where the natural light illumination is less than the preset value, the area is judged to have no one, if so, the area lights are lit, if not, the lights remain in the off state. 2.1.1. Hardware Analysis The overall framework of the system for this design is shown in Figure 1. Figure 1. Block diagram of overall system design Its main functions are as follows: (1) Sensor: mainly responsible for collecting the signal of light level and the distribution of people inside the classroom. (2) STM32 main controller: mainly responsible for receiving and transmitting signals, controlling the state of the lamps and lanterns through the program and achieving the predetermined functions. (3) serial communication: to realize the information transmission between the main controller and the upper computer monitoring system. (4) Upper computer: monitoring system based on light intensity, personnel distribution and luminaire status. 2.1.2. Software Analysis Software design is an integral part of a system and the main software modules of this control system are: (1)Infrared pyroelectric sensor, light set module, photoresistor sensor module The functions are implemented through Keil MDK programming to determine the status of the classroom and control the light sets in different ways based on the signals detected by the sensor modules. (2) Monitoring interface display Use Visual Studio to build a monitoring interface to display the light intensity, personnel distribution, lamp status and other information on the host computer, which is convenient for the logistician to view and manage in real time. 3. Hardware Design 3.1. Main Controller Selection The main controller selected for this design is the Positive Point Atomic Elite STM32F103 development board, which chooses the STM32F103ZET6, the highest configuration chip in the STM32F1 series, as the MCU. 3.2. Selection of peripheral circuits According to the functional requirements of the classroom energy saving control system designed in this paper, the main peripheral hardware included in the STM32 main controller are: power supply circuit, reset circuit, serial port circuit, JTAG/SWD debug interface circuit. 3.2.1. Power Circuit The schematic of the STM32F103 on-board power supply section is shown in Figure 2: Figure 2. Power supply circuit schematic K2 is the main power switch, U12 is a 3.3V regulator chip to provide 3.3V power to the development board, and there are two sets of simple power input and output interfaces, which can be used to provide 3.3V and 5V power to the external through the development board, and can also be used to power the development board from the external. As shown in Figure 3: Figure 3. Simple power supply circuit 139 3.2.2. Reset circuit The reset circuit is shown in Figure 4: Figure 4. Reset Circuit Low-level reset, with R3 and C12 forming the power-on reset circuit. 3.2.3. USB serial port / serial port 1 selection interface The USB serial port on the STM32F103 board and the STM32F103ZET6 serial port are connected via P4, as shown in Figure 5: Figure 5. Serial Port Circuit TXD/RXD and USART1_RX/USART1_TX are docked to enable serial communication between the USB serial port and STM32F103ZET6. Unplug the jumper cap and connect the external TTL serial port through the Dupont cable, you can realize the serial communication between STM32 and external devices; if you need to communicate with the computer, and the computer does not have a serial port, you can use RXD and TXD to connect the device up and use the development board as a USB to TTL serial port. 3.2.4. JTAG/SWD debug interface circuit The STM32F103's standard 20-pin JTAG/SWD interface circuit is shown in Figure 6: Figure 6. JTAG/SWD interface The standard JTAG connection is used here, but SWD only needs two wires, SWCLK and SWDIO, to download and debug the code, and it is fast. the SWD interface on STM32 is shared with JTAG, so as long as it is connected to JTAG, you can use SWD mode, so SWD mode is used here for debugging. 3.3. Hardware Selection 3.3.1. Infrared sensor module The HC-SR501 human sensor module is selected for personnel detection in this design, as shown in Figure 7: Figure 7. HC-SR501 module 3.3.2. Illuminance acquisition The photoresistor sensor module used in this design is shown in Figure 8: Figure 8. Photoresistor sensor module 3.3.3. Light set module The light module selected for this design is four 3W white high-power LED modules, which have a wide range of light- emitting angles, long service life and durability, as shown in Figure 9. Figure 9. Light set module 4. Software Design 4.1. Software Architecture This system will connect the STM32 main controller and the upper computer monitoring interface through serial communication to exchange and dock data, and the specific software structure diagram is shown in Figure 10: 140 Figure 10. Software system structure diagram 4.2. System software design The specific system function implementation flow is shown in Figure 11: Figure 11. System control flowchart 4.3. Upper computer monitoring system design The upper computer of this system requires building a graphical interface, which feeds the information collected by the lower computer to the upper computer through AD conversion, and uses serial communication between the two 141 to achieve real-time display and monitoring of light intensity, personnel distribution and usage status in the classroom, which is convenient for logisticians to view and manage. Here, Visual Studio is chosen to implement the design of the upper computer monitoring system. This design divides the classroom lights into two groups, each with two lights controlled by an HC-SR501 infrared module and photoresistor sensor. According to the current light intensity and personnel location in the classroom, i.e. if there is someone in the area and the light intensity is less than the preset value, the light group in the area will be lit and the light group in the other area will be in the off state. Three alert boxes are set up on the monitoring interface, which will display the illumination value of the classroom and which area is occupied and which group of lights is being lit. In addition, the interface also includes a window for scanning serial ports, serial port number selection, baud rate setting and opening serial ports. As shown in Figure 12: Figure 12. Monitoring interface design 5. Testing of Energy-saving Control Systems in Classrooms After the software program design and completion of hardware and software simulation and debugging, the system will be tested on the actual lighting control, the next part of the test process and content will be introduced. 1. Test program The system mainly detects the natural light conditions and the distribution of people in the classroom, and combines with the program design to automatically control the light group to light up or go out. (1) Since the most realistic classroom space environment cannot be restored, this design makes a simulated small classroom model with an HC-SR501 infrared pyroelectric sensor module placed at the front and rear of it to achieve effective detection of the specific location of people entering the classroom. (2) A high-sensitivity photoresistor sensor module is placed inside the system to detect changes in natural lighting conditions in the classroom. (3) At the same time, two high-power LED light modules are placed at each of the front and rear positions above the model to simulate fluorescent lights in the classroom. (4) After the sensor acquires the above information, it is transmitted to the main controller and combined with the control program already written to realize the effective lighting and extinguishing of the light sets. 2. Test process (1) When all areas of the classroom are unoccupied and there is sufficient natural light, which is greater than the preset value, all light sets will not be lit, as shown in Figure 13. Figure 13. When no one is in front of or behind the classroom (2) When there are people in front of or behind the classroom, but under good lighting conditions, all light sets will not be on either, as shown in Figure 14 and Figure 15. Figure 14. When the front of the classroom is occupied and well lit 142 Figure 15. When the back of the classroom is occupied and well-lit (3) When there are people in front of the classroom and the light is poor and less than the preset value, LEDs 3 and 4 will be lit, as shown in Figure 16. Figure 16. When the front of the classroom is occupied and low light level (4) When there are people at the back of the classroom and the light is poor and less than the preset value, LEDs 0 and 1 will be lit, as shown in Figure 17. Figure 17. When the back of the classroom is occupied and low light level 6. Summary In this paper, a classroom energy-saving control system is designed for the current situation of serious energy loss in colleges and universities. The system completes the effective grouping control of classroom lighting based on the judgment of natural light conditions and information collection of personnel distribution, combined with program control. After testing and verification, the feasibility of the control scheme was proved. The following work was accomplished in the course of the study: (1) Overall functional architecture design of the system The classroom energy-saving control system designed in this paper adopts a combination of hardware and software, which can complete the automatic control of classroom lighting according to the indoor light intensity, personnel distribution and other information. (2) Hardware circuit design of the system The hardware part of the system is mainly based on the STM32 main controller as the core, equipped with serial circuit, reset circuit and JTAG/SWD debugging interface circuit, supplemented by infrared pyroelectric sensor module, lamp module, photoresistor sensor module to achieve the detection of the classroom environment and status, and through the on-board power supply circuit to power each module of the system, and finally according to the software design to achieve the control of lamps. (3) Software system design of the system (3) Software system design of the system The software system design of the system is mainly divided into the control program written in Keil MDK5 and the upper computer monitoring system built with Visual Studio 2019 version. After receiving the information collected by the sensors, the main controller analyzes the current usage status of the classroom, and then controls the lighting on and off. And the upper computer receives the digital signal, it can display the current usage status of the classroom in real time, which is convenient for the management of the logistic staff. (4) Simulation and debugging of the system 143 First of all, the input and output of analog signals can be detected through the debugging serial port, that is, the information collected by the detection sensor can be correctly fed back to the main controller and the host computer, and then the hardware control and software simulation were tested respectively, after confirming that there is no error; finally, the joint debugging of software and hardware was carried out, and the system was tested to be in line with the established functional design and the operation status was very normal. References [1] Li Binbin. Research on Zigbee-based intelligent lighting control system for college classrooms [D]. Harbin University of Commerce, 2012. [2] Li Jing. Design and application of classroom intelligent control system based on Internet of Things [D]. Shenyang University of Architecture,2019. [3] Wu Shiyun,Luo Jiang,Wang Yiyan,Fan Kaimin. Design of a microcontroller-based intelligent control system for energy- saving college classroom lighting [J]. Electronic design engineering. 2016(23). [4] Liu Mouli. Research on energy saving scheme of classroom lighting in universities based on Internet of Things[J]. Internet of things technology. 2014(12). [5] Yin Xiaolong,Li Cailong,Yin Xiaohai. Energy-saving control system for classroom lighting[J]. Shanxi electronic technology. 2012(01). [6] Yin J ,Liu X ,Guan B , et al. Performance analysis and energy saving potential of air conditioning system in semiconductor cleanrooms [J]. Journal of Building Engineering, 2021, 37:102158. [7] Yu K H,Chen Y A ,Jaimes E , et al. Optimization of thermal comfort, indoor quality, and energy-saving in campus classroom through deep Q learning[J]. Case Studies in Thermal Engineering, 2021, 24:100842.