sigma

[Tuya Smart] Guitar temperature and humidity sensor based on Tuya Smart

 
Overview

1. Project introduction:

    This design project is used for the project work of the Internet of Things winter vacation training camp activity jointly carried out by Lichuang EDA and Tuya Smart Platform. The theme is indoor temperature and humidity sensor based on Tuya Smart IoT module + MCU control.

The WiFi IoT module designed     for this circuit selects the WBR3 module under the Tuya Smart Platform , and the MCU main control chip selects ATmega328PB-AU (note B) . The indoor temperature and humidity sensor uses the high-precision digital temperature and humidity sensor SHT30-DIS , which supports Micro 5P [5V] power supply and lithium battery [3.7V] power supply. It is designed to automatically switch power supply, lithium battery charging and lithium battery power . display and other functions . The circuit schematic drawing and PCB design were both done using the Lichuang EDA client; the casing was designed using SolidWorks 2020, and its manufacturing process was made using 3D printing technology, and the material was PLA.

The IoT temperature and humidity sensor of this project can collect and process     indoor temperature and humidity data in real time . Through intelligent distribution of WBR3, it can be viewed through the Tuya APP on the mobile phone. At the same time, the temperature and humidity data can also be viewed through the 0.96-inch 4-pin OLED screen. real-time display. The collected indoor temperature and humidity change data can be stored in the cloud and displayed on the APP in the form of a line chart . At the same time, the main control chip leads to four pins and is connected to four LEDs of red, green, blue and orange , which can be customized . Develop temperature and humidity alarm mechanisms , network distribution mode instructions , etc.

 

2. Function introduction:

  •     1. The IoT WiFi module WBR3 is developed based on the Tuya Smart platform, and data can be remotely monitored and viewed through the Tuya Smart App;

  •     2. Configure SHT30 high-precision digital temperature and humidity sensor to collect indoor temperature and humidity data;

  •     3. The 0.96-inch 4-pin OLED screen displays temperature and humidity data in real time and refreshes every 20 seconds ;    

  •     4. It has WiFi intelligent distribution network function and can be controlled wirelessly when connected to the Internet;

  •     5. Supports Micro 5P 5V power supply and lithium battery 3.7V power supply;

  •     6. The power supply circuit can automatically switch and can terminate the power supply of the lithium battery when powered by 5V;

  •     7. Lithium battery power display function, indicating the remaining power of the lithium battery;

  •     8. Micro 5V can charge lithium batteries when powered ; 

  •  9. Lead out the ISP programming port to facilitate the programming adjustment of the bootloader ;

  •  10. The MCU leads to 4 pins, which can control LED indicators of 4 colors : red, green, blue, and orange.

 

3.Design features:

  1.    The PCB area (7.6cm×5.4cm) is limited to 10cm×10cm, and the boarding cost is low;
  2.    Supports power supply in two modes: 3.7V lithium battery and 5V type-C interface, with power display and charging functions;
  3.    Supports wireless data acquisition via WiFi, anytime and anywhere;
  4.    Small size, light weight, compact structure and low production cost;
  5.    Simple appearance, stable operation and cool effects.

 

4. Component selection:

  •     1. The IoT module uses Tuya Smart ’s low-power embedded WBR3 module, which supports wireless communication methods such as WIFI and Bluetooth ;

  •     2. MCU chooses ATmega328PB-AU . Compared with ATmega328P , it has new multi-group iic , spi , and uart hardware communication serial ports , which are more powerful and supports Arduino programming. It also supports changing to ATmega328P; (the pin functions are the same)

( You need to download and configure the corresponding MiniCore development board library from Github : Add the development board management URL in the preferences of Arduino IDE: https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json ,

  Search for MiniCore download in development board management. )

  •     3.5V供电口选用micro 5P接口,与安卓接口的手机数据线通用,使用方便;

  •     4.温湿度传感器选择SHT30,测量精度高,反应灵敏,功耗低,价格合适

  •     5.LED、电容、电阻均选择0603封装节省空间,又锻炼焊接技巧

  •     6.锂电池充电模块选择TP4095,使用方便,充电电流稳定,搭配LED指示效果强;

  •     7.电量显示模块选择HM1160,成本低廉,原理易懂节省设计内容,效果稳定,功耗低,不过要去淘宝采购

  •     8.显示屏选择0.96寸4针OLED-黄蓝屏采用I2C通讯,成本低廉,显示效果稳定功耗低

  •    9.USB转TTL电路选择CH340C管理成本低,效果稳定,原理易懂,常用选择;

  •  10.选择PS7516作为3.7V转5V升压电路的DC-DC管理芯片,升压效率高,升压效果棒。

 

