***本商品為研發實驗用的模組,無法隨插即用,“非成品"
須經專業背景人士(如:工程師、研究生、師生)
撰寫程式、燒錄、接線等二次加工後,才具備訊號傳輸功能。
並非直接插電後可直接使用之射頻模組,未經組裝無法使用
非屬電信管制射頻器材,購買前請詳閱商品說明。
物聯網IOT開關模組 含ESP-01S
ESP8266繼電器模組可手機操控WIFI雲端開關
發貨清單及規格:
1.開發板:ESP-01S * 一片
2.繼電器模組 * 一片
電源: DC 5V
PCB尺寸: 37*25mm
繼電器: 1個 NC/NO/com
*********塑膠袋包裝
安裝:
1.接線: 在繼電器接線端子接上要控制的設備,比如電燈,風扇。。。。
2.燒錄程式:使用下載器,一鍵下載,燒錄你寫好的程式碼
3.採用WIFI或APmode ,讓手機連上ESP-01S發出的熱點,
自行寫一個APP 程式, 操控 繼電器開關
範例:
#include
const char* ssid = "xxxxx"; // fill in here your router or wifi SSID
const char* password = "xxxxxx"; // fill in here your router or wifi password
#define RELAY 0 // relay connected to GPIO0
WiFiServer server(80);
void setup()
{
Serial.begin(115200); // must be same baudrate with the Serial Monitor
pinMode(RELAY,OUTPUT);
digitalWrite(RELAY, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
//Serial.print("https://192.168.0.178/");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop()
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client)
{
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available())
{
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
int value = LOW;
if (request.indexOf("/RELAY=ON") != -1)
{
Serial.println("RELAY=ON");
digitalWrite(RELAY,HIGH);
value = LOW;
}
if (request.indexOf("/RELAY=OFF") != -1)
{
Serial.println("RELAY=OFF");
digitalWrite(RELAY,LOW);
value = HIGH;
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // this is a must
client.println("");
client.println("");
client.println("
ESP8266 RELAY Control"); client.print("Relay is now: ");
if(value == HIGH)
{
client.print("OFF");
}
else
{
client.print("ON");
}
client.println("
");
client.println("Turn
OFF RELAY
");
client.println("Turn
ON RELAY
");
client.println("");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}