In this article, a microcontroller development engineer shares a hygrometer developed based on an 8051 microcontroller. This solution is relatively simple for microcontroller beginners to learn.
The humidity sensor is also called a hygrometer. In this microcontroller solution, its circuit can sense relative humidity (RH) from 20% to 95% with an accuracy of 5%, and the humidity information can be displayed on a 16×2 LCD display. In addition, in this microcontroller solution, a relay is also provided, which means that when the humidity exceeds a certain jump point, the relay will be activated to perform certain operations.
1. DHT11 humidity sensor
DHT11 is a low-cost humidity and temperature sensor with digital output. The capacitance method is used to sense humidity, while the thermistor is used to measure temperature. The sensor can sense relative humidity from 20% to 95% with 5% resolution. Temperature measurement up to 50°C with 2°C resolution. Communication with the microcontroller is via a single wire. The following figure shows the basic communication scheme:
Communicating back and forth to the DHT11 sensor is very easy. Pin 2 of DHT11 is connected to the port pin of the microcontroller. The connection scheme is shown in the figure below. The data pin (pin 2) of DHT11 requires an external 10K pull-up resistor.
The principle of its communication protocol is as follows. The microcontroller first sends a low-level signal with a width of 18mS to DHT11. After receiving this signal, the microcontroller pulls up the communication line and waits for the response of DHT11. It takes 2 to 40uS at most. Then DHT11 pulls the communication line low and keeps it low for 80usS. Then DHT11 pulls the line high and keeps it high for 80uS. DHT then pulls the line low for 50uS and the next high pulse will be the first bit of data. Data is sent in bursts of 8 bits. Each high pulse of the pulse train represents a data signal. The 50uS low signal between data bits is just a gap. The logic of a data bit is determined by measuring its width. A 26 to 28uS wide pulse indicates "low", while a 70uS wide pulse indicates "high". Simply put, pulses narrower than 50uS can be considered "low" and pulses wider than 50us can be considered "high". The first 8 bits of the data burst represent the integer value of relative humidity, the last 8 bits represent the decimal value of relative humidity, the last 8 bits represent the integer value of temperature data, and the last 8 bits represent the decimal value. For DHT11, the decimal value is always zero, we Relative humidity is measured only in this scenario. Therefore, we only need to focus on the first 8 bits of the data, which are the components of the relative humidity data. The figure below shows the circuit diagram of the humidity sensor. The last 8 bits represent the decimal value of the relative humidity, the last 8 bits represent the integer value of the temperature data, the last 8 bits represent the decimal value of the temperature data, for DHT11 the decimal value is always zero, we are measuring relative humidity only in this scenario . Therefore, we only need to focus on the first 8 bits of the data, which are the components of the relative humidity data. The figure below shows the circuit diagram of the humidity sensor. The last 8 bits represent the decimal value of the relative humidity, the last 8 bits represent the integer value of the temperature data, the last 8 bits represent the decimal value of the temperature data, for DHT11 the decimal value is always zero, we are measuring relative humidity only in this scenario . Therefore, we only need to focus on the first 8 bits of the data, which are the components of the relative humidity data. The figure below shows the circuit diagram of the humidity sensor. Therefore, we only need to focus on the first 8 bits of the data, which are the components of the relative humidity data. The figure below shows the circuit diagram of the humidity sensor. Therefore, we only need to focus on the first 8 bits of the data, which are the components of the relative humidity data. The following figure shows the circuit diagram of the humidity sensor:
The humidity sensor DHT11 is connected to P3.1 of the 8051 microcontroller. R8 pulls up the communication line between DHT11 and 8051. This relay is driven by P2.0 of the microcontroller. Transistor Q1 switches the relay. R0 is the pull-up resistor, and R7 limits the base current of Q1. D5 is just a freewheeling diode. The data line of the LCD display is connected to port 0 of the microcontroller. The control lines RS, R/E and E are connected to the P2.7, P2.6 and P2.5 pins of the microcontroller respectively. R4 sets the contrast of the display. R5 limits the current flowing through the backlight LED. C9 is a bypass capacitor. C8, C10 and X1 are associated with the clock circuit. C11, R6 and S2 form the reset circuit.
2. Source code
RS EQU P2.7
RW EQU P2.6
EEQU P2.5
ORG 000H
MOV DPTR, #LUT
SETB P3.5
CLR P2.0
MOV TMOD, #00100001B
MOV TL1, #00D
ACALL DINT
ACALL TEXT1
MAIN: MOV R1, #8D
SETB P3.5
CLR P3.5
ACALL DELAY1
SETB P3.5
HERE:JB P3.5, HERE
HERE1:JNB P3.5,HERE1
HERE2:JB P3.5, HERE2
LOOP: JNB P3.5, LOOP
RL A
MOV R0,A
SETB TR1
HERE4:JB P3.5, HERE4
CLR TR1
MOV A, TL1
SUBB A, #50D
MOV A,R0
JB PSW.7, NEXT
SETB ACC.0
SJMP ESC
NEXT:CLR ACC.0
ESC: MOV TL1, #00D
CLR PSW.7
DJNZ R1,LOOP
ACALL DINT
ACALL TEXT1
ACALL LINE2
ACALL TEXT2
ACALL HMDTY
ACALL CHECK
ACALL DELAY2
LJMP MAIN
DELAY1: MOV TH0, #0B9H
MOV TL0, #0B0H
SETB TR0
HERE5: JNB TF0, HERE5
CLR TR0
CLRTF0
RET
DELAY2:MOV R1, #112D
BACK:ACALL DELAY1
DJNZ R1,BACK
RET
CHECK:MOV A, R0
MOV B, #65D
SUBB A, B
JB PSW.7,NEXT1
ACALL TEXT3
SETB P2.0
SJMP ESC1
NEXT1:ACALL TEXT4
CLR P2.0
ESC1:CLR PSW.7
RET
CMD: MOV P0,A
CLR RS
CLR RW
SETB E
CLR E
ACALL DELAY
RET
DISPLAY:MOV P0,A
SETBRS
CLR RW
SETB E
CLR E
ACALL DELAY
RET
HMDTY:MOV A, R0
MOV B, #10D
DIV AB
MOV R2, B
MOV B, #10D
DIV AB
ACALL ASCII
ACALL DISPLAY
MOV A, B
ACALL ASCII
ACALL DISPLAY
MOV A,R2
ACALL ASCII
ACALL DISPLAY
MOV A,#"%"
ACALL DISPLAY
RET
TEXT1: MOV A,#"H"
ACALL DISPLAY
MOV A,#"y"
ACALL DISPLAY
MOV A,#"g"
ACALL DISPLAY
MOV A,#"r"
ACALL DISPLAY
MOV A,#"o"
ACALL DISPLAY
MOV A,#"m"
ACALL DISPLAY
MOV A,#"e"
ACALL DISPLAY
MOV A,#"t"
ACALL DISPLAY
MOV A,#"e"
ACALL DISPLAY
MOV A,#"r"
ACALL DISPLAY
RET
TEXT2: MOV A,#"R"
ACALL DISPLAY
MOV A,#"H"
ACALL DISPLAY
MOV A,#" "
ACALL DISPLAY
MOV A,#"="
ACALL DISPLAY
MOV A,#" "
ACALL DISPLAY
RET
TEXT3: MOV A, #" "
ACALL DISPLAY
MOV A,#" "
ACALL DISPLAY
MOV A,#"O"
ACALL DISPLAY
MOV A,#"N"
ACALL DISPLAY
RET
TEXT4:MOV A,#" "
ACALL DISPLAY
MOV A,#"O"
ACALL DISPLAY
MOV A,#"F"
ACALL DISPLAY
MOV A,#"F"
ACALL DISPLAY
RET
DINT:MOV A,#0CH
ACALL CMD
MOV A, #01H
ACALL CMD
MOV A, #06H
ACALL CMD
MOV A, #83H
ACALL CMD
MOV A, #3CH
ACALL CMD
RET
LINE2:MOV A,#0C0H
ACALL CMD
RET
DELAY: CLR E
CLR RS
SETB RW
MOV P0,#0FFH
SETB E
MOV A,P0
JB ACC.7,DELAY
CLR E
CLR RW
RET
ASCII: MOVC A, @A+DPTR
RET
LUT: DB 48D
DB 49D
DB 50D
DB 51D
DB 52D
DB 53D
DB 54D
DB 55D
DB 56D
DB 57D
END
Previous article:Efficient bit-tapping SPI port for 8051 compatible microcontrollers
Next article:How to make a simple 0-5V voltmeter using 8051 microcontroller
Recommended ReadingLatest update time:2024-11-16 09:43
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- STC32G Series MCU Technical Reference Manual
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Problems with devices that measure temperature
- Difference between Ethernet and Broadband
- Interpretation of how dust and water resistance testing of lamps is applied in international standards
- Is it as shown in the picture?
- PCB file conversion
- 5G indoor base stations will be released soon, and it is expected that each household will have a small base station, which will subvert the existing home Internet access methods.
- How to consider the impact of audio analog signals after being transmitted through a 100m long cable?
- Angle sensor
- Transistor Selection
- NUCLEO_G431RB Review - RTC Real-time Clock