Bluetooth wireless temperature and humidity detection system based on STM32

Based on STM32 MCU and HC-05 module, a wireless temperature and humidity detection system is designed. In this system, STM32 is taken as the control core, the digital temperature and humidity sensor AM2303 with low power consumption and fast response is used to collect temperature and humidity signals, and bluetooth technology is used to transmit the detected environmental information, thus completing the remote communication with the upper computer. The problem of complicated wiring of traditional wired monitoring system is solved. Through Bluetooth module, the communication between STM32 single chip microcomputer and host computer can realize the real-time detection of environmental temperature and humidity. When there is danger in the room, the mobile phone or work computer can receive warning signals in time. The experimental results show that the system has the advantages of good real-time, high data transmission reliability and good intelligence, Meanwhile, the cable is saved and the cost is reduced.


Introduction
In daily life, temperature and humidity are two very important physical parameters, which are not only closely related to people's health, but also closely related to scientific research, garden technology, warehouse management and computer room management. With the development of electronic technology, people's requirements for monitoring environmental temperature and humidity are getting higher and higher.The traditional temperature and humidity detection technology adopts wired transmission device, which is not only troublesome in wiring, but also consumes a lot of manpower and material resources, and has great limitations in practical application. Apply wireless Bluetooth technology to indoor management system, monitor all kinds of indoor environmental information in real time, judge indoor abnormal hidden dangers in time, and assist indoor managers to deal with them. It has certain innovation and practical significance to minimize the damage caused by environmental factors to indoor equipment or personnel and reduce direct economic losses.
In this paper, a wireless temperature and humidity detection system is designed. the main controller is STM32 with low power consumption and strong computing ability, the Bluetooth module is HC-05, the sensor is AM2303 with low power consumption, fast response and strong stability, and the display module is LCD screen.

Overall system design
The indoor environmental monitoring system introduced in this paper adopts Bluetooth communication to build a network model, with the single chip microcomputer STM32 as the core controller, and the monitoring terminal adopts AM2303 temperature and humidity sensor to realize indoor environmental information collection. The AM2303 temperature and humidity sensor directly outputs digital signals to the STM32 microcontroller for subsequent processing. Wireless data transmission uses Bluetooth module HC-05 to upload to mobile phones or workstations and other monitoring equipment to realize remote monitoring. The indoor monitoring system based on Bluetooth technology is shown in figure 1. The system can complete the measurement of indoor environmental parameters and realize the analysis, processing, setting and monitoring of indoor environmental parameters; Real-time wireless transmission of collected data is realized, and corresponding control operation is completed on the upper computer.

System hardware design
The hardware design of the system consists of temperature and humidity data acquisition circuit, Bluetooth wireless communication circuit, alarm circuit, display circuit and power supply circuit. Temperature and humidity data acquisition circuit is used to collect indoor temperature and humidity information; Bluetooth wireless communication circuit is used to exchange information and data with handheld terminal or workstation. The alarm circuit is used to warn that the temperature and humidity exceed the standard;The display circuit is used for displaying the value of the current detection parameter; The power supply circuit supplies power to the system.

Temperature and humidity data acquisition circuit
In the system, temperature and humidity data acquisition is completed by AM2303 digital sensor. AM2303 is a temperature and humidity composite sensor with calibrated digital signal output. Its main characteristics are: temperature resolution is 0.1 , accuracy is 0.2 ; The humidity resolution is 0.1%RH and the precision is 2% RH. Power supply voltage is 3.5~5.5V, etc. Its advantages include automatic calibration, ultra-small size, extremely low power consumption, standard single bus interface, and signal transmission distance of over 20m.
Temperature and humidity data acquisition circuit is mainly connected with SDA pin of AM2303 sensor by PA3 pin of STM32 single chip microcomputer, and the sensor is controlled to collect data by standard single bus communication mode. the design circuit is shown in figure 2.

Bluetooth wireless communication circuit
The Bluetooth wireless communication circuit adopts HC-05 Bluetooth transceiver module. RXD pin and TXD pin of HC-05 are connected with TXD pin and RXD pin of MCU respectively. Especially, when communicating with MCU, Bluetooth module can't pass through MAX232 circuit. Because Bluetooth module adopts TTL level, RS232 level will cause damage to Bluetooth internal circuit devices. Fig.3 shows the Bluetooth module interface circuit.

Alarm circuit
The alarm circuit is designed with an active buzzer. The designed circuit is shown in Figure  4. When the PB1 pin of the MCU outputs a low level, the buzzer is triggered, otherwise, the buzzer stops.

System software design
The hardware design of the system consists of temperature and humidity data acquisition circuit, Bluetooth wireless communication circuit, alarm circuit, display circuit and power supply circuit. The power supply circuit supplies power to the system.

Software design of sending end of system
Because the system is composed of several sensor modules, it is necessary to initialize each module before the system works normally. After all the sensors are powered on, the STM32 MCU sends a start signal to the sensor. After reading the start signal, the sensor wakes up immediately, switches from sleep mode to high-speed mode, and replies a response signal to STM32.Then STM32 reads the 40b data output by the sensor from SDA pin, and verifies the data. If the verification is correct, it transmits the verified data to Bluetooth module. At this time, by configuring the register of Bluetooth module chip, its working mode is configured as sending mode, and the data is sent out. If the verification is wrong, the data read this time is incorrect, and the data is discarded. Reinitialize the sensor. Fig.5 is a flow chart of software design at the sending end.

Software design of receiving end of system
The STM32 MCU at the receiving end of the system sets its working mode as transceiver mode by configuring the register of Bluetooth module chip, so that it works in full duplex state. After processing the received data, the STM32 MCU compares it with the temperature and humidity alarm value set by the system, and carries out corresponding processing. Fig.6 is the software design block diagram of the receiving end of the system.   Fig. 5. Sending end software design flow chart. Fig. 6. Software design flow chart of receiver. In the experiment, the temperature and humidity were measured and compared by the thermometer and the wireless temperature and humidity detection system proposed in this paper. Table 1 and Table 2 show the outdoor temperature and humidity measured by the thermometer and the system every 30 minutes, and their relative error and absolute error. It can be seen from the measured data in Table 1 and Table 2 that the maximum relative error is 4.2%,The relative errors of the system are all within 5%.

Experimental data
The Bluetooth communication module is tested, and the paired mobile phones and working computers of Android system and iOS system are selected respectively. The results show that the system can realize wireless communication well, and the communication distance can reach about 10m, without bit error rate and packet loss rate, and the communication quality is good. It is proved that the system has good stability and reliability, and the measurement error range is small, which meets the design requirements.