基于arduino实现的智能窗

本文介绍了使用Arduino实现的智能窗户系统,该系统集成了温湿度传感器、光强传感器、雨滴传感器和无源蜂鸣器,能够自动开关窗户,并在检测到特定环境条件如温度过低、光线不足或瓦斯泄漏时触发报警。通过LCD屏幕显示实时温湿度数据,并具备延时关闭功能,为家庭安全提供便利。
摘要由CSDN通过智能技术生成

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

今天带来的是基于arduino实现的智能窗户,可用于实现自动开关窗、检测温湿度、检测光强、检测瓦斯并实施报警功能。

一、器件

1.arduino开发板一块
2.dht11温湿度传感器一块
3.无源蜂鸣器一块
4.光强传感器一块
5.雨滴传感器一块
6.9g舵机一块
7.杜邦线若干
8.5v电源线一根

二、代码

1.引入库

代码如下(示例):

#include <dht.h>//温湿度传感器库文件
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h> 

LiquidCrystal_I2C lcd(0x27,16,2);  
dht DHT;
Servo myservo;

const int DHT11_PIN=7;//定义引脚
const int analogPin=A3; 
const int digitalPin=7; 
const int analogPin1=A2; 
const int digitalPin1=8;
const int ledPin=13; 
const int photocellPin = A5; 

int buzzerPin =6;//设置初始值

int Astate=0; 
boolean Dstate=0;  
int Astate1=0;
boolean Dstate1=0;

int outputValue = 0;

char array2[]="This is my job. ";  //the string to print on the LCD
char array1[]="Hello everybody. ";  //the string to print on the LCD

void setup()
{
  myservo.attach(9);//舵机引脚
  myservo.write(0);
  delay(1000);
  Serial.begin(9600);//波特率
  lcd.init();  
  lcd.backlight();  
  pinMode(ledPin,OUTPUT); 
  pinMode(digitalPin,INPUT);  
  pinMode (digitalPin1,INPUT);
  pinMode(buzzerPin,OUTPUT);
  digitalWrite(buzzerPin,LOW);
}

void loop()
{
  Astate=analogRead(analogPin);
  Dstate=digitalRead(digitalPin);  
  Astate1=analogRead(analogPin1);
  Dstate1=digitalRead(digitalPin1);
  outputValue = analogRead(photocellPin);
D: int chk = DHT.read11(DHT11_PIN);
  switch (chk)
  {
  case DHTLIB_OK:  
    break;
  case DHTLIB_ERROR_CHECKSUM: 
    break;
  case DHTLIB_ERROR_TIMEOUT: 
      goto D;
    break;
  default: 
    break;
  }
   lcd.setCursor(15,0);  // set the cursor to column 15, line 0
    for (int positionCounter1 = 0; positionCounter1 < 16; positionCounter1++)
    {
      lcd.scrollDisplayLeft();  //Scrolls the contents of the display one space to the left.
      lcd.print(array1[positionCounter1]);  // Print a message to the LCD.
      delay(400);  //wait for 250 microseconds
    }
    lcd.clear();  //Clears the LCD screen and positions the cursor in the upper-left corner.
    lcd.setCursor(15,1);  // set the cursor to column 15, line 1
    for (int positionCounter = 0; positionCounter < 26; positionCounter++)
    {
      lcd.scrollDisplayLeft();  //Scrolls the contents of the display one space to the left.
      lcd.print(array2[positionCounter]);  // Print a message to the LCD.
      delay(400);  //wait for 250 microseconds
    }
      lcd.clear(); 
       delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("Tem:");
  lcd.print(DHT.temperature,1); 
  lcd.print(char(223));
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.print("Hum:");
  lcd.print(DHT.humidity,1); 
  lcd.print(" %"); 
  delay(2000); //wait a while 
  Serial.print(Dstate);
  Serial.println(outputValue);
  
  if(DHT.temperature<20.0 || Dstate==LOW || Dstate1==LOW||outputValue <= 400)//判断条件
  {
    myservo.write(90);
    digitalWrite(ledPin,HIGH);
    digitalWrite(buzzerPin,HIGH);
    delay(10000);
    digitalWrite(ledPin,LOW);
    digitalWrite(buzzerPin,LOW);
  }
   else
  {
    myservo.write(0);
    digitalWrite(ledPin,LOW);
    digitalWrite(buzzerPin,LOW); 
  }
}

成果图初次检测显示温湿度最终效果

总结

基本实现了预期功能,还可以进一步改进,例如提高检测精度,加上gsm通信模块实现报警感知。

  • 4
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gcc future.c

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值