石榴姐

[Tuya Smart] Intelligent dehumidification industrial controller based on Arduino-582526A

 
Overview

d=====( ̄▽ ̄*)b

First of all, the front row thanks the sponsor for providing this learning opportunity and learning platform.

1. Design overview

1. If the humidity is too high, dehumidification will be automatically turned on. Suitable for large dehumidifiers in large skating rinks, northern bathhouses, family bathrooms, bathroom heaters, etc. (The company previously had a project to develop a control system for a large dehumidifier manufacturer). In the same way, it can be used for humidification function. Solve the problem of equipment networking in large industrial control industries. Tuya platform MCU product development

2. This solution is based on Arduino-UNO, with low development threshold and easy program burning. mcu.png 3. The power supply part uses an AC-DC module to obtain 5V power supply to the MCU, and then obtains 3.3V power supply to the Wifi module through AMS1117-33. power.png

4. There have always been too many devices to consider in the peripheral circuit of the relay. Here we chose a NUD3105, which integrates many peripherals and can directly control the relay. There is no need to consider the reverse induction of the relay, pull-up (pull-down, current limiting). Resistors, etc. can be said to be very convenient. (Experience gained from the last training camp)


relay.png

5. The Wifi module uses Tuya's WB3S (universal firmware version), with 3.3V power supply and serial port communication. The communication is very convenient. The peripheral circuit only requires power supply + voltage stabilizing capacitor, which is not too simple.

Post the specification link: Tuya Wi-Fi+BLE dual protocol module WB3S specification , the circuit is as follows:

wifi.png

The development materials are the most detailed of any platform I have ever used. Even key types such as PID have been written into case codes. You can call them perfectly by just adding your own MCU function code, as shown below:


Information.png

6. Level conversion: Since the IO of the Arduino-UNO platform is 5V, and the Wifi module is 3.3V (as shown below)

IO port level.png

Arduino-UNO must undergo level conversion when communicating with Wifi. As shown below: Level conversion.png

2. A few things about the male mold housing and PCB

1. Before designing a board, it is best to find a suitable shell first, and design the PCB according to the size of the shell, so that it can be installed well later. If it is just a development version or experimental version, please feel free to do so. 2. The company happens to have this shell, and the male model is easier to buy. I picked one up and measured the size. Make PCB designs. (In order to avoid the failure of the Taobao store link, I will not put the link here. You can search for "temperature and humidity shell" on Taobao, sort by low to high price, and you will find the exact same shell after a few searches)

size.png According to the searched size, plan the frame and screw holes, and then lock them

Draw the border.png

3. The shell I chose is a bit too small, so it’s not easy to put it in. I guess I can’t put it down on one side. Can’t fit on the top layer.png

4. I had to put it on the back, and put the shorter components on the bottom layer. I stayed up until early in the morning and finished it.

Floor plan.jpg

5. Some precautions (1) A relatively thick line width of 2mm is used in the high current area and converted into a pad. Later, you can solder more tin to thicken the copper foil and increase the power. conversion pad.png

(2) Copper cannot be laid in areas with strong electricity. This is because it is very dangerous to prevent strong electricity from creeping into the internal microcircuit. You can use the solid fill tool and set it to no fill in the property bar after drawing the area. Set as follows: No padding.pngNo copper for strong electricity.png

(3) The temperature and humidity sensor should be placed as close to the side as possible, and a tiny fan can be added if conditions permit. The sensor should be kept away from internal heating components (such as power chips, power modules, buck chips, etc.). The case is placed in the top corner. Temperature and humidity sensor location.png

3. Welding finished product

1. There are various methods. Currently, the author uses "teppanyaki". First, apply solder paste, stick it on, and then heat it with a "whirter".

2. After completion, do not weld the AC-DC module and relay first (it will be inconvenient for debugging if they are welded), and then add them after debugging is completed. ~~~~ Note: First check whether VCC (5V3.3VUSB) and GND are short-circuited, and make sure before plugging in. Do not plug in if there is a short circuit.

SMD welding.png

4. Software code part

1. Open the downloaded MCU_SDK file and put it in a folder. After ".c" is changed to ".cpp", the IDE can be opened. For details, please refer to the MCU SDK porting tutorial provided by Tuya Platform.

2. In short, you need to read more documents. Everyone's PID, function, etc. of this code are different. I have pasted the main program code of Arduino. If your function is the same as mine, you can download the code and modify it. PID and other places. Of course, if the functions are different, you can only modify them yourself.

