太白金星

[Internet of Things Course Design] Potted Plant Hosting Terminal Based on ESP32

 
Overview

Demo video HD link: https://www.bilibili.com/video/BV17Y4y1x7cN

Code: https://github.com/breakfast759/ESP32_iot_plants.git

(I’m not very good at using github)

Hardware parts

1 power module

1.1 Brief description of requirements

First of all, in the project concept, the potted plants in the project are placed in a semi-open environment such as a balcony, which requires the power module to be able to stably power the system in a changing external environment. Secondly, when the project members tested in the laboratory environment, they found that Under the condition of 5V power supply, when all the equipment in the system is turned on, that is, when the water pump (about 400mA), fill light (about 800mA), and motor (about 300mA) are fully turned on, the operating current of the system is about 1.6A, and the external equipment When all are turned off, the operating current is about 130mA, which requires the power module to provide stable power supply to the system when the load changes drastically. Finally, the project plans to use WiFi for communication. This communication method is susceptible to interference. In order to improve the signal transmission quality, every effort should be made. It is possible to avoid interference introduced by the power supply as much as possible, which requires the ripple of the power supply to be as small as possible and the output to be as stable as possible.

To sum up, when designing a power module, stability will be the first factor.

1.2 Scheme comparison

Solution 1 18650 battery pack power supply

        Using 18650 lithium battery for power supply is a common power supply solution for electronic equipment. Common 18650 battery capacities are 2200mAh, 2600mAh, 3400mAh, 5500mAh, 7400mAh, 9250mAh and 12580mAh. The discharge capacity of one 18650 battery is generally 3C (about 10A). Under normal working conditions, its output voltage changes between 3.7V and 4.2V with the amount of electricity. Figure 1 shows the Panasonic NCR18650B lithium battery.

18650

Figure 1 Panasonic NCR18650B lithium battery

Advantages: economical, convenient to purchase

Disadvantages: There are major safety risks in the face of changing external environments; the cost of stably powering the system for a long time is high

Solution 2: Switching power supply

        Switching power supply is a high-efficiency, small-volume, and high-precision power supply method that is widely used in industrial fields and various electronic equipment. According to project needs, switching power supplies with different output voltages and output powers can be flexibly selected. Figure 2 shows the Taiwan MEAN WELL RS-15-5 switching power supply.

Taiwan MEAN WELL 5V3A switching power supply

Figure 2 Taiwan MEAN WELL RS-15-5 switching power supply

Advantages: high efficiency, no-load consumption <0.5W; long life; high reliability, overvoltage/short circuit/overpower protection; connected to the mains, it can stably power the system for a long time

Disadvantages: higher price

        When the system is working normally, multiple 18650 batteries are needed to ensure that it can work for a long time. However, charging and discharging multiple 18650 batteries requires complex peripheral circuits for protection and coordination, and the project products will work in a semi-open-air environment for a long time, which poses a high test to the life and stability of the 18650 battery pack.

For safety and economic reasons, the project team selected Taiwan's MEAN WELL 5V3A RS series switching power supply to power the system. High-power circuits based on high-power equipment are directly powered by switching power supplies. The weak current part and the strong current part are isolated by relays to prevent interference. The 5V switching power supply supplies power to the weak current circuit with MCU as the main body through the AMS1117-3.3 voltage stabilizing circuit.

1.3 Final design

        The final power module design block diagram is shown in Figure 3.

Power module block diagram

Figure 3 Power module design block diagram

2 Measurement module

2.1 Brief description of requirements

        The measurement module mainly includes 4 parts: illumination measurement part, ambient temperature and humidity measurement part, soil moisture measurement part and water tank water level measurement part.

        The collected illumination information needs to provide criteria for whether to turn on the fill light. The fill light cannot replace sunlight, but can only play the role of "icing on the cake". Therefore, there are no special requirements for accuracy, range and sensitivity of illumination information.

        The collected ambient temperature information needs to provide criteria for turning on the motor. The growth of plants is relatively sensitive to temperature, so it requires a certain degree of accuracy and sensitivity. Considering that the project products mainly work in a general environment, the temperature range is required to be -20℃~+50℃.

       The collected soil moisture information needs to provide criteria for whether to turn on the water pump. The growth of plants is sensitive to soil moisture, so it requires a certain degree of accuracy and sensitivity; there are no special requirements for the measuring range.

       The collected water level information is used to trigger a water tank water shortage alarm. As long as the indicator light lights up when the water level is lower than a certain level, there are no special requirements for accuracy, range and sensitivity of water level information.

