toothache

[Training Camp_Advanced Class] Smart Life Kit Based on ESP8266

 
Overview

Smart life kit based on ESP8266+STM32F1

1. Project background

   家里的电器用着真不方便。晚上休息的时候,总是要下床去关灯,尤其在冬天,好不容易焐热了被窝,根本没有下床的欲望,但不关又不行。客厅里的饮水机不光在白天开着,晚上也一直开着,即耗电又耗水。有时候晚上想去关掉它,但总是懒得走而无视它开着的存在。有时候下班回家发现家里的湿度比较高,此时开除湿机好像有点晚了。

2. Project analysis

    我们不想下床去关灯,可以把家里的灯通过WIFI连接网络,通过手机来控制驱动继电器开关,客厅里的饮水机我们也可以连接网络,通过手机APP可以查看饮水机的开关状态,然后动动小手关闭它。可以在家里安装一个温湿度传感器,用来检测家里的湿度环境,通过网络上传到我们的手机,在下班的路上我们就可以看到家里的湿度情况了,然后判断需不需要打开除湿机,回到家后我们就能享受良好的环境了。

3. Product Framework

3.1 Controller (which control chip controls the operating status)

3.2 Networking module (can connect to the Internet)

3.3 Control module (control switch of home appliances)

3.4 Temperature and humidity module (can collect temperature and humidity at home)

3.5 Indication module (can display the operating status of the module)

3.6 Interactive module (users can communicate with the module)

4. Design ideas

4.1 Hardware:

4.1.1 The STM32 microcontroller communicates with the esp8266 module through AT commands and is connected to the Alibaba Cloud Life IoT Platform.

4.1.2 DHT11 collects indoor temperature and transmits it to the living Internet of Things platform.

4.1.3 A relay controls a light bulb at home, and the mobile APP is used to turn the light bulb on and off.

4.1.4 A relay is ready to be connected to a socket to realize the switch of the socket, and then connect the water dispenser at home to the socket and control it through the mobile APP.

4.1.5 OLED displays indoor temperature, humidity and switch status in real time

4.1.6 4 buttons:

1. 控制esp8266智能配网

2. 控制三元组的烧写

3. 控制灯的开关

4. 控制插座的开关

4.1.7 3 LEDs: B1 B10 B11

1. 智能配网: B10和B11同时0.2s闪烁。
2. 烧写三元组:B1和B10同时0.2s闪烁。
3. 设备没有联网状态:B1每隔0.5s闪烁
4. 设备连上网络状态:B1常量
5. 灯亮: B10亮 灯灭: B10灭
6. 插座开: B11亮 插座关: B11灭

4.1.8 W25Q64 stores triplet information.

4.2 Software:

    利用keil5开发。通过mqtt协议和阿里云生活物联网平台通信,通过在物联网平台创建设备,并和实际的设备绑定,可通过手机APP绑定设备,继而控制设备。另创建了web界面,可以在网页查看设备的运行状态和上传的信息。

5. Hardware planning

STM32F103C8T6:

    作为主控芯片,主频高,有很快的速度,实时性更好,有更大的RAM和ROM,片上外设也比较丰富,有多个串口且价格低廉。

ESP8266-01S:

    实现联网功能,登入阿里云平台。是比较常用的WIFI模块,线上资源丰富,便于开发,体积小,功能强大,通过简单的AT指令就可以连接互联网,通过一个串口可以很好的和STM32进行通信。

DHT11 :

    采集温湿度模块,通过编程可采集室内温湿度。超快响应、抗干扰能力强、性价比高,体积小功耗低,操作简单。

0.96-inch OLED:

    显示温湿度和灯泡、插座的状态,观感更强。体积小,显示效果好,显示内容多,IIC通信,通信接口少,通信简单。

Active buzzer:

    可作为配置模块信息的提示,有源蜂鸣器比无源蜂鸣器编程更简单。

Two-way relay:

    连接家用电器的接口,通过小电压设备控制大电压设备。选择5V的继电器,电压使用范围合适。

W25Q64:

    flash存储芯片,可存储设备三元组一些必要的数据,掉电不丢失。

Three programmable LEDs and a power indicator:

    3个可编程LED可以作为调试程序的指示,也可作为esp8266的联网模式和烧写三元组的指示灯。

