0% found this document useful (0 votes)
89 views28 pages

Đ Án 1 (Thành+Dương)

The project aims to design a compact and cost-effective device for measuring temperature, humidity, and carbon monoxide (CO) concentration, utilizing advanced sensors and microcontroller technology for real-time monitoring. It features a user-friendly interface, supports wireless data transmission, and is applicable in various environments to enhance safety and comfort. The document includes detailed hardware and software specifications, sensor integration, and potential applications of the monitoring solution.

Uploaded by

khang pham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views28 pages

Đ Án 1 (Thành+Dương)

The project aims to design a compact and cost-effective device for measuring temperature, humidity, and carbon monoxide (CO) concentration, utilizing advanced sensors and microcontroller technology for real-time monitoring. It features a user-friendly interface, supports wireless data transmission, and is applicable in various environments to enhance safety and comfort. The document includes detailed hardware and software specifications, sensor integration, and potential applications of the monitoring solution.

Uploaded by

khang pham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

HA NOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

PROJECT I
Design a device for measuring temparature,
humidity and CO concentration
HO XUAN THANH

[email protected]
VO TU DUONG
[email protected]

Instructor : PGS. TS. Nguyen Thanh Huong


Supervisor’s signature

School: School of Electrical and Electronic Engineering

HA NOI, 7/2024
Abstract
This project focuses on the design and development of a compact, efficient, and
cost-effective device for measuring environmental parameters: temperature,
humidity, and carbon monoxide (CO) concentration. The device integrates advanced
sensors and microcontroller technology to ensure precise and real-time monitoring.
The primary objectives include achieving high accuracy, low power consumption,
and ease of use. The device features a user-friendly interface and supports wireless
data transmission for remote monitoring. Applications range from residential to
industrial environments, enhancing safety and comfort by providing timely alerts
and historical data analysis. This project aims to contribute to the growing need for
reliable environmental monitoring solutions.

1
TABLE OF CONTENTS

CHAPTER 1: INTRODUCTION ................................................................... 1


CHAPTER 2: HARDWARE........................................................................... 2
2.1. Microcontroller STM32F103C8T6 ............................................................ 3
2.2. Humidity & Temperature sensor DHT11 . ................................................. 6
2.3. CO concentration sensor MQ-7 ................................................................ 10
2.4. Real-time DS1307 ..................................................................................... 15
2.5. Heating and convert circuit for MQ-7 ...................................................... 16
 Waring system .......................................................................................... 17
 Display LCD20x04 Modul ...................................................................... 18
 Power circuit ............................................................................................. 20
CHAPTER 3: SOFTWARE .......................................................................... 21
 Flowchart................................................................................................... 21
CONCLUSION ............................................................................................... 23

2
LIST OF FIGURES
Figure 2.1: Block diagram of the device ..................................................................... 2
Figure 2.2: Pin configuration ...................................................................................... 3
Figure 2.3: Sensor DHT11 .......................................................................................... 6
Figure 2.4: Communication process of DHT11 and MCU ......................................... 8
Figure 2.5: Start pulse ................................................................................................. 8
Figure 2.6: Response of DHT11 to MCU ................................................................... 9
Figure 2.7: Data indication .......................................................................................... 9
Figure 2.8: a) Structure of MQ-7 b) MQ-7 ............................................................. 10
Figure 2.9: Circuit of MQ-7 ...................................................................................... 11
Figure 2.10: Operation of MQ-7 ............................................................................... 11
Figure 2.11: The typical dependence of the MQ-7 on temperature and humidity.... 12
Figure 2.11: Sensitivity characteristics of MQ-7 ...................................................... 14
Figure 1.13: Real-time DS1307 module ................................................................... 15
Figure 2.14: Heating circuit for MQ-7 ...................................................................... 16
Figure 2.15: LCD 20x04 module .............................................................................. 18
Figure 2.12: a) AMS1117 b) DC-DC LM2596 ................................................. 20
Figure 3.1: Flowchart of subprogram related to sensors ........................................... 21
Figure 3.2: Flowchart for main program ................................................................... 22

3
LIST OF TABLES

Table 2.1: Features of each pin STM32F103C8T6 .................................................... 4


Table 2.2: The detailed technical specifications of sensor DHT11 ............................ 7
Table 2.3: Pins of MQ-7........................................................................................... 10
Table 2.4: Value of k1, k2 in each situation ............................................................. 13
Table 2.5: Value of k3, k4 in respect to each rate ..................................................... 15
Table 2.6: Command table ........................................................................................ 19
Table 2.6: Input voltage for each element................................................................. 20

