只需按下按鈕,本制作就能保護(hù)你的安全。如果遇到危險(xiǎn),在你按下按鈕的時(shí)候,你的準(zhǔn)確位置將會(huì)共享到你預(yù)先用代碼選定的所有網(wǎng)站上。作為一款9V電池供電的手持式設(shè)備,本項(xiàng)目電路可安裝在在盒子里,方便外出攜帶。
項(xiàng)目物料清單如下:
Arduino UNO ? ? ? ? ? ? ? ? ? ? ×1?
Espressif ESP8266 ESP-01 ? ? ? ?×1?
Infineon DPS310 ? ? ? ? ? ? ? ? ×1?
Linear Regulator (7805) ? ? ? ? ×1?
SparkFun Big Red Dome Button ?×1?
Breadboard (generic) ? ? ? ? ? ?×1
?

?
想象一下這樣的場景,你被困在高樓里,但眼前只能看到一片紅暈,看不清任何數(shù)字或所在高度,這是多么恐懼啊?這時(shí)你就可以借助這個(gè)按鈕獲得準(zhǔn)確的位置信息。類似情況可能發(fā)生在救援隊(duì)員身上,說明這個(gè)項(xiàng)目非常有意義。
第1步: 連接電源
?

使用9V電池作為供電,通過7805三端穩(wěn)壓器芯片為arduino供電。
第2步: 將ESP8266與電源連接
?

?
將Arduino的3.3V輸出連接到ESP8266。ESP8266工作于3.3V而不是5V,這點(diǎn)一定要記住。
第3步: 連接RX和TX
將Arduino板的RXD引腳、TXD引腳,分別連接到ESP8266板的RX引腳、TX引腳。
?

當(dāng)需要兩個(gè)硬件之間相互通話時(shí),通常將其中一個(gè)的TX引腳與另一方的RX引腳連接,這就是雙工。這里不需要Arduino直接向ESP8266喊話,我們通過電腦實(shí)現(xiàn)Arduino與ESP8266通信。
第4步: GND和RST
連接RES 或 RESET 引腳。當(dāng) RESET 引腳接地后,Arduino對串口連接器來說相當(dāng)于一個(gè)啞巴USB,這就實(shí)現(xiàn)了我們想要和ESP8266通話的目的。
?

?
第5步: 連接按鈕
為電源添加按鈕。

?
第6步: Arduino IDE
在Arduino IDE中,我們不需要選擇任何板子,因?yàn)槲覀儾幌駿SP8266上傳任何數(shù)據(jù)。只需從 Tools 菜單選擇正確接口即可——“工具 - 串口監(jiān)視器”,再將傳輸速率設(shè)置為ESP8266固件使用的默認(rèn)值115200。由于我們與 CH_PD 引腳通話,如果需要指示燈,可連接ESP8266 GPIO0引腳。
?

第7步: 連接DPS310
按照電路圖連接I2C口。
?

?
第8步: 安裝Infineon DPS310庫
在Arduino IDE中安裝DPS310壓力傳感器庫,須從Arduino IDE打開 Sketch > Include Library > Add .ZIP Library... 轉(zhuǎn)至已下載的 .ZIP 文件。這個(gè)庫將安裝在Arduino sketch文件夾的庫中,也可將它包含在Sketch > Include Library> IFX_DPS310中。
?

第9步: Arduino庫與Google地圖通話
參照https://github.com/witnessmenow/arduino-google-maps-api連接Google地圖。DPS310壓力傳感器是從地平面開始記錄測量數(shù)據(jù)的,需要為不同城市創(chuàng)建不同的程序和算法。
附:DPS310 C/C++ Code file
#include "SoftwareSerial.h"
String ssid ="yourSSID";
String password="yourPassword";
SoftwareSerial esp(6, 7);// RX, TX
String data;
String server = "yourServer"; // www.example.com
String uri = "yourURI";// our example is /esppost.php
int DHpin = 8;//sensor pin
byte dat [5];
String pressure;
void setup() {
pinMode (DHpin, OUTPUT);
esp.begin(9600);
Serial.begin(9600);
reset();
connectWifi();
}
//reset the esp8266 module
void reset() {
esp.println("AT+RST");
delay(1000);
if(esp.find("OK") ) Serial.println("Module Reset");
}
//connect to your wifi network
void connectWifi() {
String cmd = "AT+CWJAP="" +ssid+"","" + password + """;
esp.println(cmd);
delay(4000);
if(esp.find("OK")) {
Serial.println("Connected!");
}
else {
connectWifi();
Serial.println("Cannot connect to wifi"); }
}
byte read_data () {
byte data;
for (int i = 0; i < 8; i ++) {
if (digitalRead (DHpin) == LOW) {
while (digitalRead (DHpin) == LOW); // wait for 50us
delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or '1'
if (digitalRead (DHpin) == HIGH)
data |= (1 << (7-i)); // high front and low in the post
while (digitalRead (DHpin) == HIGH);
// data '1 ', wait for the next one receiver
}
} return data; }
void start_test () {
digitalWrite (DHpin, LOW); // bus down, send start signal
delay (30); // delay greater than 18ms, so DHT11 start signal can be detected
digitalWrite (DHpin, HIGH);
delayMicroseconds (40); // Wait for DPS response
pinMode (DHpin, INPUT);
while (digitalRead (DHpin) == HIGH);
delayMicroseconds (80);
// DPS response, pulled the bus 80us
if (digitalRead (DHpin) == LOW);
delayMicroseconds (80);
// DPS 80us after the bus pulled to start sending data
for (int i = 0; i < 4; i ++)
// receive temperature and humidity data, the parity bit is not considered
dat[i] = read_data ();
pinMode (DHpin, OUTPUT);
digitalWrite (DHpin, HIGH);
// send data once after releasing the bus, wait for the host to open the next Start signal
}
void loop () {
start_test ();
// convert the bit data to string form
pressure = String(dat[0]);
data = "PRESSURE" +pressure;// data sent must be under this form //name1=value1&name2=value2.
httppost();
delay(1000);
}
void httppost () {
esp.println("AT+CIPSTART="TCP","" + server + "",80");//start a TCP connection.
if( esp.find("OK")) {
Serial.println("TCP connection ready");
} delay(1000);
String postRequest =
"POST " + uri + " HTTP/1.0\r\n" +
"Host: " + server + "\r\n" +
"Accept: *" + "/" + "*\r\n" +
"Content-Length: " + data.length() + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"\r\n" + data;
String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.
esp.print(sendCmd);
esp.println(postRequest.length() );
delay(500);
if(esp.find(">")) { Serial.println("Sending.."); esp.print(postRequest);
if( esp.find("SEND OK")) { Serial.println("Packet sent");
while (esp.available()) {
String tmpResp = esp.readString();
Serial.println(tmpResp);
}
// close the connection
esp.println("AT+CIPCLOSE");
}
}}
審核編輯:湯梓紅
評論