2.2 Scheme comparison

2.2.1 Illuminance measurement part

Solution 1 GY302 module

       The GY302 module is composed of BH1750FVI chip and peripheral circuits. The main BH1750FVI chip integrates photodiodes, operational amplifiers , ADC acquisition, crystal oscillators, etc. The photodiode converts the input optical signal into an electrical signal through the photovoltaic effect. After amplification by the operational amplifier circuit, the voltage is collected by the ADC. The voltage is processed by the logic circuit and converted into a 16-bit binary number and stored in the register. The GY302 module leads to the clock line and data line of the BH1750FVI. The MCU can communicate with the GY302 module through the IIC protocol to configure the working mode of the BH1750FVI or read out the illumination data.

GY302 module

Figure 4 GY302 module

Advantages: direct digital output, omitting complex calculations, omitting calibration, easy to use; does not distinguish between ambient light sources, spectroscopic characteristics close to visual sensitivity, and can perform high-precision measurements of 1lux on a wide range of two teams

Disadvantages: higher price

Solution 2 OPT101 module

       The OPT101 module consists of the OPT101 chip and peripheral circuits. OPT101 is a monolithic photodiode and single-supply transimpedance amplifier produced by TI. The chip integrates a photodiode and a specially optimized operational amplifier.

OPT101 module

Figure 5 OPT101 module

Advantages: wide spectral response range (300nm~1000nm); high sensitivity (0.45A/W at 650nm); low power consumption (quiescent current 120uA)

Disadvantages: Inconvenient to use, analog output requires peripheral circuit processing and ADC sampling; larger size; higher price

Solution three photoresistor

The optical signal is converted into an electrical signal through a photoresistor and a simple peripheral circuit, which is collected through the ADC of the MCU, and the data is processed through an algorithm. Figure 6 shows the photoresistor.

Photoresistance

Figure 6 Photoresistor

Advantages: low cost; high reliability

Disadvantages: poor accuracy and sensitivity; need to design your own algorithm for data processing and calibration, difficult to quantitatively process

        Since the illumination measurement part does not have special requirements for accuracy, sensitivity and range, the most economical option three is adopted.

2.2.2 Environmental temperature and humidity measurement part

Solution 1 triode temperature measurement

        Transistor temperature measurement mainly uses the characteristics of the PN junction voltage of the transistor that changes with temperature changes. The PN junction of the emitter-base of the transistor is used to convert the temperature signal into an electrical signal. After passing through the bridge conversion circuit and the differential amplifier circuit, it is transmitted by the MCU. ADC is used for acquisition and data processing is performed through algorithms. Figure 7 shows the structure of a common triode temperature measurement circuit.

Common triode temperature measurement circuit structure block diagram

Figure 7 Common triode temperature measurement circuit structure block diagram

Advantages: low cost

Disadvantages: complex to use, requiring the design of complex peripheral circuits and algorithms

Solution 2 DHT11 module

        DHT11 is an integrated humidity and temperature digital sensor produced by Guangzhou Aosong Co., Ltd. The sensor includes a resistive moisture measuring element and an NTC temperature measuring element. The MCU can collect environmental humidity and temperature in real time through one data line. Figure 8 shows the DHT11 temperature and humidity measurement module.

DHT11

Figure 8 DHT11 temperature and humidity measurement module

Advantages: practical and convenient; low cost

Disadvantages: long sampling period and low sensitivity

       Since the environmental temperature and humidity measurement part has high requirements for accuracy and low requirements for sensitivity, option three is selected.

2.2.3 Soil moisture measurement part

Solution 1 Resistive soil moisture sensor module

The resistive soil moisture sensor module consists of a resistive soil moisture sensor and a voltage comparison circuit. The appearance of the resistive soil moisture sensor module is shown in Figure 10.