4
CHAPTER 1: INTRODUCTION
In recent years, environmental monitoring has become increasingly important due
to the growing awareness of air quality and its impact on health and well-being.
Carbon monoxide (CO), a colorless and odorless gas, poses significant risks even at
low concentrations. It is produced by incomplete combustion processes, such as those
occurring in vehicles, industrial facilities, and residential heating systems. Prolonged
exposure to CO can lead to severe health issues, including headaches, dizziness, and
in extreme cases, death. Therefore, reliable CO detection and monitoring are crucial
for ensuring public safety.

Simultaneously, monitoring temperature and humidity is essential for a


comprehensive understanding of environmental conditions. Temperature variations
can affect human comfort, the efficiency of heating and cooling systems, and the
operation of various industrial processes. Humidity levels play a critical role in
respiratory health, the preservation of materials, and the prevention of mold growth.
Accurate measurement of these parameters can inform better decision-making in both
residential and industrial settings.

Moreover, accurate measurement of CO concentration requires consideration of


temperature and humidity levels. CO sensors can be affected by environmental
conditions, making it necessary to monitor and adjust for these factors to ensure
precise readings.

This project aims to develop a system that can accurately measure the concentration
of carbon monoxide (CO) in the air, along with ambient temperature and humidity
levels. By integrating advanced sensors and data processing techniques, the system
will provide real-time monitoring and alerts, enhancing safety and comfort in various
environments. The integration of CO, temperature, and humidity measurements into
a single platform offers a comprehensive solution for environmental monitoring,
contributing to healthier and safer living and working spaces.

In the following sections, we will discuss the technical specifications of the sensors
used, the design and implementation of the measurement system, and the potential
applications and benefits of this integrated monitoring solution.

1
CHAPTER 2: HARDWARE

In this section, we present the detail of the developed system used for measuring
temperature, humidity and CO concentration. This system measure temperature and
humidity via a DHT11 sensor and utilize this information to calibrate in order to
measure CO concentration. Then, 3 main information temperature, humidity and CO
concentration to the display LCD 2004. Furthermore, we use the warning and real-
time system to display the real-time information and inform when the data refer to
that is not safety.

In particular, we first introduce the hardware of the system, then design of the
software for the system is also presented.

Figure 2.1: Block diagram of the device

• Microcontroller STM32F103C8T6
• Sensor DHT11
• Sensor MQ-7
• LCD 2004 Module
• Real-time Module
• Buzzer/LED
• Other electrical device: Include converter/voltage regulation, resister,
capacitor, …
2
2.1 Microcontroller STM32F103C8T6
A medium density performance line ARM Cortex-M3 32-bit microcontroller in a
48-pin LQFP device is the STM32F103C8T6. High-performance RISC CPU working
at 72 MHz, fast embedded memories, a wide range of improved I/Os, and peripherals
coupled to two APB busses are all included. The 12-bit ADC, three general purpose
16-bit timers plus one advanced-control timer with standard and sophisticated
communication interfaces: two I2Cs and SPIs, three USARTs, a CAN and a
USB. Low power application design is made possible by a wide range of power
saving modes.
The devices function within a power supply range of 2.0 to 3.6 V. They are
available for operation in two temperature ranges: from -40 to +85°C and the extended
range from -40 to +105°C. These microcontrollers offer a wide array of power-saving
modes, enabling the creation of energy-efficient applications.
2.1.1 Structure of hardware STM32F103C8T6:
• Memory Flash & SRAM: 60KB & 20KB respectively
• Operating voltage: 2.0 to 3.6 V
• Clock, reset and supply management
• 37 GPIOs
• Debug mode: Serial wire debug (SWD) and JTAG interfaces
• Up to nine communication interfaces
2.1.2. Pin Configuration STM32F103C8T6:
The STM32F103C8T6 microcontroller comes in a 48-pin LQFP package.

Figure 2.2: Pin configuration

3
Table 2.1: Features of each pin STM32F103C8T6

Pin Pin Name Function Pin Pin Function


