智能浇花系统

智能浇花系统

摘  要

随着生活水平的不断提高,人们对生活品质有更多的追求,越来越多得人开始在家里或办公室里种植一些盆栽。由于生活节奏的加快,经常会忘记给花卉浇水,花卉的生长需要经常浇灌,如果供水不足,花卉就会因缺水而干枯死亡,在不同的温湿度环境下,植物需要的供水也会有所变化。有些珍贵植物对湿度的要求高,浇水量达不到精确值,会影响到植物的正常生长。本设计是一款经济实用的智能浇花系统,能在无人管理的情况下自动地、智能地完成浇水的任务。通过市面上的土壤湿度传感器、继电器、水泵、温度传感器连接Arduino开发板可以实现该智能浇花系统。

关键词:智能浇花;Arduino开发板;土壤传感器;温湿度传感器

 

Abstract

With the continuous improvement of living standards, people have more pursuit of quality of life, and more and more people begin to plant some potted plants at home or in the office. As the pace of life accelerates, we often forget to water the flowers. The growth of flowers needs regular watering. If the water supply is insufficient, the flowers will dry up and die due to lack of water. Under different temperature and humidity environments, the water supply required by plants will also change. Some precious plants have high requirements for humidity, and the watering amount cannot reach an accurate value, which will affect the normal growth of plants. This design is an economical and practical intelligent watering system, which can automatically and intelligently complete the task of watering without human management. The intelligent watering system can be realized by connecting the Arduino development board with the soil humidity sensor, relay, water pump and temperature sensor on the market.

Keywords: Intelligent watering; Arduino; Soil sensor; Temperature and humidity sensor

目录

目录

智能浇花系统... I

摘  要... I

Abstract II

1.概  述... 4

1.1 背景... 4

1.2 开发环境... 4

1.2.1 硬件需求... 4

1.2.2 软件需求... 5

1.3 功能介绍... 5

2. 需求分析... 5

3. 详细设计... 6

3.1 数据的采集与硬件设计... 6

3.1.1 基本流程... 7

3.1.2 具体流程... 7

3.1.3 电路连接图... 7

3.2 软件设计... 6

3.2.1 具体流程... 6

4. 成果展示... 9

5. 完整代码... 9

参考文献:... 14

 

1.概  述

1.1 背景

随着科技的发展, 我们跑步进入了智能化时代, 智慧城市、 智能之家等都逐渐映入眼帘。 我们充分享受着智能带来的便捷, 交通智能化方便了我们的出行, 微型计算机代替人脑完成复杂计算, 互联网、 物联网在地球上编织了一张大网, 让人与人之间的距离缩近, 这一切都改变着我们的生活。 闲暇之际, 养花成了现代人陶冶情操的方式, 但是, 经常旅游出差等却总是让爱花几近凋谢。 为解决这一问题, 市场上出现了一些浇花装置, 主要分为两类: 一类是以物理虹吸原理,即利用渗透的方式来自动浇水, 另一类是利用简单的定时控制技术实现自动浇水。 由于这些浇花系统检测方式单一, 无法根据土壤湿度来达到实时浇水, 因此往往出现花卉干枯或者过涝死亡的现象。

本文提出一种新的智能化的浇花系统,在太阳能加电池的稳定电源供电下, 通过土壤湿度传感器、 温湿度传感器来实时监测花卉的情况, 核心处理器 Arduino 将传感器得到的信息进行判断处理, 并及时给出控制系统信号, 从而控制水泵的开启与关闭, 实现按需浇花;

1.2 开发环境

1.2.1 硬件需求

表1  Arduino UNO 控制芯片连接硬件情况表

主要硬件

Arduino接口

Arduino拓展板

Arduino UNO

土壤湿度传感器YL-69

A0

继电器模块

D8

DHT22温湿度传感器

A2

LCD1602显示屏

D6、D5、D4、D3、D2

在选用材料时,考虑到多个方面,如下:

(1)   材料易得

(2)   使用方便,库函数易找

(3)   功能完备