4 independent buttons:

    独立按键可用于实现智能配网的按键,烧写三元组的按键,控制继电器开关的按键,也可用于调试程序使用。

LDO :

    LDO使用ASM1117-3.3V的芯片,可在低压差稳定输出主控所需的3.3V的电压,即便宜又好用。

Comes with reset button:

    单片机复位按键,在程序编写过程中使用非常方便。

Serial download + ST-LINK download:

    提供两种下载模式,可自由选择,串口下载电路还可以用来传输三元组信息,ST-LINK下载更为方便。

USB interface:

    USB接口采用micro-usb,采用安卓数据线接口,是使用最广的接口之一,不用购买额外的数据线。

ULN2003:

    驱动继电器,一个芯片可以驱动好几路继电器,接线简单,而且非常的便宜。

6. PCB design

Designed PCB:

image.png

Network part: This esp8266 module is produced by Espressif Systems. It is cheap and easy to use. It leads to two IO pins and can be directly developed for secondary development. We use the AT commands of the factory firmware to communicate through the microcontroller to realize the networking function. During the PCB design process, we hollowed out the bottom of the module to ensure the stability of the signal.

image.png

Power supply part: We have added a 5V to 3.3V circuit, which can be powered by 5V and can be directly connected to the computer's USB or 5V power adapter, which is simple and convenient. A self-restoring fuse is added to the power supply to protect the power circuit from being burned.

image.png

Relay drive part: We use the ULN2003 chip driver. This chip is a high-voltage, high-current composite transistor array. It can be directly connected to TTL and CMOS circuits at a working voltage of 5V, and one ULN2003 can directly drive 7 channels. The relay greatly saves the consumption of other components and occupies a relatively small volume in the PCB.

image.png

USB interface: We have dealt with the micro-usb convenience and modified the frame so that the micro-usb directly contacts the frame to ensure that the data cable can be plugged into the micro-usb port during use.

image.png

Copper coating: Regarding the relay, we did not conduct copper coating on it. Considering that it is a strong current part, it is very dangerous. We did not perform copper coating operation to avoid unnecessary danger. The crystal oscillator is not covered with copper to reduce interference.

image.png

OLED: The OLED screen is placed on top of the chip, just covering the main control circuit, which makes the board look more beautiful.

image.png

Layout: Each device is placed according to the position of the corresponding chip pin, avoiding drilling holes for wiring.

image.png

Silk screen: Each device has a corresponding silk screen to facilitate subsequent welding and debugging.

image.png

7. Issues that need to be paid attention to when drawing PCB

7.1 A clear area is required under the WIFI antenna, and slotting is best.

7.2 The strong current part should not be covered with copper. Pay attention to the safe distance between strong current and strong current, strong current and weak current (try to 3mm, and consider digging grooves if it is lower than 2mm).

7.3 The terminal blocks and micro-USB are placed on the edge of the board for easy plug-in. If they are too far inside, it is easy to fail to insert them.

8. Welding

Got the board

image.png

Welded board

image.png

Connect the module board

image.png

Board after running

image.png

Problems encountered during the welding process:

      我一共焊了两块板子,首先在第一块板子焊接的过程中,什么都焊好了,也测试好了,程序也烧录进去了,一切都是那么的完美,但是在一次上电插线的过程中把micro-usb拔掉了。原因是在焊接的过程中没有固定,后面的孔的锡没有和前面的孔连接。我再次焊上去,却怎么也不通电,板子没有电,就很懵,忙活了好久之后,又把micro-usb拆掉才发现问题,原来我在这个口的电源部分打了一个孔,现在这个孔的线和电源部分断开了,没办法,我尝试飞线,但发现好丑,最后无奈把能拆的都拆了又重新焊了一个,就是多费了些功夫。