#include "wifi.h"
#include "Adafruit_SHT31.h"
#include 
#include 
#include 
SoftwareSerial mySerial(5, 6); // RX, TX
#define _SS_MAX_RX_BUFF 300
#define relay 10
Adafruit_SHT31 sht31 = Adafruit_SHT31();
int time_cnt = 0, cnt = 0, init_flag = 0;
int TEM, HUM, TEM_Past, HUM_Past;
union data
{
  int a;
  byte b[4];
};
data HUMUPPR;
data HUMLOWER;
void setup() {
  pinMode(relay, OUTPUT);   // 继电器I/O初始化
  digitalWrite(relay, LOW);
  pinMode(3, INPUT_PULLUP);     // 重置Wi-Fi按键初始化
  pinMode(13, OUTPUT);       // Wi-Fi状态指示灯初始化
  mySerial.begin(9600);     // 软件串口初始化
  //mySerial.println("myserial init successful!");
  Serial.begin(9600);     // PA3 RX   PA2 TX
  Serial.println("serial init successful!");
  sht31.begin(0x44);//SHT地址0x44
  wifi_protocol_init();
  for (int n = 0; n < 4; n++) //湿度上限读取
    HUMUPPR.b[n] = EEPROM.read(n);
  for (int n = 0; n < 4; n++)//湿度下限读取,下限起始地址在4
    HUMLOWER.b[n] = EEPROM.read(n + 4);
}
void loop() {
  if (init_flag == 0) {
    time_cnt++;
    if (time_cnt % 6000 == 0) {
      time_cnt = 0;
      cnt ++;
    }
    wifi_stat_led(&cnt);   // Wi-Fi状态处理
  }
  wifi_uart_service();
  myserialEvent();      // 串口接收处理
  key_scan();           // 重置配网按键检测
  aotocontrol();        //自动控制
}
/***********完整代码详见附件*******************/

3. Since the upper and lower limits of humidity of the device are alarm values, the initial value cannot be defined in the program, otherwise the set value will be lost once the power is adjusted and restarted. The method I use here is to store the set threshold in the ROM of the microcontroller (Arduino EEPROM), so that it is read once when the process arrives and written when the setting value is issued. In this way, the data will not be lost even if the power is turned off~~~~

union data
{
  int a;
  byte b[4];
};
data HUMUPPR;
data HUMLOWER;
for (int n = 0; n < 4; n++) //湿度上限读取EEPROM
    HUMUPPR.b[n] = EEPROM.read(n);
  for (int n = 0; n < 4; n++)//湿度下限读取EEPROM,下限起始地址在4
    HUMLOWER.b[n] = EEPROM.read(n + 4);
union data
{
  int a;
  byte b[4];
};
data HUMUPPR;
data HUMLOWER;
/**********放置到上限值设置函数dp_download_maxhum_set_handle中*******/
HUMUPPR.a = (int)maxhum_set;
  for (int n = 0; n < 4; n++)//写入湿度上限到EEPROM,上限起始地址是0
    EEPROM.write(n, HUMUPPR.b[n]);
/**********放置到下限值设置函数dp_download_minihum_set_handle中*******/
HUMLOWER.a = (int)minihum_set;
 for (int n = 0; n < 4; n++)
    EEPROM.write(n+4, HUMLOWER.b[n]);//写入湿度下限到EEPROM,下限起始地址是4

Guide to avoid pitfalls:

(1) Humidity threshold lost during power outage:

Be sure to use ROM to take over the setting values, so that they can be saved when the power is turned off; the program I wrote before has been forgotten for a long time, and the previously set values ​​will be lost when the power is turned off.

(2) Always unable to enter network distribution mode:

The underlying library of SHT has a 500ms delay. When calling read in the loop, I actually measured that it takes 7 seconds to return the heartbeat to the wifi module. I still cannot connect to the Internet and cannot enter the network configuration mode. Then I changed the underlying delay. The problem That’s it; (There may be other solutions, I haven’t found them yet)

boolean Adafruit_SHT31::readTempHum(void) {
  uint8_t readbuffer[6];

  writeCommand(SHT31_MEAS_HIGHREP);

  delay(500);/**********我把这里改成了100*************/
  Wire.requestFrom(_i2caddr, (uint8_t)6);
  if (Wire.available() != 6) 
    return false;
  for (uint8_t i=0; i<6; i++) {
    readbuffer[i] = Wire.read();
  //  Serial.print("0x"); Serial.println(readbuffer[i], HEX);
  }
(3) Try not to route wires under the Wif module:

Tuya's engineers said before that it is best not to route wires under the wifi module. My version 1.1 is gone, so I drew a 1.2 PCB (I was anxious and already printed a 1.1 board in advance), but judging from the current tests, V1.1 has already It was a success . So friends can choose by themselves.

(4) The relay is a bit high:

I didn't pay attention to the size when choosing the relay. I forgot to calculate the thickness of the board. It was a bit high, about 1mm over, and the lid couldn't be closed. Fortunately, I cleverly used hot melt glue to stick them together.

(5) For learning reference only: ~~~~

There are risks in completely copying. If the code, wiring, layout, etc. are cheated, don’t blame UP. You bear the consequences at your own risk.

The joy of success (actual test demonstration):

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-24 02:42:55

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号