Bang-Bang based temperature and humidity control system
2026-04-06 08:57:27··#1
Temperature and humidity requirements are prevalent in various applications, including warehousing management, manufacturing, meteorological observation, scientific research, and daily life. For example, the "Provisional Regulations on Technical Management of Archives Storage Facilities" explicitly state that the temperature of archives storage facilities (including film and magnetic tape storage facilities) should be controlled between 14 and 24°C, with daily variations not exceeding ±2°C for facilities with equipment; the relative humidity should be controlled between 45% and 60%, with daily variations not exceeding ±5% for facilities with equipment. This paper designs an automated system that meets these requirements using a novel C8051F020 microcontroller and the I2C bus digital temperature and humidity sensor SHT11. System Hardware Design The archives storage temperature and humidity controller is based on the C8051F020 microcontroller. The main device is the 8051F020, and the slave device is the I2C bus digital temperature and humidity sensor SHT11. The SHT11 is a single-chip, fully calibrated digital relative humidity and temperature sensor with an I2C bus interface, manufactured by Sennsirion GmbH, Switzerland. Traditional analog humidity sensors typically require signal conditioning circuits and complex calibration processes, making it difficult to guarantee measurement accuracy and often resulting in unsatisfactory linearity, repeatability, interchangeability, and consistency. The SHT11, from the Swiss company Sennsirion, is a new type of temperature and humidity sensor based on CMOSens™ technology (integrating temperature and humidity sensor, signal amplification and conditioning, A/D conversion, and I2C bus all onto a single chip). This sensor outputs humidity values with a 14-bit resolution and temperature values with a 12-bit resolution, programmable to 12-bit and 8-bit. The C8051F020 microcontroller is a mixed-signal system-on-a-chip microcontroller, fully compatible with the MCS8051 core and instructions. In addition to standard 8051 digital peripherals, it integrates analog components and other digital peripherals and functional components commonly used in data acquisition and control systems. It also features internal JTAG and debugging circuitry, allowing for non-intrusive, full-speed, and online system debugging via the JTAG interface when installed on the final application system. The hardware connection of the temperature and humidity controller composed of the two is shown in Figure 1. Figure 1 shows the wiring diagram of C8051F020 and SHT11. Using the I/O port initialization program, the priority crossbar decoder is started, configuring pins P0.0 and P0.1 as SDA (serial data) and SCL (serial clock) respectively. These are then connected to the DATA and SCK pins of the SHT11. Under clock control, the temperature and humidity data acquired by the SHT11 and converted by A/D is read. P0.2 and P0.3 are configured as basic inputs and outputs, controlling two relays based on the read temperature and humidity values, thereby controlling the temperature and humidity regulator. In serial communication, the master device is 8051F020, and the slave device is SHT11. Software Design 1: Bang-Bang Control. In the temperature and humidity control of the archive, the requirement for temperature and humidity is not a constant value, but a range. The actuator has only two states: on (operating) and off (not operating). For this actuator, a typical digital control algorithm, the Bang-Bang control algorithm, is used. This requires two temperature setpoints: THIGH and TLOW, and two humidity setpoints: HHIGH and HLOW. Temperature control is the same as humidity control, so only temperature control will be described. If the temperature is higher than THIGH, the controller shuts off the power (relay releases); if the temperature is lower than TLOW, the controller turns on the power (relay engages). The difference between THIGH and TLOW is called hysteresis. Using hysteresis extends the lifespan of the relay because it reduces the number of relay switching cycles. 2. Program Design The program includes: ● System reset subroutine (Reset_Init): Completes the settings for the internal oscillator, sets XBR0 and XBR2, and connects SMB to a general-purpose I/O pin; ● SMBus initialization subroutine (SMBus_Init): Configures and enables SMBus, sets the SMBus clock rate, and clears the SM_BUSY flag for the first transmission; ● A/D conversion and data reading subroutine (ADCRead); Bang-Bang control algorithm subroutine (Bang-Bang); ● Output control subroutine (OUTcontrol). The main subroutines for starting A/D conversion and reading data are given below. ADCRead: WRITE EQU 00H //SMBus write command READ EQU 01H //SMBus write command CHIP-A EQU 00H //SHT11 slave address MEAMURE_TEMP EQU 03H //SHT11 temperature measurement command MEARURE_HUMI EQU 05H //SHT11 humidity measurement command CLR RW //Write slave address MOV A,#CHIP_A ORL A,#WRITE MOV WRIT_ADC, A SETB SM_BUSY SETB STA JB SM_BUSY, $ //Write temperature measurement command CLR RW MOV A,# MEAMURE_TEMP ORL A,#WRITE MOV WRIT_ADC, A SETB SM_BUSY SETB STA JB SM_BUSY, $ //Read measured temperature SETB RW MOV A, # CHIP_A ORL A,#READ MOV READ_ADC, A SETB SM_BUSY SETB STA ACALL DELAY MOV TEMPR, RECEIVE_BYTE ———————— —————————— //Write humidity measurement command—————————————————— //Read the measured humidity value. Since the humidity measurement and temperature measurement programs are the same, they are not provided. The measured temperature and humidity data are placed in the TEMPR and HUMIR registers respectively, and then controlled by the linear correction program and the bar algorithm program to control the relay action. Conclusion This paper designs a temperature and humidity control system. The main device is the 8051F020, and the slave device is the I2C bus digital temperature and humidity sensor SHT11. The interface circuit uses an I/O port initialization program to start a priority crossbar decoder to configure the pins as serial data and serial clock, and configure the basic inputs and outputs. The software design adopts the Bang-Bang control algorithm, requiring two temperature setpoints, high and low. If the temperature is higher than the high point, the power is turned off; if the temperature is lower than the low point, the power is turned on. The control program includes system reset, initialization, A/D conversion and data reading conversion, the Bang-Bang control algorithm, and output control subroutines.