Resistive Soil Moisture Sensor

图9 电阻式土壤湿度传感器模块

优点:价格低廉;精度较低

缺点:传感器电极直接与土壤接触,易被腐蚀

方案二 电容式土壤湿度传感器模块

       电容式土壤湿度传感器模块由电容式土壤湿度传感器和电压放大电路组成。电容式土壤湿度传感器模块外观如图10所示。

Capacitive Soil Moisture Sensor

图10 电容式土壤湿度传感器模块

优点:传感器电路部分不与土壤接触,寿命较长;可靠性高;精度较高

缺点:价格较高

       由于土壤湿度测量部分对精度和灵敏度要求高,故选用方案二。

2.2.4 水箱水位测量部分

方案一 电阻式液位传感器

       电阻式土壤湿度传感器模块由电阻式土壤湿度传感器和电压放大电路组成。通过一系列暴露的平行导线线迹测量液位。电阻式液位传感器模块外观如图11所示。

Resistive level sensor

图11 电阻式液位传感器

优点:价格低廉

缺点:易受温度影响,可靠性差;灵敏度由暴露平行导线线迹的密度决定,灵敏度较差;直接与液体接触,寿命较短;体积较大

方案二 HY-SRF05超声波测距模块

       HC-SRF05超声波测距模块可提供2cm~400cm的非接触式距离感测功能,测距精度可达高到3mm;模块包括超声波发射器、接收器与控制电路。通过读取距离液面的距离信息即可推算出液位高度。HC-SRF05超声波测距模块外观如图12所示。

HY-SRF05 ultrasonic ranging module

图12 HY-SRF05超声波测距模块

优点:不直接接触液体,寿命长

缺点:精度较差;需要MCU进行较多的数据处理,使用复杂

方案三 电容式柔性非接触式液位传感器

       电容式柔性非接触式液位传感器是一种可以直接粘贴在容器表面进行非接触测量的新型液位传感器。电容式柔性非接触式液位传感器外观如图13所示。

Contactless flexible liquid level sensor

图13 电容式柔性非接触式液位传感器

优点:使用场景广泛;使用方便;功耗极低(5V供电情况下典型工作电流291μA);精度较高(±1.5mm);不直接接触液体,寿命长

缺点:价格较贵

       水位测量部分没有对精度、灵敏度和量程提出特别要求,但最经济实惠的电阻式液位传感器体积过大,装入容器中会影响整体观感,且其寿命较短,故综合考虑后选择方案三。

2.3 最终设计

2.3.1 光照度测量部分设计

        如图14所示,光敏电阻Rp与R2并联,经R1分压后送入MCU进行ADC采集,即可获取光照度信息。送入MCU的电压可计算。

Light sensor circuit

图14 光照度测量电路原理图

2.3.2 环境温湿度测量部分设计

       如图15所示,数据线经R1上拉输入至MCU进行通讯,即可获得环境温湿度信息。

Ambient temperature and humidity sensor circuit

图15 环境温湿度传感器电路原理图

2.3.3 土壤湿度测量部分设计

       采购了电容式土壤湿度传感器,并通过MCU的ADC外设进行信号采集。

2.3.4 水箱水位测量部分设计

       采购了电容式柔性非接触式液位传感器。如图16所示,传感器输出信号通过上拉电阻可直接驱动继电器或点亮报警灯。

Water level measurement circuit schematic diagram

图16 水箱水位测量电路原理图

3 控制与通讯模块

3.1 要求简述

       项目定位是一个物联网嵌入式终端,具有测量、控制和通讯的功能。具体要求如下:

       ①能够获取传感器采集的信息

       ②能够将获取的信息上传至云平台在线展现给使用者

       ③能够将获取到的信息离线直观地展现给使用者

       ④能够根据获取的信息配合算法进行自动控制

       ⑤能够手动离线控制或通过云平台在线控制

3.2 方案比较

3.2.1 主控部分