5.APP界面:


配网步骤:

  • (1)打开PCB板上的总开关;
  • (2)打开手机端的涂鸦APP;
  • (3)使设备与手机连接在同一WIFI下;
  • (4)点击涂鸦APP右上角添加设备;
  • (5)点击自动搜搜,等待配网成功。
  • 注:如果自动搜索超时,可以选择手动搜索。

 

Tuya模组调试成功截图:

  • MCU模拟:

  • 模组模拟:

 

6.程序设计:

GitHub地址:https://github.com/BlackRain543/Indoor-temperature-and-humidity-sensor.git

 

1.所使用的Arduino库文件:

#include <U8g2lib.h>                       //OLED驱动

#include <ClosedCube_SHT31D.h> //SHT30驱动

#include <SoftwareSerial.h>           //通信串口设置

 

  • U8G2为节省RAM消耗,采用2页缓存,每10s更新一次数据,同时自定义制作了简单的中文字库;
  • ClosedCube_SHT31D库读取SHT30传感器所采集到的温度和湿度数据;
  • SoftwareSerial库实现MCU与涂鸦模块的串口通信。

 

2.LED指示设置:(蓝,绿LED指示湿度,红、橙LED指示温度)

  •   温度<25℃时,          红LED灭,橙LED亮;
  •   25℃<温度<30℃时,红LED亮,红LED灭;
  •   温度>30℃时,          红LED亮,橙LED亮。
  •  
  •   湿度<60%时,          蓝LED灭,绿LED亮;
  •   60%<湿度<75%时, 蓝LED亮,绿LED灭;
  •   湿度>75%时,          蓝LED亮,绿LED亮。

 

7.外壳设计:

SolidWorks建模,Keyshot 9渲染。】

外壳设计思路:

  1.   建模思路依据3D打印制造工艺,无需支撑,保证了壳体表面的光滑度,结构强度与制造的流畅性,外壳整体四周多处采用镂空结构,增强了外壳的散热能力与通风能力,优化了LED灯的指示效果。
  2.  外壳的主要镂空图形采用六边蜂窝,简约的同时增强科技感。
  3.  对开关,tuya联网模块天线,Micro接口等外露处切出空间以方便调试,温湿度传感器处所对应的壳体位置周围镂空以增加气流通畅性,保证所采集数据的稳定性、实效性与可信度。

 

3D打印参数(总共4件):层高0.15mm,填充(15%),无需支撑。

 

 

8.成品展示:

 

9.设计心得:

        经过本次的物联网训练营基于MCU方案的PCB项目设计,学习到了许多与实际设计PCB中相关的新知识,例如锂电池的电量检测,锂电池的充电电路,ATmega328p基于供电电压对晶振的选择等,同时进一步熟悉了立创EDA的操作,了解到了更多关于PCB器件布局,布线的设计细节。

本次设计在电源管理方面进行了较多尝试,初次尝试了设计与MCU相关的电路。在起初设计过程中,跟着训练营的课程与去开源广场的参考并未感觉到有多少困难,但是当收到PCB板并焊接完成后上电的那一刻才发现到了第一次崩盘:无法烧录bootloader引导程序。毕竟Arduino开发与STM32相比更简单是因为IDE里有很多铺垫,但当自己铺不上的时候就倍感难顶。而且由于本人工具缺少难以拆焊,飞线本领也不到家,所以本人当即修改引出烧录口后与调整下载电路后进行了第二次打板,毕竟新年将至时间不多了。

