当前位置:网站首页>LabVIEW Arduino TCP/IP远程智能家居系统(项目篇—5)
LabVIEW Arduino TCP/IP远程智能家居系统(项目篇—5)
2022-06-26 21:40:00 【InfoQ】
1、项目概述
2、项目架构

3、传感器选型
3.1、气体传感器

3.2、温度传感器
3.3、热释电红外传感器

3.4、继电器

4、硬件环境

5、Arduino功能设计
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 //DS18B20接至Arduino数字口2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define gas_Command 0x81
#define temp_Command 0x82
#define infrared_Command 0x80
#define SW1_ON_Command 0x11
#define SW1_OFF_Command 0x10
#define SW2_ON_Command 0x21
#define SW2_OFF_Command 0x20
#define SW3_ON_Command 0x31
#define SW3_OFF_Command 0x30
#define SW4_ON_Command 0x41
#define SW4_OFF_Command 0x40
#include <SPI.h>
#include <Ethernet.h>
// Adresses MAC et IP à changer suivant vos besoins
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
// Initialisation de la librairie ethernet
// et création d'un objet "Server" qui va accepter
// les connexions extérieures à l'adresse IP defini plus
// haut et sur le port indiqué (ici 8000)
EthernetServer server(8000);
byte comdata[3]={0};
void test_do_data(void); //测试串口数据是否正确并执行命令
int SW1=3;
int SW2=4;
int SW3=5;
int SW4=6;
int inrared_Pin=7;
void setup()
{
Ethernet.begin(mac, ip); // Initialisation de la pile TCP/IP
server.begin(); // Démarrage du serveur
sensors.begin();
pinMode(SW1, OUTPUT);
pinMode(SW2, OUTPUT);
pinMode(SW3, OUTPUT);
pinMode(SW4, OUTPUT);
}
void loop()
{
int i ;
// Attente des connexions et création d'un objet client s'il y a lieu
EthernetClient client = server.available();
if (client) { // Un client existe
while (client.connected()) { // il est connecté
if (client.available()) { // et il a envoyé des caractères
for(i=0;i<3;i++)
{
comdata[i] =client.read();
//延时一会,让串口缓存准备好下一个字节,不延时可能会导致数据丢失
delay(2);
}
test_do_data();
}
// on renvoie au client une chaine de caractère qui représente le résultat de
// la conversion AN (par ex: '236') suivi des caractères CR+LF
}
client.stop(); // Fermeture de la connexion
}
}
void test_do_data()
{
if(comdata[0] == 0x55) //0x55和0xAA均为判断是否为有效命令
{
if(comdata[1] == 0xAA)
{
switch (comdata[2])
{
case temp_Command:
sensors.requestTemperatures();
server.print(sensors.getTempCByIndex(0),2);
break;
case infrared_Command:
server.print(digitalRead(inrared_Pin)*5/1024,2);
break;
case gas_Command:
server.print(analogRead(A0));
break;
case SW1_ON_Command:
digitalWrite(SW1, HIGH);
break;
case SW1_OFF_Command:
digitalWrite(SW1, LOW);
break;
case SW2_ON_Command:
digitalWrite(SW2, HIGH);
break;
case SW2_OFF_Command:
digitalWrite(SW2, LOW);
break;
case SW3_ON_Command:
digitalWrite(SW3, HIGH);
break;
case SW3_OFF_Command:
digitalWrite(SW3, LOW);
break;
case SW4_ON_Command:
digitalWrite(SW4, HIGH);
break;
case SW4_OFF_Command:
digitalWrite(SW4, LOW);
break;
}
}
}
}6、LabVIEW功能设计
6.1、前面板设计

6.2、程序框图设计







边栏推荐
- DAST 黑盒漏洞扫描器 第五篇:漏洞扫描引擎与服务能力
- Leetcode question brushing: String 03 (Sword finger offer 05. replace space)
- PostgreSQL notes
- Installation avec homebrew dans un environnement Mac OS [email protected]
- 网络爬虫终篇:向10万级网易云用户发送定向消息
- The importance of using fonts correctly in DataWindow
- VB.net类库(进阶版——1)
- CVPR 2022 | 美团技术团队精选论文解读
- Shiniman household sprint A shares: annual revenue of nearly 1.2 billion red star Macalline and incredibly home are shareholders
- Leetcode question brushing: String 01 (inverted string)
猜你喜欢

Leetcode(763)——划分字母区间

【 protobuf 】 quelques puits causés par la mise à niveau de protobuf

The postgraduate entrance examination in these areas is crazy! Which area has the largest number of candidates?

基于Qt实现的“合成大西瓜”小游戏

Matrix derivation and its chain rule

【protobuf 】protobuf 昇級後帶來的一些坑

Leetcode question brushing: String 06 (implement strstr())

YOLOv6:又快又准的目標檢測框架開源啦

VB.net类库(进阶版——1)

leetcode:152. 乘积最大子数组【考虑两个维度的dp】
随机推荐
剑指 Offer II 098. 路径的数目 / 剑指 Offer II 099. 最小路径之和
这个算BUG吗?乱填的字母是否可以关闭
leetcode:6103. 从树中删除边的最小分数【dfs + 联通分量 + 子图的值记录】
Can compass open an account for stock trading? Is it safe?
Leetcode: hash table 08 (sum of four numbers)
Web crawler 2: crawl the user ID and home page address of Netease cloud music reviews
Stop being a giant baby
12个MySQL慢查询的原因分析
YOLOv6:又快又准的目標檢測框架開源啦
Talk about my remote work experience | community essay solicitation
【protobuf 】protobuf 升级后带来的一些坑
Leetcode(122)——买卖股票的最佳时机 II
[protobuf] some pits brought by protobuf upgrade
Implementation of collaborative filtering evolution version neuralcf and tensorflow2
SAP commerce cloud project Spartacus getting started
About appium trample pit: encountered internal error running command: error: cannot verify the signature of (solved)
What are the accounting elements
网络爬虫2:抓取网易云音乐评论用户ID及主页地址
基于启发式搜索的一字棋
KDD2022 | 基于知识增强提示学习的统一会话推荐系统