5v1BAc9

#9th LCSC Electronics Design Contest# High-quality touch temperature and humidity sensor

 
Overview

1. Project Introduction:

The core circuit design of this project replicates the LCSC EDA Training Camp – Desktop Temperature and Humidity Detector. Based on the training camp's basic design, components and layout were optimized to reduce the overall size of the detector. Considering the difficulty of pressing the original physical wake-up button with a single finger, this project upgraded it to a touch wake-up button for easier single-finger operation. Simultaneously, an upper touch panel PCB was designed around the touch button, which also serves as the panel of the temperature and humidity detector, improving the overall aesthetics.

The main controller uses the low-cost STM32G030K6T6,
and the temperature and humidity acquisition uses the Sensirion SHT40-AD1B high-precision temperature and humidity sensor module.
Power is supplied by two AAA batteries, and it also supports 1.2V rechargeable batteries and 1.5V disposable batteries. It features an environmentally friendly design
. The data display section uses the classic 74HC595 tri-state output 8-segment shift register + digital tube combination. The
touch screen uses a single-channel capacitive touch, using the PT2041AT6 as the touch chip.
The main controller PCB and touch panel PCB are connected via POGO PIN surface mount spring pins and pads.
 
2. Circuit Design

: The overall circuit design framework is shown in the figure below.
The circuit itself is not complex; the main difficulty lies in understanding the working principle of the core display circuit, namely the shift register + digital tube. The microcontroller can directly control the digital tube display via GPIO, but a 3-digit digital tube requires 8 GPIOs to control the 8 LEDs in a single segment + 3 GPIOs to control the switching of the 3 segments, totaling 11 valuable GPIO port resources. This is a huge burden for the STM32 microcontroller with limited pins, so a tri-state output 8-bit shift register like the 74HC595 is needed to achieve a large number of outputs with a small number of GPIO ports.

The 74HC595 works as follows: the SER pin uses high and low levels to input data, and the SCLK pin uses high and low levels to make the data input by SER valid and segmented. Finally, RCLK inputs a high level to complete the entire communication process. For example, if the microcontroller needs to input 0111 0011 into the 74HC595 and output it, the input needs to be in reverse order: the first input is the last 1, followed by 1, 0, 0, 1, 1, 1, 0. First, SCLK is pulled high, and simultaneously SER is pulled high to input 1 (if 0 is needed, it is kept low). After completion, SCLK is pulled low, completing the input of this bit. After repeating the input 8 times to complete 8 bits, RCLK inputs a rising edge to complete this round of input, and the data in the shift register is shifted to the latch and output as an eight-bit block. The working principle of a common-cathode 3-segment LED display: Eight pins (A, B, C, D, E, F, G, DP) simultaneously control the same segment of each of the three digits, for a total of eight segments. DIG1, ​​DIG2, and DIG3 control the eight segments of the same digit. By alternating between these pins, a specific digit can be controlled at a time to display a designated number. For example, if the second digit needs to be 1, DIG1 and DIG3 are input with a high level to eliminate the potential difference and prevent current from flowing through the LEDs. DIG2 is input with a low level to create a potential difference, allowing the second digit to be displayed. Since the number 1 requires segments B and C to light up simultaneously, pins 4 and 7 are input with a high level, while the other six pins are input with a low level. At this point, only segments B and C of the second digit have a potential difference, causing them to conduct and light up, thus displaying the number 1 in the second digit.
 
3. Software Design:

The software design uses STM32CubeMX and Keil5. STM32CubeMX software can generate and configure basic code, providing a graphical configuration interface to help beginners get started quickly and significantly shorten the learning curve. The code used in this project requires the ARM Compile 5 compiler in Keil 5. The latest Keil 5 version includes the ARM Compile 6 compiler; the AC5 compiler needs to be installed separately, which can be downloaded directly after registering an account on the official website.
When configuring GPIO in STM32CubeMX, it's necessary to understand the two output modes: push-pull output and open-drain output.

Push-pull output: When a high level is desired, the P-MOS is on and the N-MOS is off, outputting the power supply voltage VDD. When a low level is desired, the N-MOS is on and the P-MOS is off, essentially grounding the pin and outputting a low level.
In open-drain output mode, the P-MOS is always off. When the N-MOS is on, a low level is output; when the N-MOS is off, both the P-MOS and N-MOS terminals are off, and the resistance of the two transistors can be considered infinite, resulting in a high-impedance output. Open-drain outputs require a pull-up resistor and are often used in scenarios where the chip's direct output voltage does not match the demand (e.g., an STM32 outputs 3.3V, but a 5V output is desired). An external pull-up resistor and a 5V power supply can be connected.

In summary, push-pull outputs can output both high and low levels, while open-drain outputs can only output low levels. This project requires high/low level switching for data output, therefore push-pull output mode is used.
When writing code in Keil 5, three aspects need to be thoroughly understood:

1) Interacting with the temperature and humidity sensor to obtain temperature and humidity data. Locate and open the relevant datasheet for the SHT40, focusing on the IIC address and data transmission protocol. The datasheet shows that 0x44 is the IIC address; when the least significant bit is 0, it indicates reading data; when the least significant bit is 1, it indicates writing data; when the 0xFD instruction is sent, it represents high-precision temperature and humidity measurement; the temperature and humidity can be calculated using formulas from the data; 2) Understanding interrupts. An interrupt occurs when a microcontroller encounters an urgent event during operation. The microcontroller pauses its current code execution and executes code for the more pressing event. After processing, it returns to the previously paused program. The STM32G030K6T6 uses a Cortex ARM0+ core, featuring an NVIC (Nested Interrupt Controller) and EXTI (External Interrupt Event Controller), supporting four priority settings. Each GPIO can be used as an external interrupt/event trigger signal input. This combination allows the microcontroller to respond quickly to external interrupts/events. Here, the PB7 (WAKE) pin is read on the falling edge. When a falling edge occurs, the microcontroller enters interrupt handling and executes the relevant code, eliminating the need to continuously poll the button pin for a low level.
3) Entering sleep mode and timer interrupts. The STM32G0 series has four sleep modes, with sleep mode waking the system from sleep and being woken up by any interrupt/event. Timer 14 interrupt is configured in CubeMX. It is disabled by default in the code, but starts automatically when enabled. An overflow interrupt occurs when the timer expires. The timer overflow interrupt callback function is used to acquire the temperature and display it on the digital tube.

 
4. Physical Demonstration:

The upper touch panel and main control board are fixed using M2*5+3 single-through copper pillars, and the main control board and base plate are fixed using M2*15 double-through copper pillars. The installation diagram is shown below.
Physical demonstration after assembly.
5. Demonstration Video

 
 
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2026-03-27 02:56:20

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

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号