2019-3-16 11:39:53 [显示全部楼层]
6383浏览
查看: 6383|回复: 2

[教程] Arduino WiFi + App Inventor: 烟雾报警

[复制链接]
本帖最后由 szjuliet 于 2019-3-16 11:39 编辑

本贴写于2016-9-5,QQ日志。当时给MIT写博客,所以app和编程界面都是英文。视频链接在文末。

使用Arduino UNO WIFI板将烟雾传感器的值发送到客户端。客户端判断值的高低,如果超过临界值,手机报警,并给预设的手机发送警告短信。

硬件:
Arduino UNO WiFi板
gas sensor气体传感器
LED灯

软件:
Arduino IDE
App Inventor

一、Arduino UNO WiFi部分:
1. 将传感器与Aruidno板模拟端口0接好,LED灯与数字13口接好。


2.  将板子与电脑连接,启动Arduino IDE,端口设置为Network Pors-->当前获得的网络端口。


3.  编写代码,代码如下:
#include <Wire.h>
#include <ArduinoWiFi.h>
/*
on your borwser, you type http://<IP>/arduino/webserver/ or http://<hostname>.local/arduino/webserver/

http://www.arduino.org/learning/tutorials/webserver

*/
void setup() {
    Wifi.begin();
    Wifi.println("WebServer Server is up");
    pinMode(13, OUTPUT);
}
void loop() {
     
          if (analogRead(0) > 500)
       {  
          digitalWrite(13, HIGH);
       }
      else
       {
          digitalWrite(13, LOW);
       }        
    while(Wifi.available()){
      process(Wifi);
  
     }
  delay(50);
}
void process(WifiData client) {
  // read the command
  String command = client.readStringUntil('/');

  if (command == "webserver") {
    WebServer(client);
  }
}
void WebServer(WifiData client) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  
          client.println("Refresh: 20");  // refresh the page automatically every  sec
          client.println();      
          client.println("<html>");
          client.println("<head> <title>UNO WIFI Example</title> </head>");
          client.print("<body>");
         
            int analogChannel = 0;
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is (");
            client.print(sensorReading);
            client.print(")");
            client.print("<br/>");
         

          client.print("</body>");
          client.println("</html>");
          client.print(DELIMITER); // very important to end the communication !!!         
}

二、App Inventor部分:

1.  用户界面User Interface:
Arduino WiFi + App Inventor: 烟雾报警图1

2. 组件Components:
Arduino WiFi + App Inventor: 烟雾报警图2

3. 代码块:


三、实现烟雾报警:

1.  将.ino程序上传到UNO板。
2.  打包App Inventor程序并在手机上安装。
3.  启动app,呈现如下界面,此时气体传感器返回状态为“Normal"正常。
Arduino WiFi + App Inventor: 烟雾报警图3      


4.  点燃一支烟,并放到气体传感器旁边。此时传感器返回的值大于500,状态变为Dangerous。手机蜂鸣报警并给指定的手机号码发送提示短信。
   Arduino WiFi + App Inventor: 烟雾报警图4
程序中设置好的手机上接收到报警信息
   Arduino WiFi + App Inventor: 烟雾报警图5

此时UNO WIFI板子上的LED灯亮,起到警示作用。


演示视频在YouTube上。视频最后的声音是手机成功接收到报警短信的声音。

gada888  版主

发表于 2019-3-21 14:06:17

超好的教程
回复

使用道具 举报

szjuliet  版主
 楼主|

发表于 2019-3-22 08:53:15


:lol:handshake
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail