所以到目前为止,我的代码是让我的arduino能够使用以太网发送加速度计和陀螺仪数据,但我无法弄清楚如何使其无线化。
这是我到目前为止所拥有的:
`
#包括
#包括
的#include
Byte mac[] = { 0x00, 0Xaa, 0xbb, 0xcc, 0xde 0x01 }; // Reserved Mac Address
EthernetClient client;
#define DHTPIN 2 // SENSOR PIN
#define DHTTYPE DHT11 // SENSOR TYPE
DHT dht(DHTPIN, DHTTYPE);
long previousMillis = 0;
unsigned long currentMillis= 0;
long interval = 250000; //READING INTERVAL
int t = 0; // TEMPERATURE VAR
int h = 0; // HUMIDITY VAR
String data;
Void setup() {
Serial.begin(115200);
If (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
}
dht.begin();
delay(10000); // GIVE THE SENSOR SOME TIME TO START
h = (int) dht.readHumidity();
t = (int) dht.readTemperature();
data = “”;
}
void loop(){
currentMillis = millis();
if(currentMillis – previousMillis > interval) { //READ ONLY ONCE PER INTERVAL
previousMillis = currentMillis;
h = (int) dht.readHumidity();
t = (int) dht.readTemperature();
}
data = “templ=” + t + “&hum1=” + h; //THIS IS FOR PRINTING DATA TO WEBPAGE
if (client.connect(www.*****.*************.com,80)) { //REPLACE WITH SERVER ADDRESS
client.println(“POST /add.php HTTP/1.1”);
client.println(“Host: *****.*************.com,80”); //SERVER ADDRESS HERE TOO
client.println(“Content-Type: application/x-www-form-urlencoded”);
client.print(“Content-Length: “);
client.println(data.length());
client.println();
client.print(data);
}
If (client.connected()) {
client.stop(); //Disconnect from the server
}
delay(300000); //Wait five minutes before sending again
}
`
谢谢
答案 0 :(得分:0)
你需要一个像ESP8266这样的WiFi模块。
你也可以单独使用它(没有arduino)因为它是带有io引脚的完整soc。
答案 1 :(得分:0)
对于小范围,您可以使用Xbee模块或蓝牙防护。对于范围,建议使用GSM屏蔽。