Num Num Name
1 PA13 25 PC14 OSC32-IN
JTMS/SWDIO
2 PA14 JTCK/SWCLK 26 PC15
OSC32-OUT
3 PF0 OSC_IN 27 NC
Not Connected
4 PF1 OSC_OUT 28 PA11
USB_DM
5 OSC_IN Main Oscillator Input 29 PA12
USB_DP
6 OSC_OUT Main Oscillator Output 30 PA15
JTDI
7 NRST Reset 31 PB0 ADC1_IN8/TIM3_CH3
8 PA15 JTDI 32 PB1
ADC1_IN9/TIM3_CH4
9 VSS Ground 33 PB2 BOOT1
10 VDD Power Supply 34 PB10
I2C2_SCL/TIM2_CH3
11 PA0 USART2_CTS/TIM2_CH1/TIM5_ 35 VSSA Analog Ground
CH1
12 PA1 USART2_RTS/TIM2_CH2/TIM5_ 36 VDDA
Analog Power Supply
CH2
13 PA2 USART2_TX/TIM2_CH3/TIM5_ 37 SWDIO
Serial Wire Debug I/O
CH3
14 PA3 USART2_RX/TIM2_CH4/TIM5_ 38 SWCLK Serial Wire Clock
CH4
15 PA4 SPI1_NSS/USART2_CK/DAC_ 39 PB11
I2C2_SDA/TIM2_CH4
OUT1
16 PA5 SPI1_SCK/DAC_OUT2 40 PB12 SPI2_NSS
17 PA6 SPI1_MISO/TIM3_CH1 41 PB13 SPI2_SCK
18 PA7 SPI1_MOSI/TIM3_CH2 42 PB14
SPI2_MISO
19 PA8 MCO/TIM1_CH1 43 VSS
Ground
20 PA9 44 VDD
USART1_TX/TIM1_CH2 Power Supply
21 PA10 45 PB15
USART1_RX/TIM1_CH3 SPI2_MOSI
22 VSS Groud 46 PB8
I2C1_SCL/TIM4_CH3
23 VDD Power Supply 47 PB9
I2C1_SDA/TIM4_CH4
24 PC13 48 PB5
TAMPER-RTC I2C1_SMBA/TIM3_CH2

4
This above table provides a simplified view of the pin functions. The actual pin
functionalities can be more diverse due to the alternate function mapping which can
be configured via software.

2.1.3. Advantage & Disadvantage:

Advantages:

• High performance: With a maximum working frequency of 72 MHz and


floating-point and high-performance computing capabilities, this frequency is
ideal for real-time and computationally demanding applications.
• Rich peripherals: Numerous built-in peripherals, including timers, PWM, SPI,
I2C, UART, and up to 39 GPIO, can be adjusted to suit a variety of application
scenarios.
• Low power consumption: Numerous low power consumption modes—such as
standby, hibernation, shutdown, and others—that are integrated and
appropriate for low power conditions. These modes can also help prolong the
life of batteries.
• Abundant software support: Adopting the ARM Cortex-M3 core and
supporting a wide range of software packages and development tools (Keil,
IAR, CubeMX, etc.) results in great development efficiency.
• High cost-effectiveness: This feature can better satisfy the demands of low-
cost and accessible applications and is applicable to a wide range of industries,
including embedded systems, smart homes, and the Internet of Things.
Disadvantage:
• Limited Flash and RAM: For complex applications or those requiring more
memory, the 64 KB Flash and 20 KB SRAM may be insufficient.
• Package: The package might be challenging for those without experience in
soldering fine-pitch components.
• Limited Advanced Features:
• No FPU: Lacks a floating-point unit, which may be a drawback for
applications requiring extensive floating-point calculations.
• No Ethernet or CAN: Missing some advanced communication interfaces
found in higher-end STM32 models.
In summary, the STM32F103C8T6 is a versatile and cost-effective microcontroller
with a good balance of performance and peripherals, suitable for a wide range of
embedded applications. However, it has limitations in memory, lacks some advanced
features, and can pose a challenge for beginners.

5
2.2 Humidity & Temperature Sensor DHT11:
2.2.1. Introduction
The DHT11 is a widely used temperature and humidity sensor known for its
affordability, simplicity, and reliability. It integrates a thermistor and a capacitive
humidity sensor to measure the surrounding air and provides calibrated digital output.
The sensor uses a single-wire digital interface, which simplifies the connection to
microcontrollers and other digital devices. This single-wire interface is not only easy
and quick to implement but also reduces the number of pins required, making it ideal
for projects with limited I/O availability.

Figure 2.3: Sensor DHT11

Furthermore, the DHT11 is compact and lightweight, which allows it to be easily


integrated into various projects without adding significant bulk. Its low power
consumption makes it suitable for battery-operated devices. Overall, the DHT11
temperature and humidity sensor is a versatile and essential tool for anyone interested
in environmental sensing and monitoring.

2.2.2. Technical Specification


The DHT11 sensor operates within a temperature range of 0 to 50 degrees Celsius
with an accuracy of ±2 degrees, and it can measure humidity levels from 20% to
90% with an accuracy of ±5%. These specifications make it adequate for general
applications, though not ideal for situations requiring high precision.

6
Table 2.2: The detailed technical specifications of sensor DHT11

Parameters Conditions Minimum Typical Maximum


