Table of Contents
1 Project Overview
1.1 Project Function Introduction
1.2 Physical Demonstration
1.3 Optimization Suggestions
2 Project Attributes & Open Source License
2.1 Project Attributes
2.2 Open Source License
3 Hardware Part
3.1 Schematic Diagram
3.1.1 Main Control Part 3.1.2
Sensor Part 3.1.3
Shift Register 3.1.4
Display Part
3.1.5 Power Supply Part
3.2 PCB
3.2.1 Page Layout
3.2.2 Layout Considerations
3.2.3 Soldering
3.3 Housing
4 Software Part
5 BOM List
6 Competition Logo Verification
7 Demo Video
Postscript
Note: I originally included a table of contents navigation, but LCSC doesn't support it, so I had to delete the relevant sections. 1 Project Overview
1.1 Project Function Introduction
This project is a desktop temperature and humidity sensor based on the STM32G030K6T6.
The sensor used is the Swiss Sensory SHT40-AD1B, which has the advantages of low power consumption, high accuracy, and small size, making it very suitable for onboard use.
The display section uses an SN74HC595+ three-digit LED display.
The power supply section uses a 4.2V lithium battery.
1.2 Physical Display:
Front and

Back

1.3 Optimization Suggestions:
Map battery voltage to percentage and display
; optimize sampling
; change display method 2 Project Attributes & Open Source License
2.1 Project Attributes:
This project is being publicly released for the first time. It is an improvement based on the official schematic and source code and has not won any awards in other competitions.
2.2 Open Source License :
The open source license uses GPL 3.0
. GPL 3.0: https://www.gnu.org/licenses/gpl-3.0.html
3 Hardware Section
3.1 Schematic Diagram
3.1.1 Main Control Section
: The main control uses an STM32G030K6T6.

3.1.2 Sensor Section
: The sensor uses a Sensirion SHT40-AD1B from Switzerland. Compared to the module, a filter capacitor C1 and bus pull-up resistors R2 and R3 need to be added.

3.1.3 Shift Register
: The LED display shift register uses a 74HC595.

3.1.4 Display Section
The display section uses a 0.56-inch three-digit LED display.

Originally, I used one purchased from LCSC Mall (as shown in Figure 1). I bought six, but only one was left. So I had to buy one from Taobao (as shown in Figure 2). The price was one-quarter of that in Figure 1. The soldering temperature was slightly higher and it was perfectly fine. Unlike some other types, it would break as soon as it was soldered and was also ridiculously expensive.

3.1.5 Power Supply Section
(1) Power Supply Block Diagram

(2) Lithium Battery Charging Circuit
I believe everyone is familiar with TP4056, so I will not introduce it.

(3) LDO Circuit
The LDO used is RT9013-33GB.

Note that since the voltage of lithium batteries is between 3.3-4.2V, ordinary LDOs (such as AMS1117-3.3) are not suitable because their voltage difference is too large, around 1V. The voltage difference of RT9013-33GB is smaller, so RT9013-33GB is selected.
ME6211C33 can also be used here, as the circuits are basically the same. However, I have more RT9013-33GB (obtained from LCSC 16-15) and few ME6211C33, so I chose RT9013-33GB.
DC-DC is more efficient, but the cost is higher, so it is not chosen.
3.2 PCB
3.2.1 Page layout
The front

and back

are made of 1MM board, and the overall use is surface mount as much as possible. Resistors and capacitors are all 0603.
3.2.2 Layout precautions
(1) Copper-layout prohibited area

(2) No-trace area

(3) Component placement

Sensor placement suggestions

3.2.3 Soldering
solder paste and soldering oil (as shown in Figure 1), then use a heating table (as shown in Figure 2) and hot air gun for surface mount soldering, and then use a soldering iron to solder the plug-in. My heating table was damaged, so I used a constant temperature magnetic heater, which has a temperature of two or three hundred degrees, which is sufficient.

Soldering finished product

3.3 Outer
shell The outer shell is made of 2MM acrylic.


Use a single-edged tapered drill bit (as shown in Figure 1) to drill four countersunk holes in the acrylic (as shown in Figure 2). Since I am using a hand drill, I used a single-edged one.

