步驟1:硬件零件
對于此項目,我將使用以下內(nèi)容:
Arduino Uno
HC-SR04超聲波傳感器
用于將傳感器連接到arduino的電線
CAT5電纜
路由器
筆記本電腦
步驟2:上傳軟件
在執(zhí)行其他任何操作之前,先將軟件上載到arduino。請注意,以下代碼使用以太網(wǎng)屏蔽和HTTP請求來答復(fù)客戶端(瀏覽器)。因此,在下一步中,我們將看到服務(wù)器以如下所示的HTTP請求進行響應(yīng)。如果出于任何原因想要使用Wi-Fi防護罩或其他任何東西,則可能需要修改代碼。
用戶獲取的值(整數(shù))就是傳感器檢測到的值。因此,實際上它不是液位。但是,如果您根據(jù)剛得到的值從滿罐中提取出假設(shè)的液體,則只需計算液位。簡單的數(shù)學(xué)方程式。
/*****************************************************************************
An idea for Future Smart Homes
Oil Monitoring is a project that lets you monitor the ammount of oil
at yourhome. Alerts you with a message on facebook, gmail or even SMS
at your personal phone and more important gives you statistics about
the past.
* Arduino Uno
* Ethernet shield and ethernet cable | Wireless shield
* UltraSonic Distance Sensor
* Wires for arduino pins
Developed by Tzivaras Vasilis
Last Update: [10-06-2015]
*****************************************************************************/
#define echoPin 7
#define trigPin 8
#include
#include
// UltraSonic sensor min and max value to be accepted.
int maximumRange = 200;
int minimumRange = 0;
long duration, distance;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// Open serial communications and wait for port to open:
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print(“server is at ”);
Serial.println(Ethernet.localIP());
}
void getSensorValue() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println(“new client”);
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you‘ve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == ’ ‘ && currentLineIsBlank) {
// send a standard http response header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connection: close”); // the connection will be closed after completion of the response
client.println(“Refresh: 5”); // refresh the page automatically every 5 sec
client.println();
client.println(“”);
client.println(“”);
getSensorValue();
client.print(“{”id“:”);
client.print(“1770,”);
client.print(“”measurement“:”);
client.print(distance);
client.print(“}”);
client.println(“”);
client.println(“”);
break;
}
if (c == ’ ‘) {
// you’re starting a new line
currentLineIsBlank = true;
}
else if (c != ‘ ’) {
// you‘ve gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println(“client disconnected”);
}
}
步驟3:連接硬件
這很容易做到。抓住四根電線,將它們連接到傳感器和以太網(wǎng)屏蔽。將屏蔽罩安裝在arduino上。請注意,傳感器具有一個GND(接地),一個5V(電源)和另外兩個名為echo和trig的引腳。 Echo連接到arduino中的7個數(shù)字引腳,并觸發(fā)到8個數(shù)字引腳。
此后,使用cat5電纜將屏蔽層與路由器相連。打開筆記本電腦的電源,然后繼續(xù)下一步。
步驟4:測試所有內(nèi)容
現(xiàn)在,我們可以測試了。在筆記本電腦上打開瀏覽器,然后輸入192.168.1.177。它應(yīng)該可以工作:)
請注意,在我們上傳的代碼中,我們說arduino具有上述IP。您可以根據(jù)需要進行更改。現(xiàn)在您可以將設(shè)備放在水箱中了,在那里放置路由器并回家,鍵入IP,然后查看水箱中剩余了多少水或石油。
-
監(jiān)控器
+關(guān)注
關(guān)注
1文章
373瀏覽量
28996
發(fā)布評論請先 登錄
MAX1363/MAX1364:4通道12位系統(tǒng)監(jiān)控器的全方位解析
深入剖析 MAX1363/MAX1364:4 通道 12 位系統(tǒng)監(jiān)控器
MAX1361/MAX1362:4通道10位系統(tǒng)監(jiān)控器的深度剖析
MAX1363/MAX1364:4通道12位系統(tǒng)監(jiān)控器的技術(shù)解析與應(yīng)用指南
MAX1361/MAX1362:4 通道 10 位系統(tǒng)監(jiān)控器的技術(shù)剖析
一種基于電壓監(jiān)控器與內(nèi)置自檢機制的汽車攝像頭功能安全設(shè)計方法
AMC80系統(tǒng)硬件監(jiān)控器:功能、應(yīng)用與設(shè)計詳解
NoC性能監(jiān)控器調(diào)試指南
AMC60304光學(xué)監(jiān)控器和控制器技術(shù)解析與應(yīng)用指南
INA234 12位數(shù)字電流監(jiān)控器技術(shù)解析與應(yīng)用指南
水池液位與水泵狀態(tài)遠程監(jiān)控系統(tǒng)方案
水箱液位組態(tài)監(jiān)控物聯(lián)網(wǎng)解決方案
Texas Instruments INA4235 16位數(shù)字電流監(jiān)控器數(shù)據(jù)手冊
Texas Instruments INA4230 16位數(shù)字電流監(jiān)控器數(shù)據(jù)手冊
液位監(jiān)控器的制作方法
評論