Humidity
Resoulution 1%RH 1%RH 1%RH
8 bit
Repeatability ±1%RH
Accuracy 25°C ±4%RH
0-50°C ±5%RH
Interchargable Fully Interchargable
Measurement 0°C 30%RH 90%RH
Range 25°C 20%RH 90%RH
50°C 20%RH 80%RH
Response Time 1/e(63%) 25°C 6s 10 s 15 s
(Seconds) 1m/s Air
Hysterisis ±1%RH
Long-term Typical ±1%RH/year
Stability
Temperature
Resolution 1°C 1°C 1°C
8 bit 8 bit 8 bit
Repeatability ±1°C
Accuracy ±1°C ±2°C
Measurement 25°C 25°C
Range
Response Time 1/e(63%) 6s 30 s
(Seconds)

The table above outlines the key technical specifications of the DHT11 sensor,
providing comprehensive details on its operational parameters, electrical
characteristics, physical dimensions, and performance metrics. This information is
crucial for understanding the sensor's capabilities and limitations, ensuring accurate
integration and optimal performance in various applications.

2.2.3. Power and Pin


The DHT11 operates at a voltage range of 3.3V to 5.5V, making it compatible
with both 3.3V and 5V logic devices. Its low power consumption is another
advantage, drawing only about 2.5mA during measurement and less than 1µA in
standby mode. This makes it suitable for battery-operated devices and projects
where power efficiency is crucial.

7
2.2.4. Communication Process: Serial Interface
The single-bus data format is used for communication and synchronization
between the MCU and the DHT11 sensor. Each communication process takes
approximately 4ms.

The data includes both decimal and integral parts, with a complete transmission
consisting of 40 bits. The data format is structured as follows: 8 bits for the integral
part of the relative humidity (RH), 8 bits for the decimal part of the RH, 8 bits for
the integral part of the temperature, 8 bits for the decimal part of the temperature,
and 8 bits for the checksum.

a) Overview Process

When MCU sends a start signal, DHT11 will change its mode from the low-
power-comsumption mode to the running-mode. When MCU complete the start
signal, DHT11 sends a response signal to MCU to transmit 40-bit data, that include
the temperature and humidity information. Once data is collected, DHT11 will
change to the low-power-consumption mode.

Figure 2.4: Communication process of DHT11 and MCU

b) Start pulse (Request)

Data Single-bus free status is at high voltage level. To start communication with
DHT11, first we should send the start pulse to the DHT11 sensor. To provide start
pulse, pull down (low) the data pin minimum and then pull up. This process must
take at least 18ms to ensure DHT’s detection of MCU's signal and take 20-40 us to
wait for response.

Figure 2.5: Start pulse

8
c) Response from DHT11

After getting start pulse from, DHT11 sensor sends the response pulse which
indicates that DHT11 received start pulse. The response pulse is low for 54us and
then goes high for 80us for DHT’s preparation for sending data.

Figure 2.6: Response of DHT11 to MCU

d) Data transmission

After sending the response pulse, DHT11 sensor sends the data, which contains
humidity and temperature value along with checksum.

When DHT is sending data to MCU, every bit of data begins with the 50us low-
voltage-level andthe length of the following high-voltage-level signal determines
whether data bit is "0" or "1"

Figure 2.7: Data indication

If the response signal from DHT is always at high-voltage-level, it suggests that


DHT is not responding properly and please check the connection. When the last bit
data is transmitted, DHT11 pulls down the voltage level and keeps it for 50us. Then
the Single-Bus voltage will be pulled up by the resistor to set it back to the free
status.

9
2.3. CO Concentration Sensor MQ7:
The MQ-7 sensor is a type of gas sensor designed to detect the concentration of
carbon monoxide (CO) in the air. This sensor is very popular in safety-related
applications such as gas leak warning systems, air quality monitoring systems, and
other measuring devices. With the ability of detecting CO gas in the range of 10 ppm
to 1000 ppm, MQ7 uses a sensing element made of SnO2 (tin dioxide) whose
conductivity increases when the concentration of CO gas in the air increases. This
change is converted into an electrical signal to measure the gas concentration.

2.3.1. Structure and configuration, basic measuring circuit.


a) Structure and configuration

Sensor composed by micro AL2O3 ceramic tube, Tin Dioxide (SnO2)


sensitive layer, measuring electrode and heater are fixed into a crust made by
plastic and stainless steel net. The enveloped MQ-7 have 6 pin ,4 of them are
used to fetch signals, and other 2 are used for providing heating current.

Table 2.3: Pins of MQ-7

