tutorial video
How to use the ESP-01S relay socket?
Required hardware
relay
ESP-01S relay socket
WIFI module
esp8266-01s wifi module
Writer
Software preparation
Arduino IDE needs to install the esp8266 extension
Download and install blinker APP
Android download:
Click to download or search "blinker" in the android app store to download and install
IOS download:
Click to download or search "blinker" in the app store to download
Install the blinker Arduino library
Import the .ZIP library into the library through the Arduino IDE menu > Project > Load Library > Add .ZIP library, as shown in the figure:
Import the .zip library extended by esp8266
Complete sample program ( copied from the official website )
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "Your Device Secret Key";
char ssid[] = "Your WiFi network SSID or name";
char pswd[] = "Your WiFi network WPA password or WEP key";
// 新建组件对象
BlinkerButton Button1("btn-abc");
BlinkerNumber Number1("num-abc");
int counter = 0;
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // LED引脚的编号
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
void setup() {
// 初始化串口
Serial.begin(115200);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
// 初始化有LED的IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // LED引脚的编号
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
}
void loop() {
Blinker.run();
}
What needs to be changed
Change the pin of digitalWrite output
Because the default control pin in the above complete example code isLED_BUILTIN
In Arduino
the program, instead of specific pin numbers (such as ) are Blink
used because the lights on the board are built-in and their interface circuits have already been designed. Using functions, no matter which specific pin the light is connected to, it can be correctly identified and controlled. This makes the program more portable and independent of the specific hardware design.LED_BUILTIN
13
Arduino
LED
LED_BUILTIN
LED
If LED
the light is connected to pin 13, you can of course use 13 instead LED_BUILTIN
. But in other board types or custom hardware, LED
the lights may be connected to other pins, which may be LED_BUILTIN
more advantageous.
In
ESP8266-01s
the module,0
pin No. isGPIO
(general-purpose input and output), we just need toLED_BUILTIN
replace them all0
.
According to ESP8266-01s
the manual, we can see that ESP01s
the chip works through GPIO0
a pin-controlled relay and is active at high level.
Use Ctrl+H
one-click replacement
Change lighting key
Change the secret key to your own
char auth[] = "Your Device Secret Key";
You need to add an independent device to the Dian Technology APP, select network access, and generate a secret key.
Change WIFI name and password
char ssid[] = "Your WiFi network SSID or name";
char pswd[] = "Your WiFi network WPA password or WEP key";
ssid[]
Corresponds to the name of WIFIpswd[]
Corresponding to the password of WIFI
Remote switch control
After that, you can manually add the switch button on the lighting APP for remote control after the device is online.
Notice
It should be noted that when adding a device button, the name needs to be consistent with the code