方案一 STM32F103VET6+ESP8266-12F模块

       STM32F103VET6是由ST公司提供的一款32位高密度高性能线路MCU,具有丰富的外设资源。主频72MHz,具有5组共80个GPIO引脚,512kB Flash。STM32F103VET6外观如图17所示。

STM32F103VET6

图17 STM32F103VET6

优点:引脚资源丰富,具有极强的拓展性,方便进行二次开发

缺点:价格昂贵;主频较低,在复杂的ui图形化界面处理中乏力

方案二 ESP32-WROOM-32E模块

       ESP32-WROOM-32E模块是由乐鑫公司提供的一款双核WiFi+BT+BLE+MCU模组,主频240MHz,功能强大,用途广泛,可以用于低功耗传感器网络和例如语音编码、音频流和MP3解码要求极高的任务。ESP32-WROOM-32E模块如图18所示。

ESP32-WROOM-32E

图18 ESP32-WROOM-32E模块

优点:集成了MCU和通讯模组,实用方便;主频高,在ui图形化界面处理等高要求任务中表现突出;经济实惠

缺点:相关资料少,开发困难;引脚较少,二次开发困难

       由于硬件开发成本远高于软件开发成本,故在确保引脚和外设满足使用要求后,选择方案二。

3.2.2 通讯部分

方案一 蓝牙通讯

       蓝牙(Bluetooth)属于WPAN(无线个域网),即点对点、多点对多点。主要用于无线连接外部设备或在近距离进行数据传输。蓝牙传输的带宽为1Mbps,通信距离一般为 10米左右,使用FHSS(跳频扩谱)方式,一般每秒钟跳变1600次,将83.5MHz的频带划分为79个频带信道,每个时刻只占1MHz的带宽,使用GFSK(高斯频移键控)进行调制。常见的蓝牙模块有HC-05,BT08B,CH9141等。HC-05蓝牙模块外观如图19所示。

HC05 Bluetooth module

图19 HC-05蓝牙模块

优点:连接稳定;数据安全性高;功耗低

缺点:传输距离短;数据传输速度较慢

方案二 WiFi通讯

       WiFi(Wireless Fidelity),又称802.11b标准,属于WLAN无线局域网。支持多个终端设备同时传输的网路模式,即一对多的模式。传输范围100米,速度最大可以达到11Mbps,使用DSSS(直序列扩频)和QPSK或BPSK(相移键控)技术,上下带宽为22MHz。常见的WiFi模块有ESP88266-12F,ESP32等。ESP8266-12F模块外观如图20所示。

ESP8266-12F

图20 ESP8266-12F WiFi模块

优点:传输距离较长;数据传输速度快,可在应用层拓展更多功能

缺点:连接不稳定;数据安全性较低;功耗较大

       由于项目产品面向的是日常生活,大部分家庭并没有配备蓝牙网关,但一般都配备有WiFi网关,为了更方便用户使用,也为了能在应用层开发更多功能,故选择方案二。

3.3 最终设计

       采购了ESP32-WROOM-32E(16MB)模块,并为其设计了相应的外围电路。

4 总体设计

       硬件设计以主板硬件设计为主,主板主要特征如下:

       ·可通过DC-005插座或TypeC接口供电

       ·板载CH340C,设计有自动下载电路,可以通过TypeC接口串口通讯和 程 序烧录

       ·板载3.2inch SPI Module ILI9341 SKU:MSP3218屏幕接口(可拓展触屏和 SD卡)

       ·引出1路IIC通讯引脚,可拓展外部模块

       主板原理图如图21所示,PCB设计图如图22所示,实物图如图23所示。

Overall circuit schematic diagram

图21 主板电路原理图

Motherboard PCB design drawing

图22 主板PCB设计图

材料购买链接,仅供参考:

5V3A switching power supply: LRS switching power supply 220 to 24V MEAN WELL 12V DC 5V 50/100/150/200S transformer 350NES-tmall.com Tmall , RS-15-5|5V3A

ESP32-WROOM-32E module: ESP32-WROOM-32D-32U-32E original module WiFi+Bluetooth dual-core ESP32-WROVER-B-Taobao (taobao.com) , ESP32-WROOM-32E|16MB