Part Meterial
1 Gas sensing layer SnO2
2 Electrode Au
3 Electrode line Pt
4 Heater coil Ni-Cr alloy
a) 5 Tubular ceramic Al2O3
6 Anti-explosion Stainless steel gauze
network (SUS316 100-mesh)
7 Clamp ring Copper plating Ni
8 Resin base Bakelite
9 Tube Pin Copper plating Ni

b)
Figure 2.8: a) Structure of MQ-7 b) MQ-7

10
b) Measuring circuit

Figure 2.9: Circuit of MQ-7

As shown in Fig 2.8, standard measuring circuit of MQ-7 sensitive components


consists of 2 parts. one is heating circuit having time control function (the high voltage
and the low voltage work circularly). The heating circuit is the combination of
OPAMP and STM32 signal, which will be presented in the part ...

The second is the signal output circuit, it can accurately respond changes of surface
resistance of the sensor. The output signal then feed to the STM32 to measure the CO
concentration.

2.3.2. Operation principle:


The figure 2.9 show the operation of MQ7:

Figure 2.10: Operation of MQ-7

The MQ-7 sensor requires a heating cycle to operate accurately, usually consisting
of two stages:

• High heating stage (60s): During this period, the sensor is heated to a high
temperature to clean the surface and prepare for gas detection.

11
• Low heating stage (90s): At a lower temperature, the sensor measures the
CO gas concentration in the air.

The high voltage level 5V is used for heating stage, at this period, the feedback
signal form the sensor is not reiable. In the low heating stage, low voltage level at
1.4V is used, the value of sensor can be measured to calculate the CO concentration.

2.3.3. Data processing


The relationship between the surface resistance of the sensor Rs and the load
resistance RL is described:
𝑅𝑠 𝑉𝐶 −𝑉𝑅𝐿
= (2.3.1)
𝑅𝐿 𝑉𝑅𝐿

𝑉𝐶 is the voltage source and 𝑉𝑅𝐿 is the voltage of the resistance RL, which is the output
signal can be measured through STM32. The voltage source 𝑉𝐶 = 5V and RL = 10kΩ
are used to design the measure circuit. Then the sensor resistance can be calculated
form Eq.2.3.1 as:
𝑉𝐶 −𝑉𝑅𝐿
𝑅𝑠 = . 𝑅𝐿 (2.3.2)
𝑉𝑅𝐿

After getting 𝑅𝑠 from the Eq.2.3.2 , 𝑅𝑠 must be adjusted to the standard condition
(at temp 200C, humidity 65%) through the dependence relation of sensor resistance
on temparature and humindity.

Figure 2.11: The typical dependence of the MQ-7 on temperature and humidity.

Ro: sensor resistance at 100ppm in air at 33%RH and 20degree.

Rs: sensor resistance at different temperatures and humidity.

12
Assume that the measured resistance is at the condition 𝑅𝑠 (T0C, RH%) then the
mission is adjusting to the standard condition 𝑅𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑 (200C,65%). Overall, this
mission required a mid-processing convert through R0(200C, 33%). First, we build the
equation for the dependence of MQ7 resistance. For all condition of humidity, the
dependence equation has similar form as:
𝑅𝑠
= 𝑘1 . 𝑒 −𝑇 + 𝑘2 , if T < 50C
𝑅0
𝑅𝑠 , if T ≥ 50C
log ( ) = 𝑘1 . log(𝑇) + 𝑘2
𝑅0

Table 2.4: Value of k1, k2 in each situation

Temperature Humidity: 33% Humidity: 85%


𝑘1 𝑘2 𝑘1 𝑘2
−100 𝐶 ≤ 𝑇 < 00 𝐶 1,067.10 −5 1,129
6,674.10 −5 1,033

00 𝐶 ≤ 𝑇 < 50 𝐶 14,84 - 13,625 0,0675 0,9655


50 𝐶 ≤ 𝑇 < 100 𝐶 -0,0648 0,0926 -0,078 0,0397
100 𝐶 ≤ 𝑇 < 150 𝐶 -0,0847 0,1125 -0,068 0,0297
150 𝐶 ≤ 𝑇 < 200 𝐶 -0,103 0,134 -0,1598 0,137
200 𝐶 ≤ 𝑇 < 250 𝐶 -0,155 0,202 -0,1067 0,0682
250 𝐶 ≤ 𝑇 < 300 𝐶 -0,0916 0,113 -0,1338 0,1061
300 𝐶 ≤ 𝑇 < 350 𝐶 -0,138 0,1816 -0,121 0,0876
350 𝐶 ≤ 𝑇 < 400 𝐶 -0,204 0,2836 -0,1426 0,1206
400 𝐶 ≤ 𝑇 < 450 𝐶 -0,1419 0,184 -0,2766 0,3352
450 𝐶 ≤ 𝑇 -0,436 0,671 -0,2807 0,342
For 𝑅𝑠 (T0C, RH%), we can have the equation:
𝑅 𝑅
At RH = 65%: log ( 𝑠 ) = 𝑘1 . log(𝑇) + 𝑘2 ⇒ ( 𝑠 )85% = 10𝑘1 .log(𝑇)+𝑘2 (2.3.3)
𝑅0 𝑅0