image.png

    在第二个继电器的部分有一点问题,我在下载程序调试的时候,发现第二个继电器总是不能够控制,第一个和第二个继电器用料,接法一模一样,但第一个可以正常工作。我首先测继电器输出的ULN2003的引脚,发现第二个继电器的ULN2003的控制引脚电压总是低于第一个继电器的ULN2003的控制引脚。我把第一个继电器的控制引脚和第二个继电器的控制引脚短接,发现第二个继电器可以正常工作了。我就想是不是单片机的这个引脚没有焊接好,我又重新涂了一遍锡,发现还是不行,我又在想是不是程序有问题,导致整个引脚没有输出,因为都是继电器,我就在程序里把引脚换了,发现还是不行。好苦恼。最后还是没有找到原因。没得办法,继电器还得工作,因为ULN2003有7路输出,而我只用了三路,我在设计的时候还多引出了一路,正好这个有用了,我就把这个引脚和第二个继电器的引脚连接到了一块,上电,正常了。但是更纳闷为什么另一个引脚不行,可能是我虚焊了吧。

9. Intelligent network distribution method (two configuration modes)

9.1 AP mode:

step:

1.esp8266初始化并进入AP模式,使得手机可以搜索到esp8266模块的热点信息。

2.手机扫描WIFI列表,连接模块热点发送路由器ssid和password(通过UDP)。

3.esp8266解析字符串提取ssid和password,连接路由器。

9.2 SmartConfig mode (the mode we adopt)

这种配网模式需要使用指定的APP软件。

因为我们使用的是乐鑫生产的esp8266-01s,所以我们采用乐鑫自主研发的ESP TOUCH实现智能配网模式。ESP TOUCH 协议采⽤的是 Smart Config(智能配置)技术,帮助⽤户将采⽤ ESP8266EX 和 ESP32 的设备(以下简称“设备”)连接⾄ Wi-Fi ⽹络。⽤户只需在⼿机上进⾏简单操作即可实现智能配置。

1.手机连接家里的路由器,打开ESP TOUCH软件,输入路由器的密码。

image.png

2.esp8266开启混杂模式监听所有的网络数据包(按下设备复位键的同时按下智能配网按键,松开复位键不要松开配网按键,等待LED2和LED5同时闪烁时再松开配网按键)

3.手机通过广播发送ssid和password(点击软件中底下的确认)

image.png

4.此时手机APP出现这个界面,说明正在进行配网,需要我们等待一下。

image.png

5.出现这个界面说明我们配网成功,esp8266已成功连接路由器。

6.并且一次配网终生有效。

10. Creation of Life IoT Platform Equipment

Create Alibaba Cloud device:

1.登录阿里云生活物联网平台。

2.点击创建新项目

image.png

3.输入设备名称,类型选择自有品牌项目。

4.新创建的项目

image.png

5.点击创建新产品

image.png

image.png

Fill in the format as shown above (note that the networking method uses cellular, because Alibaba Cloud does not support esp8266)

6.默认功能:

image.png

7.给我们的插座添加功能(两路开关,一路温湿度)

Click the Add Function button and search for switches in other types (I use the left switch and the right switch as two-way relay switches, which can be freely selected). The adding methods for temperature and humidity are the same. Unnecessary features can be removed. Interface after adding:

image.png

8.在人机交互界面我们选择使用公版APP(有另外的APP的可自主选择)

image.png

Click the product display on the left to change the product icon, product name, and brand. In the device panel we can set the interface of our product’s mobile APP, including layout, etc.

image.png

Save and exit after creation.

9.在设备调试界面选择合宙的2G模块。

image.png

Add a new device to the test device.

10.发布产品,开发完成。

image.png

11. Device binding and triple programming

11.1 Device binding:

Bind actual products to cloud devices. In the code, I designed a triplet interface. Instead of writing the triplet directly into the program, the triplet to be bound to the device can be transmitted through the serial port.

Operating procedures:

1. After creating the device in Alibaba Cloud, it is displayed that the device is not activated. In the device debugging interface

image.png

2. In the function definition interface

image.png

3. We copy the required triplet and identifier information, separated by commas (English commas). Please note: Fill in the format of product number, device name, device key, lamp, socket, temperature, and humidity. a1MFq7NDKJv,Switch,342a55cad323807a1f93bc288ca6d2d5,leftPowerstate,rightPowerstate,temperature,humidity

4. Open the serial port debugging assistant,

image.png

5. Fill in the triplet and identifier information into the sending box, and then open the serial port.