Capacitive soil moisture sensor: Capacitive soil moisture sensor module is not easy to corrode soil moisture content detection wide voltage wiring-tmall.com Tmall

Capacitive flexible non-contact liquid level sensor: liquid level sensor non-contact water level water volume waterless sensing non-floating ball proximity sensor flexible - Taobao (taobao.com) , select the model according to the thickness of the water tank

DHT11 ambient temperature and humidity sensor: DHT11 DHT22 temperature and humidity sensor SHT30/31 digital switch AM2302 electronic building block module-tmall.com Tmall , DHT11 temperature and humidity module, free DuPont line

4-way relay module: 1/2/3/4-way relay module with optocoupler isolation compatible with 3.3V/5V or 12V TTL control signal-tmall.com Tmall , 4-way 5V version compatible with 3.3V

3.2-inch resistive touch screen: color LCD screen module 1.44/1.8/2.0/2.2/2.4/2.8/3.2/3.5/4.0-inch TFT color screen - Taobao (taobao.com) , 3.2-inch/with touch

Other common materials are not listed one by one.

software part

1 Introduction

1.1 Purpose

       This document mainly introduces the various functions and system components of the software part in the Internet of Things course design project, and how to implement them. Guide developers in subsequent coding, testing, maintenance and use.

1.2 Project background

       Software name: Garden on the Cloud

       Software English name: GardenOnTheCloud

       Software version number: 11_Version1.0.1.20220531_RC

1.3 References

"esp-idf-zh_CN-v5.0-dev-2938-gad747b237a-esp32"

《FreeRTOS_Reference_Manual_V10.0.0》

《LVGL Documentation 8.3》

2 Version change instructions

version number

Reason/purpose of change

Affected functional modules

Remark

       
       
       

3 Task Overview

3.1 Objectives

       Node part:

       · MCU can collect data obtained from sensors and update the UI interface in real time

       · MCU can accept manual control commands transmitted by the touch screen and control external devices according to the commands

       · MCU can connect to AP via WiFi and upload sensor data and device status to the cloud platform

       · MCU can receive and respond to online control commands from the cloud platform and control external devices according to the commands

       Host computer part:

       · Ability to issue commands through the IoT platform to control external devices online

       · Ability to display acquired sensor data in real time and query historical records within a certain period of time

3.2 Embedded software operating environment

       The software part is based on the esp-idf-v4.4 environment and is developed using Visual Studio Code tools. The UI is based on the transplanted LVGL8.2 design.

4 Overall design

4.1 Project directory structure

-..devcontainer

-.vscode // Visual Studio Code configuration file

-build // Compilation related

-components

---dht11 // Ambient temperature and humidity sensor driver component

---illuminance_adc // Illuminance sensor ADC sampling component

---LED // Programmable LED components

---light // Fill light driver component

---lvgl // LVGL8.2 component

---lvgl_esp32_drivers // ESP32 and LVGL8.2 related driver components

---motor // Motor drive component

---mqtt_ssl // mqtt communication component

---pump // water pump drive component

---sd_fatfs_br759 // SD card driver component

---soil_humi_adc // Soil moisture sensor ADC sampling component

---ui_display // ui component

---wifi_connection // WiFi connection component

-main // Main function, special component

-CmakeLists.txt // Cmake compilation file

-Makefile

-partitions.csv // Modified ESP32 Flash partition table

-README.md // Project related instructions

-sdkconfig // ESP32 initialization configuration file

-sdkconfig.old // ESP32 last initialization configuration file

4.2 Overview of program flow

       The basic flow of the program is shown in Figure 23.

Program flow chart

Figure 23 Program startup process and working status diagram

 

Notice! ! ! The description of the software part is for reference only, especially the program startup process and working status diagram! ! ! The actual code is single-tasking! ! ! The actual code is single-tasking! ! ! The actual code is single-tasking! ! ! I have been busy reviewing for the postgraduate entrance examination recently, and the subsequent code is still being improved, but the basic functions are no problem! ! !

 

Finally, thank you for reading this! ! ! If possible, how about paying attention to my favorite bilibili VTB (Ming Ming meichan)~

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2024-11-22 12:01:47

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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号