𝑅 𝑅 ′ ′
At RH = 33%: log ( 𝑠 ) = 𝑘1′ . log(𝑇) + 𝑘2′ ⇒ ( 𝑠 )33% = 10𝑘1.log(𝑇)+𝑘2 (2.3.4)
𝑅0 𝑅0

𝑅𝑠
From the Equ.(2.3.3) and Equ.(2.3.4) , the ratio of can be computed:
𝑅0

𝑅 𝑅 85−𝑅𝐻 𝑅 𝑅
( 𝑠 )𝑅𝐻% = ( 𝑠 )85% + ( ). [ ( 𝑠 ) − ( 𝑠) ] (2.3.5)
𝑅0 𝑅0 85−33 𝑅0 33% 𝑅0 85%

13
Then the relationship between 𝑅𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑 (200C,65%) and R0(200C, 33%) can be
computed:
𝑅 ′ ′
( 𝑠 )33% = 10𝑘1 .log(𝑇)+𝑘2 = 10−0,155.log(20)+0,202 = 1
𝑅0

𝑅
( 𝑠 )85% = 10𝑘1.log(𝑇)+𝑘2 = 10−0,1067.log(20)+0,0682 = 0,85
𝑅0

𝑅𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝑅 85−65 𝑅 𝑅
( )65% = ( 𝑠 )85% + ( ). [ ( 𝑠 ) − ( 𝑠) ]
𝑅0 𝑅0 85−33 𝑅0 33% 𝑅0 85%

𝑅𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑 85−65
( )65% = 0,85 + ( ). [1 − 0,85] = 0,908
𝑅0 85−33

⇒ 𝑅𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑 = 0,908 . 𝑅0 (2.3.6)

From Equ.(2.3.5) and Equ.(2.3.6) , adjusted sensor resistance value can be computed:
𝑅𝑠 1 𝑅 85−𝑅𝐻 𝑅 𝑅
( ) = . ( 𝑠 )85% + ( ). [ ( 𝑠 ) − ( 𝑠) ]
𝑅𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝑅𝐻% 0,908 𝑅0 85−33 𝑅0 33% 𝑅0 85%

𝑅𝑠
After getting the ratio , we can get the concentration of CO from the sentivity
𝑅𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑
characteristic.

Figure 2.11: Sensitivity characteristics of MQ-7

14
The concentration from the Figure can be calculated with the formular:
𝑅𝑠
log(𝑝𝑝𝑚) = 𝑘3 . log ( ) + 𝑘4
𝑅𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑
Table 2.5: Value of k3, k4 in respect to each rate

𝑅𝑠
rate = Humidity: 33%
𝑅𝑠𝑡𝑎𝑛𝑑𝑎𝑟𝑑
𝑘3 𝑘4
rate > 1,66 ppm = 50
1< rate ≤ 1.66 -1.3676 2
0,36< rate ≤ 1 -1.3569 2
0,226< rate ≤ 0,36 -1.9681 1.7288
0,09< rate ≤ 0,226 -2.5 1.385
rate ≤ 0,09 ppm = 4000

2.4. Real-time DS1307:


The DS1307 is a real-time clock (RTC) module that keeps track of the current time
and date even when the system is powered off. It uses an I²C interface to communicate
with microcontrollers, making it easy to integrate into various applications such as
time-stamping, scheduling, and clock-based functionalities.

Figure 1.13: Real-time DS1307 module

Due to the low accuracy of real-time clock in STM32, additional module has to be
used to save the real-time information and control the heating circuit.

15
2.5. Heating and convert circuit for MQ7
2.5.1. Heating circuit for MQ7
With the requirement of period heating and cooling condition for MQ7,
specifically:

• High heating stage (60s at 5V): During this period, the sensor is heated to
a high temperature to clean the surface and prepare for gas detection.
• Low heating stage (90s at 1.4V): At a lower temperature, the sensor
measures the CO gas concentration in the air.

Since the output of the STM32 is only 0V-3V, although using PWM method, the
requirement of 5V cannot be reached. Therefore, a heating circuit must be designed
to complete the mission. This circuit is designed mainly based on the OPAMP and
resistor to get the suitable amplifier gain:

Figure 2.14: Heating circuit for MQ-7

The input R1 is the PWM signal with the Duty circle D(%), therefore:

𝑈𝑖𝑛 = 𝐷. 3𝑉

The amplifier circuit has the gain K=2, therefore:

𝑈𝑜𝑢𝑡 = 2. 𝑈𝑖𝑛 = 2. 𝐷. 3 = 6. 𝐷 (𝑉)

For both cases, to control the heating circuit, we use PWM signal with difference duty
circle:

• High heating stage (60s at 5V): D = 5/6 = 83.33%.


• Low heating stage (90s at 1.4V): D = 1.4/6 = 23.33%.

16
2.5.2. Convert circuit for MQ7
The output of MQ7 has the range from 0V to 5V but the ADC in STM32F103C8T6
is 12 bits and has the maximum input voltage is 3.3V. Therefore, it is necessary to
have a convert circuit to step down the voltage from 5V to 3.3V linearly.

The simple method is using amplifier to reduce the voltage. The circuit has
following form:

The output can be written in the formula contain the input:


𝑅2
𝑉0 = ⋅ 𝑉𝑖
𝑅1 +𝑅2

We have 𝑉0 = 3.3𝑉 while 𝑉𝑖 = 5𝑉 then the value of 𝑅1 and 𝑅2 :

𝑅2 𝑉0 3.3 33
= = =
𝑅1 + 𝑅2 𝑉𝑖 5 33 + 17

Therefore, we can choose 𝑅1 = 17 𝑘𝛺 and 𝑅2 = 33 𝑘𝛺

2.6. Warning system


Led and buzzer can be used to inform some overheat or the concentration of CO
are exceeded safety condition.

The system will have the warning message if exist some following condition:

• The temperature is over 450C or lower than 100C.


• The humidity is over 90% or under 35%.
• The CO concentration is over 1000ppm.

The system will give the message by buzzer and light.

17
2.7. Display LCD20x04 Module
An LCD 20x4 is a type of liquid crystal display that can show 20 characters per line
on 4 lines. It's commonly used in various electronics projects. Its blue or green backlit
screen offers good visibility under different lighting conditions. The LCD 2004 is
highly valued for its ease of use, reliability, and ability to enhance the functionality of
numerous DIY and professional applications.

Figure 2.15: LCD 20x04 module

2.7.1. Pin configuration


There are 16 pins:

• VSS: Ground
• VCC: Power (5V)
• Constrast Voltage (VEE): control the bright of display
• Register Select (RS): A signal for selecting registers:
• 1: Data Register (for read and write)
• 0: Instruction Register (for write), Busy flag_Address Counter (for read)
• Read/Write (R/W): Choose read/write mode
• R/W = “H”: Read mode
• R/W = “L”: Write mode
• Enable (E): An enable signal for writing or reading data
• D0-D7: 8-bit bi-directional data bus with 2 mode: 8 bit and 4 bit
• LED+: Power supply for backlight
• LED-: The backlight ground
18
2.7.2. Command Table
Table 2.6: Command table

Instruction Mode
Instruction Discription
RS RW DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0

Clear Write “20H” to


Display 0 0 0 0 0 0 0 0 0 1 DDRAM and set
DDRAM address to
“00H” from AC
Set DDRAM address to
“00H” from AC and
Return 0 0 0 0 0 0 0 0 1 - return cursor to its
Home original position if
shiftes. The contents
of DDRAM are not
changed
Entry Mode Assign cursor moving
Set 0 0 0 0 0 0 0 1 I/D S direction and enable
the shift of retire
display
Display Set display (D).
ON/OFF 0 0 0 0 0 0 1 D C B cursor©, and blinking
Control of cursor(B) on/off
control bit
Set cursor moving and
Cursor or display shift control
Display Shift 0 0 0 0 0 1 S/C R/L - - bit, and the direction,
without changing of
DDRAM data
Function Set Set interface data
0 0 0 0 1 DL N F - - length, numbers of
display line and,
display fone type
Set CDRAM 0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC0 Set CGRAM address in
Address address counter
Set DDRAM 0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0 Set DDRAM address in
Address address counter
Read Busy Whether during
Flag and internal operation or
Address 0 1 BF AC6 AC5 AC4 AC3 AC2 AC1 AC0 not can be known by
Counter reading BF. The couter
can also be read
Write Data 1 0 D7 D6 D5 D4 D3 D2 D1 D0 Write data into
to RAM internal RAM
Write Data 1 1 D7 D6 D5 D4 D3 D2 D1 D0 Read data from
from RAM internal RAM
Note1: “—” don’t care

