动手实践丨手把手教你用STM32做一个智能鱼缸

<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">本文分享自华为云社区《<a style="color: blue;">基于STM32+华为云IOT设计的物联网鱼缸【玩转华为云】-云社区-华为云</a>》,作者: DS小龙哥 。</span></p>
<h1 style="text-align: left; margin-bottom: 10px;">1. 前言</h1>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">为了缓解学习、生活、工作带来的压力,提升生活品质,许多人喜欢在家中、办公室等场所养鱼,为节省鱼友时间、劳力、增加养鱼乐趣;为此,本文基于STM32单片机设计了一款基于物联网的智能鱼缸,该鱼缸可以实现水温检测、水质检测、自动或手动换水、氛围灯灯光变换和自动或手动喂食等功能为一体的控制系统,鱼缸通过ESP8266连接华为云IOT物联网平台,并通过应用侧接口开发了上位机APP实现远程对鱼缸参数检测查看,并能远程控制。</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: blue;"><span style="color: green;">从功能上分析,需要用到的硬件如下:</span></strong></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">(1)STM32系统板</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">(2)水温温度检测传感器: 测量水温</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">(3)水质检测传感器: 测量水中的溶解性固体含量,反应水质。</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">(4)步进电机: 作为鱼饲料投食器</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">(5)RGB氛围灯: 采用RGB 3色灯,给鱼缸照明。</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">(6)抽水电动马达: 用来给鱼缸充氧,换水,加水等。</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">(7)ESP8266 WIFI:设置串口协议的WIFI,内置了TCP/IP协议栈,完善的AT指令,通过简单的指令就可以联网通信,但是当前采用的ESP8266没有烧写第三方固件,采用原本的原滋原味的官方固件,没有内置MQTT协议,代码里连接华为云物联网平台需要使用MQTT协议,所以在STM32代码里通过MQTT协议文档的字段结构自己实现了MQTT协议,在通过ESP8266的TCP相关的AT指令完成数据发送接收,完成与华为云IOT平台交互。</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><span style="color: green;">水产养殖水质常规检测的传感器有哪些?水产养殖水质常规检测的传感器有水质ph传感器、溶解氧传感器和温度传感器。</span></p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">(1)水质ph传感器:</p>ph传感器是高智能化在线连续监测仪,由传感器和二次表两部分组成,可配三复合或两复合电极,以满足各种使用场所,配上纯水和超纯水电极,可适用于电导率小于3μs/cm的水质(如化学补给水、饱和蒸气、凝结水等)的pH值测量。
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">(2)溶解氧传感器:</p>
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">氧气的消耗量与存在的氧含量成正比,而氧是通过可透膜扩散进来的,传感器与专门设计的监测溶氧的测量电路或电脑数据采集系统相连,溶解氧传感器能够空气校准,一般校准所需时间较长,在使用后要注意保养,如果在养殖水中工作时间过长,就必须定期地清洗膜,对其进行额外保养。</p>在很多水产养殖中,每天测几次溶氧就可以了解溶氧情况,对池塘和许多水槽养殖系统,溶氧水平不会变化很快,池塘一般每天检测2~3次,对于较高密度养殖系统,增氧泵故障发生可能不到1h就会造成鱼虾等大面积死亡,这些密度高的养殖系统要求有足够多的装备或每小时多次自动测量溶氧。
<p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">(3)温度传感器:</p>温度传感器有多种结构,包括热电偶、电阻温度传感器和热敏电阻,热电偶技术成熟,应用领域广,货源充足,选择热电偶必须满足温度范围要求,且其材料与环境相容,电阻温度传感器(RTDs)的原理为金属的电阻随温度的改变而改变,大多电阻温度传感器(RTDs)由铂、镍或镍合金制成,其线性度比热电偶好,热切更加稳定,但容易破碎,热敏电阻是电阻与温度具有负相关关系的半导体,热敏电阻比RTD和热电偶更灵敏,也更容易破碎,不能承受大的温差,但这一点在水产养殖中不成问题。
<div style="text-align: left; margin-bottom: 10px;"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" style="width: 100%; margin-bottom: 20px;"></div>
<div style="text-align: left; margin-bottom: 10px;"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" style="width: 100%; margin-bottom: 20px;"></div>
<div style="text-align: left; margin-bottom: 10px;"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" style="width: 100%; margin-bottom: 20px;"></div>
<div style="text-align: left; margin-bottom: 10px;"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" style="width: 100%; margin-bottom: 20px;"></div>
<div style="text-align: left; margin-bottom: 10px;"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" style="width: 100%; margin-bottom: 20px;"></div>
<div style="text-align: left; margin-bottom: 10px;"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" style="width: 100%; margin-bottom: 20