Hygrometer design based on 8051 microcontroller development

Publisher:AningmengLatest update time:2023-10-30 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  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:

  Hygrometer design based on 8051 microcontroller development

  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.

  Hygrometer design based on 8051 microcontroller development

  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:

  Hygrometer design based on 8051 microcontroller development

  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


Reference address:Hygrometer design based on 8051 microcontroller development

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

Practical analysis of 8051 microcontroller (taking STC89C52RC as an example) | 09 - LED dot matrix display of numbers
1 LED dot matrix LED dot matrix is ​​a display device composed of light-emitting diodes. It can be seen everywhere in our daily electrical appliances and is widely used in bus station announcers, advertising screens, etc. The 8*8 dot matrix is ​​usually used more often, and then multiple 8*8 dot matrices can be used t
[Microcontroller]
Practical analysis of 8051 microcontroller (taking STC89C52RC as an example) | 09 - LED dot matrix display of numbers
8051 series microcontroller internal resources
1. Timer/Counter The 8051 series of microcontrollers have at least two 16-bit internal timers/counters (T/C, Timer/Counter) and provide 3 timers. The two basic timers/counters are timer/counter 0 (T/C0 ) and timer/counter 1 (T/C1). They can be programmed as either timers or counters. If it counts the internal crystal
[Microcontroller]
8051 series microcontroller internal resources
C8051F330 timer function
Summary: Use the 16-bit timer (mode 2) mode of timer 0 to implement a 100us interrupt. The system clock uses the internal high-frequency clock 24.5M The timer clock uses the system clock divided by 4 Macro definition: #define SYSCLK   (24500000) #define AUX2 (0xFD91) //The count required for 100us timing (the ti
[Microcontroller]
DS1307 interfaces with 8051-compatible microcontrollers
This application note provides information on how to interface the DS1307 real-time clock (RTC) to a microcontroller and provides some example code to access the device. introduce The DS1307 serial real-time clock integrates a 2-wire serial interface and can be controlled using an 8051-compatible microcontroller. Th
[Microcontroller]
DS1307 interfaces with 8051-compatible microcontrollers
USB-Controller Area Network (CAN) conversion of CP2102 and C8051
      With the rapid development of computer technology, PC, a controller that has adopted USB as a universal bus and universal interface standard, has become the only choice for controlling terminals in almost all fields. As long as the interface standards are unified and the necessary application software and driver
[Microcontroller]
USB-Controller Area Network (CAN) conversion of CP2102 and C8051
How to use 8051 microcontroller to control stepper motor
In this article, we explain how to use 8051 microcontroller to control stepper motors. Stepper motors are widely used in industrial, medical, and consumer electronics applications. In short, it is used wherever precise rotation or positioning of an object is required. 1. What is a stepper motor? A stepper motor is a
[Microcontroller]
How to use 8051 microcontroller to control stepper motor
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号