The command table for the LCD 2004 is a set of predefined instructions used to
control the display's behavior.
19
2.8. Power circuit:
Overall, the power circuit must ensure enough power and voltage for all different
input voltage of all devices. Some devices has input power form the STM32F103C8
will not be computed since they had own circuit before. The information input voltage
is listed below:

Table 2.6: Input voltage for each element

No. Circuit elements Input voltage


1 Microcontroller STM32 3.3V
2 LCD 2004 5V
3 CO sensor: MQ7 5V
4 DS1307 5V

Almost devices need 5V voltage supply but it’s hard to find exactly 5V voltage
supply. Therefore, 3 battery cells (3.7V for each) were used to generate 12V power
supply for all device. Moreover, a Buck converter DC-DC LM2596 was use to
stepdown voltage to 5V to feed to the device No2,3,4. For STM32F103C8, using a
3.3V voltage regulation AMS1117 to get the input voltage for microcontroller.

a) b)

Figure 2.12: a) AMS1117 b) DC-DC LM2596

20
CHAPTER 3: SOFTWARE
We have been developed a software program based on the Keil C. The software sets
up the GPIO pins for communication with both sensors. For the DHT11, a library is
typically used to simplify the process of sending a start signal, reading the 40-bit data
stream, and interpreting the temperature and humidity values. For the MQ-7 CO
sensor, an analog read function is employed to measure the voltage level
corresponding to the CO concentration. The software includes routines to initialize
the sensors, periodically read data from them, and process this data to convert raw
sensor values into meaningful measurements. Data from the DHT11 is converted to
human-readable temperature and humidity values, while the analog value from the
MQ-7 is converted to a CO concentration level using a calibration curve. The software
also handles error checking and data validation to ensure reliable readings. Finally,
the processed data is displayed on an LCD screen.

3.1. Flowchart
a) Flowchart for sensors

a) b)

Figure 3.1: Flowchart of subprogram related to sensors

21
• Subprogram (a) starts with the initiation of the DHT11 sensor. It then waits
for a response from the DHT11. Upon receiving a response, the program reads
the data, checks the validity of the data, and stores the values into variables.
• Subprogram (b) begins by taking values from the ADC (Analog-to-Digital
Converter) and calculating the average value. The program then converts
these values to initial voltage (before amplification by OPAMP). It calculates
the sensor resistor and adjusts it based on temperature and humidity. The next
step is to calculate the ratio Rs/R0 and determine the CO concentration.
Finally, the program returns the concentration value in ppm and stops the
process.

b) Flowchart for main program

The below flowchart outlines the main program's process. It begins with initializing
the I2C and LCD. The program then checks if the user wants to set up the time. If the
user chooses to set up the time, the program scans the key matrix and saves the time
value. If the user opts not to set up the time, the program proceeds to take the values
of temperature and humidity. Following this, it measures the CO concentration in
parts per million (ppm). The current time, along with the temperature, humidity, and
CO ppm values, are printed on the LCD. Finally, the program waits for a button press
to either restart the process or terminate it, depending on the button's function.

Figure 3.2: Flowchart for main program

22
CONCLUSION
After have the research on the DHT11 and MQ7, we have a deeper knowledge
about some useful sensor, gain coding and programming technique. For DHT11, we
have deeper learning of the communication protocol between different devices. For
the MQ7, I have explored the general operating principle of gas sensors and their
dependence on external factors such as humidity and temperature.

After completing the project, several drawbacks remain unresolved. The solution
for these problems is recommended to improve the disadvantage.

• First, although the measurement range and accuracy of the DHT11 sensor
have improved compared to the LM35 sensor, in certain conditions, they
are still not wide enough and the accuracy is not high enough. The solution
is that we can consider using another sensor or use better sensor is DHT22
with higher range and accuracy.
• Second, the use of the DC-DC converter (LM2596) only achieved the
condition of reducing the voltage to 5V but did not achieve stability due to
voltage drops when connecting multiple devices together. By adding
voltage regulator 5V, we can improve the voltage supply for devices.
• Third, the usage time is not very long due to the lack of energy optimization
in the program and limitations when connecting to a battery. The power
component can be replaced by a AC-DC converter, convert from 220VAC
to 12VDC to get a sustainable voltage supply.
• Fourth, the CO concentration is not measured very frequently due to the
heating conditions of the MQ7 sensor (typically only able to check about
every 30 seconds, with a 1-minute interval before the next check), leading
to lower efficiency when the system requires continuous monitoring. A
possible solution is to use multiple MQ7 sensors simultaneously in a
staggered manner, meaning they will operate together but have alternating
measurement intervals, sequentially reporting values back to the STM32.

23

You might also like