根据上面的需求,首先选择土壤湿度传感器YL-69,YL-69是一个简单的土壤湿度传感器,其原理为湿敏电容,当环境的湿度发生改变时,会使得湿敏电容存在的环境中的介质发生改变,导致湿敏电容中的电容数值产生变化,电容的数值正比于湿度值。由于湿敏电容有这很高的灵敏度、响应速度快,易于在集成电路中使用。要实现浇水的需求,选取电机加水泵的组合,通过控制继电器来实现浇水和停止浇水。显示屏选择了lcd1602,这是一款简单的16*2显示液晶屏,它是一种专门用来显示字母、数字、符号等的点阵型液晶模块。字符型液晶,能够同时显示16x02即32个字符,适用于小型集成电路,并且操作简单。另外选取了DHT22作为温湿度传感器的选择。它是一款含有已校准数字信号输出的温湿度复合传感器,具有很高的可靠性与稳定性,系统连接简洁,功耗极低,信号传输距离可达 20 m 以上,相较于旧版的DHT11误差更小,十分符合本次项目的需要。

1.2.2 软件需求

Arduino直接编程。

其中本项目运用的是基于Arduino IDE的Arduino直接编程的方法。因为Arduino IDE基于processing IDE开发。对于初学者来说,极易掌握,同时有着足够的灵活性。Arduino语言基于wiring语言开发,是对 avr-gcc库的二次封装,不需要太多的单片机基础、编程基础,简单学习后,就快速的进行开发。DHT22作为本设计的温度检测模块,可以很方便的找到Arudino的库文件,可以直接引用。

1.3 功能介绍

该设计实现如下功能:

  1. 采集目标花卉的土壤环境和实时环境的温湿度数据。
  2. 将湿度模拟信号转换为数字信号传送到 Arduino
  3. Arduino将检测到的湿度值与预设的湿度阈值进行比较
  4. 若小于预设阈值则启动系统,大于预设值则停止浇水。

2. 需求分析

随着智能家居的概念深入人心,越来越多的人开始追求更为智能以及方便的生活。花卉的养护通常是需要耐心和精力的事情,设计本项目可以实现部分的花卉照顾自动化

3. 详细设计

3.1 数据的采集与硬件设计

3.1.1 基本流程

Arduino 作为主要控制芯片, 要实现预想的浇花系统功能, 需要利用 Arduino进行程序的编写。

当系统启动时, Arduino 开始对程序进行初始化, 随后等待上位机发出指令, 接

收到指令后, 对程序相关设定参数进行更新 (包括土壤湿度、室温等) , 然后开

始检测土壤湿度, 在当前湿度监测值传回上位机后, 系统将把检测值与预设值

进行比较, 当检测值低于预设值时, Arduino 驱动水泵电机进行工作, 此时土壤

湿度将随着水量的增加而增加, 直到检测值大于设定值时, 水泵停止工作, 具

体工作流程如图1所示。

图1 主控程序设计流程图

3.1.2 具体流程

3.1.2.1获取数据

       首先要在Arduino IDE定义开发板的型号,在IDE中进入开发板管理器,加载在互联网上找到的DHTLib库,这是DHT22的库文件。定义好土壤传感器的接口