Assemble the M3-5mm countersunk screws and M3-6mm copper posts.

4. Software Part
Due to my limited skill, please point out any errors.
To implement the functions of short press to power on, short press again to switch functions, and long press to power off, I added the following code to gpio.c to implement the long/short press judgment.
0.1s-1s is a short press, more than 1s is a long press
void Key_scan(void)
{
uint8_t val = HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_5);
static uint16_t count=0;
if (!val)//Record time
{
count++;
}
else
{
if(count>100)
{
device_paramter.KeyScan = 2;//Long press
}
else if(count>10 && count<100)
{
device_paramter.KeyScan = 1;//short press
}
count=0;
}
}
To prevent a short press from triggering the device and simultaneously determining a short press of Key_scan, I added a delay to the main loop:
HAL_Delay(150);
Correspondingly, modifications need to be made to main.c.
if(device_paramter.KeyStatus == KEY_SHAKE_STATE)
{
HAL_Delay(150);
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_5) == GPIO_PIN_RESET)
{
while(1)
{
device_paramter.sleepStatus = 0;//clear sleep flag
while(device_paramter.KeyScan == 0)
{
SHT40_Read_RHData(&temperature,&humidity);//read temperature and humidity
device_paramter.Temp = temperature * 10;//amplify temperature and humidity
device_paramter.Humi = humidity * 10;
device_paramter.Display_Type = 1;
HAL_TIM_Base_Start_IT(&htim14);//start timer, display data
Key_scan() );
}
if(device_paramter.KeyScan == 2)
{
device_paramter.KeyStatus = KEY_NO_PRESS; // Clear the key press flag
device_paramter.KeyScan = 0; // Reset the long/short press judgment
device_paramter.sleepStatus = 1; // Enable sleep flag
break; // Exit the loop
}
else if(device_paramter.KeyScan == 1)
{
/* Function jump */
break; // Exit the loop
}
}
}
}
To achieve simultaneous display of temperature and humidity, I modified the relevant content in tim.c.
if(htim->Instance == TIM14)
{
if(device_paramter.Dispiay_Type == 1)
{
HAL_TIM_Base_Stop_IT(&htim14);
updata_flag++;
if(updata_flag <= 1000)
{
ShowNum(1,1,(device_paramter.Temp/100));
ShowNum(1,2,(device_paramter.Temp / 10 % 10));
ShowNum(1,3,device_paramter.Temp%10);
ShowNum(2,1,(device_paramter.Humi/100));
ShowNum(2,2,(device_paramter.Humi / 10 % 10));
ShowNum(2,3,device_paramter.Humi%10);
}
else
{
updata_flag = 0;
sleep_flag++;
}
__HAL_TIM_SetCounter(&htim14,0);
if(sleep_flag >= 1)
{
sleep_flag = 0;
SN74HC595_Send_Data(SN_DIG,0xFF);
SN74HC595_Send_Data(SN_LED1,0x00);
SN74HC595_Send_Data(SN_LED2,0x00);
}
else
{
HAL_TIM_Base_Start_IT(&htim14);
}
}
}
During the function jump, relevant code was added to detect the battery voltage, but the effect was not good.
/* ADC voltage acquisition */
HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADC_Start(&hadc1); // Start ADC conversion
HAL_ADC_PollForConversion(&hadc1, 50); // Wait for conversion to complete, 50 is the maximum waiting time in ms
if(HAL_IS_BIT_SET(HAL_ADC_GetState(&hadc1), HAL_ADC_STATE_REG_EOC))
{
ADC_Value = HAL_ADC_GetValue(&hadc1); // Get ADC value
Data = (ADC_Value*3.324f)/4095.0f; // 12-bit ADC, the obtained value is between 0 and 4095, reference voltage 3.3V()
}
ol_Value = (uint16_t)(Data * 100)*2; // Due to the voltage divider using two resistors
device_paramter.Display_Type = 2;
HAL_TIM_Base_Start_IT(&htim14);
device_paramter.KeyScan = 0; // Reset long/short press judgment
device_paramter.sleepStatus = 0; // Clear sleep flag
device_paramter.KeyStatus = KEY_NO_PRESS; // Clear pressed flag
5 BOM List
Name Component
Number Package Quantity Model Brand Number Remarks Price STM32G030K6T6 U1 LQFP-32_L7.0-W7.0-P0.80-LS9.0-BL 1 STM32G030K6T6 ST (STMicroelectronics) C529331 tb 3.2 10K R1,R2,R3,R10,R11 R0603 5 0.01/pcs 0.05 100nF C2,C1,C10,C12,C13,C14 C0603 6 0.01/pcs 0.06 32.768kHz X1 OSC-SMD_L3.2-W1.5 1 SMD31327681252090 JGHC (Jingguanghua) C390740 tb 0.5 12pF C4,C3 C0603 2 0.01/pcs 0.02 SHT40-AD1B-R2 U2 DFN-4_L1.5-W1.5-P0.8-TL-EP 1 SHT40-AD1B-R2 Sensirion (Swiss Sensirion) C2909890 tb 8.6 10uF C5,C6,C11 C0603 3 0.01/pcs 0.03 1K R4,R5,R8,R9 R0603 4 0.01/pcs 0.04 TP4056 U3 ESOP-8_L4.9-W3.9-P1.27-LS6.0-BL-EP 1 TP4056 UMW (Yutai Semiconductor) C725790 lc-GX4056 0.23 LED_0603-R LED1 LED_0603 1 0.05/pcs 0.05 LED_0603-G LED2,LED3,LED4 LED_0603 3 0.05/pcs 0.15 SN74HC595PWR U4,U5,U6 TSSOP-16_L5.0-W4.4-P0.65-LS6.4-BL 3 SN74HC595PWR TI (Texas Instruments) C273642 lc
3.6
1uF
C7,C8,C9
C0603
3
0.01/pcs
0.01
TYPE-603-T3
USB1
USB-C-SMD_TYPE-603-T3
1
TYPE-603-T3
Yuandi
C2689837
lc
0.49
5.1K
R6,R7
R0603
2
0.01/pcs
0.01
RT9013-33GB
U7
SOT-23-5_L3.0-W1.7-P0.95-LS2.8-BL
1
RT9013-33GB
RICHTEK
C47773
lc
0.94
TS-1086E-AC03526
SW1
SW-SMD_TS-1086E-AC03526
1 TS - 1086E
-
AC03526 XL - 5050UWC LED7 LED - ARRAY - SMD_6P - L5.0 -W5.0-TL-RD - 2 1 TS5215A 250gf SHOU HAN (首韩) C388295 lc 0.01 ZX-XH2.54-2PWT CN1 CONN-SMD_2P-P2.54_MEGASTAR_ZX-XH2.54-2PWT 1 ZX-XH2.54-2PWT Megastar (兆星) C7429671 (optional soldering ) 0 PZ254V-11-04P H1,H2 HDR-TH_4P-P2.54-VM 2 PZ254V-11-04P XFCN (兴飞) C2691448 (optional soldering ) 0 250mAh Lithium Battery BAT+ 502030 1 - Attached to PCB 2 Total: 22.25 Note: Since most 0603 resistors and capacitors are from stock or salvaged parts, they are uniformly calculated as 0.01/pcs . Please refer to this BOM. 6. Competition Logo Verification 7. Demo Video : LCSC Electronics Competition: "Desktop Temperature and Humidity Meter" - Functional Demonstration. In closing, this is my third time participating in the training camp. I'm grateful to LCSC for continuously giving me opportunities to improve. The first two times, due to time and ability constraints (in my second year of junior high), I didn't complete it; I couldn't even finish soldering and programming. This time, I finally finished it "independently" during the summer after the high school entrance exam (this independence is in contrast to when I participated in NOC in sixth grade, where the teacher guided me step-by-step). It's a kind of commemoration of the end of junior high school. My own abilities have improved, but my programming skills still need strengthening, hence the imperfect code. This project was originally intended as a desktop decoration, so I added my future aspirations to the back of the board. I hope my high school life will be like that, and I also wish LCSC continued growth and success, hoping for an opportunity to join them in the future! 2024/7/29