然而第二次打板后的硬件调试过程依旧阻碍重重。。。

  • [1] Since the working voltage of the tuya module is 3.3V, and the lithium battery power supply voltage is generally above 3.7V, Atmega328PB can only use 3.3V for power supply, so you can only choose an 8MHz passive external crystal oscillator. It is precisely because of this that many problems arise in bootloader programming. First of all, the signatures recognized by ATmega328PB and ATmega328P are different. After some online searches, I went into the .conf file and modified the signature to successfully burn the boot program. Then due to the problem of the 8MHz crystal oscillator, the actual delay (1000) in the program changed from 1s to 2s. When the baud rate of the serial port was set to 19200, the actual baud rate was 9600. So the problem is that the Arduino IDE cannot directly access the CH340C programming program through the Micro port, and the error always indicates a timeout. However, the final temporary solution was to use another Arduino UNO as an ISP downloader and program it. This was the first difficult point that I struggled with for a long time.
  • [2] In the process of developing the program, it was normal at first, the OLED display refreshed smoothly, and the SHT30 could also read data. However, after leaving it for a night, the data of SHT30 could not be read normally, and after checking, it was found that the error code -101 was returned. Finally, I searched the library file and found that the -101 error corresponds to the CRC check error. What is CRC? I went directly to the learning website Station B and started learning. After understanding the principle of CRC, you can narrow down the problem area to software. I tried several more libraries related to SHT30. In the end, the problem was solved by modifications in the program (although the original library was still used). This is the second difficult point that I have struggled with for a long time.
  • [3] The subsequent development finally went smoothly, but I soon stumbled again: the dynamic memory occupied 99% (`゚Д゚´). This is more troublesome. After all, it is a pleasure to adjust the library and it will overflow the crematorium. Therefore, through constant annotation and compilation, I finally positioned the U8G2 library as occupying the most. At first, I suspected a problem with the imported font library, so I went to the learning website B to learn how to customize the u8g2 font library. Although it was somewhat empty later, when tuya's SDK transplants came one after another, it was almost full again. Later, I went to CSDN to study the U8G2 library from beginning to end and found that it turned out that I made too many page cache calls. In fact, the cache of one or two pages on the screen was enough. I accidentally set it to the maximum page cache, so don't The refresh rate is quite high, but the price is quite high. After slight changes, the dynamic memory usage only accounts for 51%, which is much more comfortable.
  • [4] However, the transplantation of SDK is a big trouble for a novice like me who is trying it for the first time. [It turned out that I didn’t even know what an SDK was] Tuya gave me a lot of files, so I didn’t know which one to read first. After flipping through protocol.c, I found some step instructions. But when performing the library adjustment operation as usual, a bunch of strange things were reported. After searching, it was inferred that the .c file was difficult to compile on the Arduino IDE. Fortunately, the relationship between C language and C++ More recently, it can run normally after changing the suffix to .cpp.
  • [5] The code was debugged, but then I discovered that the tuya module did not give me any response. After calling several judgment functions, I found that failed, unknown, etc. were everywhere. Could it be broken? It was really broken. Later, when I asked in the group, I found out that this module is dead when the 5V voltage is applied. However, the 3.3V pin of my UNO's ISP is broken, and I have always used 5V to download the program.
  • [6] Fortunately, the quality of tuya's modules is excellent, and 5V is no big problem. The subsequent network distribution debugging was completed relatively smoothly through tuya's debugging assistant. Since I only have a mobile phone at the moment, the network configuration process is written in "Part 5". The network configuration steps on the tuya platform are still very simple, if the SDK is transplanted and debugged.
  • [7] When using a separate lithium battery for power supply, there will be a problem of insufficient power supply voltage for the tuya module. After 4V is stabilized by AMS1117, the voltage is only about 2.3V. It seems that the third time the board is built, it cannot avoid  ̄□ ̄||.

 

       After this Lichuang Tuya IoT training camp, I feel that I have really learned a lot, because if I don’t learn so many things, I wouldn’t be able to get to this point, haha, haha. The production of this project took a total of three layouts (three colors were changed hehe). The changes made when each stuck difficulty point is finally solved are basically not many places. The reason why it is time-consuming is that you have to screen all the possible problems and continue to narrow down the scope of the bug before you can basically determine it. What exactly went wrong. Although Ardunio is easy to use in daily life, it is actually not simple to build from the hardware and bottom level. The reason why it is convenient in many places is that many pioneers have already paved the way. I hope that I can become more proficient in subsequent MCU development projects.

[But if I develop an MCU next time, I decide to choose STM32.ヾ(・ω・`。) ]

Lichuang EDA platform and Tuya Smart provide developers with a good display and communication platform. What I especially like are the weird and innovative PCB designs on the Open Source Square. Many of them I want to make and play with. Tuya Intelligence also provides developers with a good communication platform, paving the way for developers to develop a very complete basic platform and creating a good ecosystem in terms of Internet of Things development. During this period of time, a series of training camp live broadcasts and exchanges filled the gap between my circuit PCB design bridge between modeling and programming, thinking that I would also work hard to become a person who can provide many complete and excellent open source tools. The developer of the project. I am very grateful to Lichuang EDA and Tuya Smart for providing a good training opportunity.

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-07 22:31:30
  • MSP430F5529 MCU FLASH related issues
  • Encoder fixed length problem
  • My one year acquaintance with EE——huaiqiao
  • Routine enet_io
  • Beijing listed communication group company recruits: DSP (2 algorithm drivers)
  • A question about sensor knowledge, urgent!!!

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号