核心代码如下:

  void loop() {

sensorValue = analogRead(sensorPin);

  int readDate = DHT.read22(DHTPIN);

  float t = DHT.temperature;

    // Recoed temperature

  float h = DHT.humidity;

    // Recoed humidity

  Serial.print("T = ");

  Serial.print(t);

  Serial.print(" *C ");

  Serial.print("    H = ");

  Serial.print(h);

  Serial.println(" % ");

   Serial.print("SH = ");

  Serial.print(sensorValue);

  Serial.println(" h ");

3.1.2.2 lcd显示

       首先在Arduino IDE加载<LiquidCrystal.h>库文件,接着代码中初始化显示屏数据,然后读取DHT22传感器传输的数据,并更改显示器的输出文字

核心代码如下:

byte degree[8] =

              {

                0b00011,

                0b00011,

                0b00000,

                0b00000,

                0b00000,

                0b00000,

                0b00000,

                0b00000

              };

void setup() {

lcd.begin(16, 2);//指定尺寸

lcd.createChar(1, degree);

lcd.clear();

lcd.print("   Humidity   ");

lcd.setCursor(0,1);

lcd.print("  Measurement ");

//delay(2000);

lcd.clear();

}

void loop() {

//lcd显示模块

  lcd.setCursor(0,0);

  lcd.print("H:");

  lcd.print(DHT.humidity);  

  // printing Humidity on LCD

  lcd.print("%");

  lcd.print(" SH:");

  lcd.print(sensorValue);

  // Printing Soil temperature on LCD

  lcd.print("h");

  lcd.setCursor(0,1);

  lcd.print("Temp:");

  lcd.print(DHT.temperature);  

  // Printing temperature on LCD

  lcd.write(1);

  lcd.print("C");

}

3.1.2.3 浇水装置

       浇水装置采用一个继电器和电机水泵来实现,首先定义好继电器的接口位置,设置一个判断函数,根据土壤传感器的数据来选择是否启动继电器,根据DHT22监测到的环境温湿度,调整需要浇水的阈值

核心代码如下:

//自动浇水模块

  if(sensorValue>700)

  //当读取的值大于700时,启动

  {

   digitalWrite(zlhPin, HIGH);

     Serial.print("Water ");

     lcd.clear();

     lcd.print("Begin Water");

    

//begin

   //高电平,继电器启动

       delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

                  Serial.print("StopWater");

  }else

  {

   digitalWrite(zlhPin, LOW);

        Serial.print("NoWater ");

//continue

   //低电平,继电器不启动

  }

  Serial.print("Soilhumidity = ");

  Serial.println(sensorValue);

int AirT=DHT.temperature;

//When Temperature>35

  if(AirT>35&&AirT<37)

  //当天气太热时自动浇水

  {

    if(sensorValue>600){

         digitalWrite(zlhPin, HIGH);

     Serial.print("Too Hot,Water");

          lcd.clear();

     lcd.print("Too Hot,Water");

            delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

//begin

   //高电平,继电器启动

       delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

                  Serial.print("StopWater");

    }

  }

3.1.3 电路连接图

3.1.3.1 土壤湿度传感器模块

图1:土壤湿度传感器连接LM393模块

3.1.3.2浇水模块

图2:水泵与继电器的连接

水泵的黑线接到电池盒黑线,LM393模块的AO--接主板的A0口 VCC接主板的5V口  GND接主板的GND   继电器的IN接主板的D8  VCC接主板的5V  GND接主板的GND继电器的另一边 NO接水泵红线  中间的COM口接电池盒红线 NC不接

3.1.3.3 DHT22温度传感器

1口接5V

2口接到拓展板的A2

4口接拓展板的GND

图3:DHT22在面包板的接线

3.1.3.4 LCD1602液晶显示屏

通过并联4个220Ω电阻调节对比度,使屏幕可见度适中

图4:1602在面包板的接线

3.1.3.5 拓展板

连接传感器接口、继电器接口

图5:拓展板接口与接线

3.1.3.6 面包板

连接lcd1602液晶显示器、DHT22温湿度传感器

图5:面包板接线

3.2 软件设计

3.2.1 具体流程

3.2.1.1 浇水模块

int sensorPin = A0;    // 设置模拟口A0为信号输入端

int zlhPin = 8;      // 设置继电器控制引脚为8

int sensorValue = 0;  // 存放模拟信号量的变量

void setup() {

  pinMode(zlhPin, OUTPUT);  //设置对应的引脚为输出

  Serial.begin(9600);     //初始化串口波特率9600

}

void loop() {

  sensorValue = analogRead(sensorPin);

 

  if(sensorValue>700)//当读取的值大于700时,启动

  {

   digitalWrite(zlhPin, HIGH);

  }else

  {

   digitalWrite(zlhPin, LOW);

  }

  Serial.println(sensorValue);

  delay(100);

}

预期结果:当土壤湿度阈值大于700时,电机会启动,开始浇水,小于700则关闭电机,停止浇水

串口检测器显示当前土壤湿度

其中400为插入水中时传感器返回的数据

图6:土壤湿度显示

3.2.1.2  DHT22模块

#include <dht.h>

//dht22的库文件

#define DHTPIN A2

dht DHT;

void setup() {

  Serial.begin(9600);   

  //初始化串口波特率9600

}

void loop() {

  int readDate = DHT.read22(DHTPIN);

  float t = DHT.temperature;

  float h = DHT.humidity;

  Serial.print("Temperature = ");

  Serial.print(t);

  Serial.print(" *C ");

  Serial.print("    Humidity = ");

  Serial.print(h);

  Serial.println(" % ");

  delay(2000);

}

预期结果:串口检测器会显示当前的空气温度和湿度

图7:环境温度和湿度显示

3.2.1.3  LCD1602模块

#include <LiquidCrystal.h>

//lcd库文件

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

//定义lcd接口

byte degree[8] =

              {

                0b00011,

                0b00011,

                0b00000,

                0b00000,

                0b00000,

                0b00000,

                0b00000,

                0b00000

              };

//初始化lcd显示

void setup() {

  Serial.begin(9600);   

   Serial.print("Initiate LCD");

  //初始化串口波特率9600

  //lcd显示屏初始化

  lcd.begin(16, 2);//指定尺寸

lcd.createChar(1, degree);

lcd.clear();

lcd.print("   Humidity   ");

lcd.setCursor(0,1);

lcd.print("  Measurement ");

//delay(2000);

lcd.clear();

}

void loop() {

    sensorValue = analogRead(sensorPin);

  int readDate = DHT.read22(DHTPIN);

  float t = DHT.temperature;

    // Recoed temperature

  float h = DHT.humidity;

    // Recoed humidity

  Serial.print("T = ");

  Serial.print(t);

  Serial.print(" *C ");

  Serial.print("    H = ");

  Serial.print(h);

  Serial.println(" % ");

   Serial.print("SH = ");

  Serial.print(sensorValue);

  Serial.println(" h ");

  delay(2000);

  //read data in computer

//lcd显示模块

  lcd.setCursor(0,0);

  lcd.print("H:");

  lcd.print(DHT.humidity);  

  // printing Humidity on LCD

  lcd.print("%");

  lcd.print(" SH:");

  lcd.print(sensorValue);

  // Printing Soil temperature on LCD

  lcd.print("h");

  lcd.setCursor(0,1);

  lcd.print("Temp:");

  lcd.print(DHT.temperature);  

  // Printing temperature on LCD

  lcd.write(1);

  lcd.print("C");

  //delay(500);

}

预期结果:显示屏上会初始化显示,并实时显示当前空气温度、湿度和土壤的湿度

图8:传感器数据在idea上的显示

图9:传感器数据在lcd显示屏上的显示

4. 成果展示

将土壤湿度传感器插入水中,即当干燥度小于设定值(700)时:

图10 :成果展示(非干燥)

电机不会启动,土壤为湿润状态。

将土壤湿度传感器从水中拔出至干燥的空气中,即当干燥度大于设定值(700)时:

图11 :成果展示(干燥)

土壤湿度传感器在空气中时,传输到系统的值为1024,大于需要浇水的阈值,电机开始工作,显示屏显示正在浇水

      

5. 完整代码

#include <Wire.h>

#include <dht.h>

//dht22的库文件

#include <LiquidCrystal.h>

//lcd库文件

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

//定义lcd接口

#define DHTPIN A2

//空气温湿度检测器DHT22 

#define dataPin 8

dht DHT;

byte degree[8] =

              {

                0b00011,

                0b00011,

                0b00000,

                0b00000,

                0b00000,

                0b00000,

                0b00000,

                0b00000

              };

//初始化lcd显示

int sensorPin = A0;

//土壤湿度检测器  

// 设置模拟口A0为信号输入端

int zlhPin = 8;     

// 设置继电器控制引脚为8

int sensorValue = 0; 

// 存放模拟信号量的变量

void setup() {

  Serial.begin(9600);   

   Serial.print("Initiate LCD");

  //初始化串口波特率9600

  //lcd显示屏初始化

lcd.begin(16, 2);//指定尺寸

lcd.createChar(1, degree);

lcd.clear();

lcd.print("   Humidity   ");

lcd.setCursor(0,1);

lcd.print("  Measurement ");

//delay(2000);

lcd.clear();

  pinMode(zlhPin, OUTPUT); 

  //设置对应的引脚为输出

Serial.print("Read Sensor");

}

void loop() {

    sensorValue = analogRead(sensorPin);

  int readDate = DHT.read22(DHTPIN);

  float t = DHT.temperature;

    // Recoed temperature

  float h = DHT.humidity;

    // Recoed humidity

  Serial.print("T = ");

  Serial.print(t);

  Serial.print(" *C ");

  Serial.print("    H = ");

  Serial.print(h);

  Serial.println(" % ");

   Serial.print("SH = ");

  Serial.print(sensorValue);

  Serial.println(" h ");

  delay(2000);

  //read data in computer

//lcd显示模块

  lcd.setCursor(0,0);

  lcd.print("H:");

  lcd.print(DHT.humidity);  

  // printing Humidity on LCD

  lcd.print("%");

  lcd.print(" SH:");

  lcd.print(sensorValue);

  // Printing Soil temperature on LCD

  lcd.print("h");

  lcd.setCursor(0,1);

  lcd.print("Temp:");

  lcd.print(DHT.temperature);  

  // Printing temperature on LCD

  lcd.write(1);

  lcd.print("C");

  //delay(500);

 //读值初始化

 //自动浇水模块

  if(sensorValue>700)

  //当读取的值大于700时,启动

  {

   digitalWrite(zlhPin, HIGH);

     Serial.print("Water ");

     lcd.clear();

     lcd.print("Begin Water");

    

//begin

   //高电平,继电器启动

       delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

                  Serial.print("StopWater");

  }else

  {

   digitalWrite(zlhPin, LOW);

        Serial.print("NoWater ");

//continue

   //低电平,继电器不启动

  }

  Serial.print("Soilhumidity = ");

  Serial.println(sensorValue);

//final

//根据空气的温度和湿度调整浇水策略

int AirT=DHT.temperature;

//When Temperature>35

  if(AirT>35&&AirT<37)

  //当天气太热时自动浇水

  {

    if(sensorValue>600){

         digitalWrite(zlhPin, HIGH);

     Serial.print("Too Hot,Water");

          lcd.clear();

     lcd.print("Too Hot,Water");

            delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

//begin

   //高电平,继电器启动

       delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

                  Serial.print("StopWater");

    }

  }

    if(AirT>37&&AirT<38)

  //当天气太热时自动浇水

  {

    if(sensorValue>650){

         digitalWrite(zlhPin, HIGH);

     Serial.print("Too Hot,Water");

          lcd.clear();

     lcd.print("Too Hot,Water");

    

//begin

   //高电平,继电器启动

       delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

                  Serial.print("StopWater");

    }

  }

 int AirH=DHT.humidity;

 //When humidity<85

   if(AirH<85)

   //当太干燥时自动浇水

  {

    if(sensorValue>650){

         digitalWrite(zlhPin, HIGH);

     Serial.print("Too Dry,Water ");

               lcd.clear();

     lcd.print("Too Dry,Water");

//begin

   //高电平,继电器启动

       delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

                  Serial.print("StopWater");

    }

  }

 //When humidity<80

   if(AirH<80)

   //当太干燥时自动浇水

  {

    if(sensorValue>600){

         digitalWrite(zlhPin, HIGH);

     Serial.print("Too Dry,Water ");

               lcd.clear();

     lcd.print("Too Dry,Water");

//begin

   //高电平,继电器启动

       delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

                  Serial.print("StopWater");

    }

  }

   //When humidity<75

   if(AirH<75)

   //当太干燥时自动浇水

  {

    if(sensorValue>500){

         digitalWrite(zlhPin, HIGH);

     Serial.print("Too Dry,Water ");

               lcd.clear();

     lcd.print("Too Dry,Water");

//begin

   //高电平,继电器启动

       delay(2000);

       //间歇浇水,防止过满

          digitalWrite(zlhPin, LOW);

                  Serial.print("StopWater");

    }

  }

}

参考文献ar:

[1] 刘川, 张小成, 高进渊, 等. 智能自动浇花系统的控制设计研究[J]. 科技视界, 2015 (18) : 87-88.

[2] 于欣龙, 李泽. 传感器实战全攻略[M]. 北京, 人民邮电出版社,2016: 263-280.

[3]袁本华, 董铮. 基于 Arduino 控制板的温室大棚测温系统设计]. 安徽农业科, 2012, 40(8) : 5049-5050.

[4]崔阳. 一种基于Ardui no的智能家居控制系统[J]. 计算机技术与应用2014—4:123—125.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值