我们复位线下设备,复位的同时按住key1键不松开,此时串口第一行打印W25Q64的ID,后面一直打印接收到的数据,并且此时LED3和LED5同时闪烁,如图所示:

image.png

6. At this time, click the send button on the serial port to transmit the triplet and other information to the device, and then the serial port will print out the triplet and other information.

image.png

7. The microcontroller will process the data after receiving it. We don’t need to worry about it. The device binding is now complete. After sending data once, the data is saved in flash and will be read automatically the next time it is powered on. Refresh the Life IoT platform and you can see that the device is online.

image.png

8. Click on the running status and find that the device is already working (data has been uploaded).

image.png

11.2 Mobile APP binding:

1. On the human-computer interaction interface of the Internet of Things platform, click Distribution Network + APP Download QR Code

image.png

2. Fill in the name of the device to be bound, mine is Switch, and click to generate a QR code. Open the mobile cloud intelligence APP: click the + sign in the upper right corner to start scanning the QR code.

image.png

3. The device is bound successfully. Click on the homepage

image.png

正是我们创建的界面。

11.3 Web interface creation

1. Enter the Alibaba Cloud official website, click on the console, select the IoT platform, and click on loT Studio.

image.png

2. Create a new application and create a new project.

image.png

3. Associate products and devices, and then edit the web interface. Just edit the interface and publish it.

image.png

12. Functional testing

The functional test part will be placed in the attachment below in the form of a video.

13. Project progress

1. Complete the hardware selection and PCB drawing from August 7th to August 8th.

2. On August 10th, the wiring of the relay part of the circuit diagram was changed. The PCB line width was widened, and there was no copper pouring underneath.

3. Place the order on August 11th and wait for delivery. Start using the development board to build a circuit and write code.

4. Successfully connected to Alibaba Cloud on August 12th and implemented the transplantation of basic code.

5. The collection and upload of temperature and humidity were completed on August 13th.

6. On August 14th, a serial port programming triplet program was added. Completed the flashing of the LED lights' programming triplet, the flashing of the smart distribution network, and the flashing of the network connection. Also improved some function descriptions.

7. The board arrived on the afternoon of August 15th and we started welding.

8. On August 16, the welding and debugging of the board, as well as the shooting of some videos and project descriptions were completed.

9. All videos will be shot and uploaded at 9 pm on August 16th, and the project will be completed.

14. Plan improvement

1. The buzzer is useless on the entire board. The LED completely replaces the prompt function. If you add a sound, it is completely redundant, and the buzzer is too large.

2. The board is designed to be relatively large. Replacing the buttons with small buttons can save a lot of space.

3. Components can be placed on both sides, and W25Q64 and ULN2003 can be placed on the back to further save space.

4. Replacing LED with EGB can also save space.

5. The st_link download interface is completely unnecessary, and the serial port download method is used. If it is made into a product, the serial port is not necessary, and two vias are directly led out for downloading the program.

6. Integrate dht1, esp8266, and oled all on the board instead of using modules.

7. Add the crust.

15. Experience

1. When drawing the board, you must understand the functions and principles of each device and use devices you are familiar with, otherwise it will be a headache when debugging.

2. Do not cover the strong current parts with copper. Pay attention to the safety distance between strong current and strong current, strong and weak current.

3. When welding, be careful not to solder the solder joints. The micro-usb must be fixed. If there is no hole underneath the micro-usb, do not drill it.

4. Don’t buy components just for the sake of cheapness. Some merchants sell defective products. Once you get them, it is not only a waste of money, but also energy. The most fatal thing is during debugging. I recommend Lichuang Mall, and you can use it with confidence.

5. Through this activity, I learned a lot from Song Gong and understood every step of a product from design to production. What I learned here is not only knowledge, but also an ability. Here, I would like to thank Song Gong for his explanation, thank Mo Gong, Zhou Gong and the friends in the group for answering questions, and thank Lichuang EDA for its support.

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-05-21 11:42:30
  • [Synopsys IP Resources] Effectively protect data in PCIe and CXL in cloud computing
  • Database under WinCE
  • Advertising lights (using the meter-taking method)
  • CYPRESS
  • STLINK connection error problem
  • Recruiting part-time DSP and other related professional lecturers or technical support personnel

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号