步驟1:硬件零件
對于此項目,我將使用以下內容:
Arduino Uno
以太網屏蔽
HC-SR04超聲波傳感器
用于將傳感器連接到arduino的電線
CAT5電纜
路由器
筆記本電腦
步驟2:上傳軟件
在執行其他任何操作之前,先將軟件上載到arduino。請注意,以下代碼使用以太網屏蔽和HTTP請求來答復客戶端(瀏覽器)。因此,在下一步中,我們將看到服務器以如下所示的HTTP請求進行響應。如果出于任何原因想要使用Wi-Fi防護罩或其他任何東西,則可能需要修改代碼。
用戶獲取的值(整數)就是傳感器檢測到的值。因此,實際上它不是液位。但是,如果您根據剛得到的值從滿罐中提取出假設的液體,則只需計算液位。簡單的數學方程式。
/*****************************************************************************
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:連接硬件
這很容易做到。抓住四根電線,將它們連接到傳感器和以太網屏蔽。將屏蔽罩安裝在arduino上。請注意,傳感器具有一個GND(接地),一個5V(電源)和另外兩個名為echo和trig的引腳。 Echo連接到arduino中的7個數字引腳,并觸發到8個數字引腳。
此后,使用cat5電纜將屏蔽層與路由器相連。打開筆記本電腦的電源,然后繼續下一步。
步驟4:測試所有內容
現在,我們可以測試了。在筆記本電腦上打開瀏覽器,然后輸入192.168.1.177。它應該可以工作:)
請注意,在我們上傳的代碼中,我們說arduino具有上述IP。您可以根據需要進行更改。現在您可以將設備放在水箱中了,在那里放置路由器并回家,鍵入IP,然后查看水箱中剩余了多少水或石油。
-
監控器
+關注
關注
1文章
323瀏覽量
27352
發布評論請先 登錄
有源蜂鳴器驅動電路制作方法
ADC128D818 12位、8通道ADC系統監控器數據表

評論