2016年9月4日星期日

Using App Inventor and Arduino UNO WIFI board to build a Smoke Alarm APP

The app will make an alarm when the gas sensor detects gas, after that the app sends a message to someone whose phone number is set in advance.

When the gas sensor detects gas, the LED light will be on.

When the gas sensor detects gas, the phone will buzzes and then send SMS to the specific people.


Here is the video:







Hardware:
Arduino UNO WIFI
Gas Sensor
Led

Software:
App Inventor

1. Arduino UNO WIFI:
Reference:
http://www.arduino.org/learning/getting-started/getting-started-with-arduino-uno-wifi 
http://www.arduino.org/learning/tutorials/boards-tutorials/webserver

Gas sensor: analog 0;
LED: Pin 13;


.ino file:
#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 !!!         
}

2. App Inventor:

User Interface:

Components:


Blocks:






没有评论:

发表评论