Google Chat: zj734465502@gmail.com
+86-0755-88291180
sales01@spotpear.com
dragon_manager@163.com
services01@spotpear.com
manager01@spotpear.com
WhatsApp:13246739196
ESP32-S3-Relay-6CH is an industrial-grade 6-channel WiFi network relay based on ESP32-S3 main controller and supports WiFi, Bluetooth, RS485, Pico and other peripheral interfaces. It has built-in protection circuits such as power supply isolation and optodecoupler isolation, which is safe, stable and reliable, and suitable for the AIoT field.
Item | Parameter |
Supply Voltage | 7~36V (or 5V/1A Type-C port) |
Relay Channels | 6 channels |
Contact Form | 1NO 1NC |
Wiring port | Type-C |
Communication protocol | USB protocol |
Dimensions | 145 × 90 × 40 (mm) |
1. ESP32-S3 2. High-quality relay 3. Optocoupler isolation 4. Digital isolation 5. Power isolation 6. Onboard TVS (Transient voltage suppressor) 7. Ceramic gas discharge tube 8. Relay screw terminal 9. Compatible Raspberry Pi Pico interface 10. RS485 communication interface | 11. Power supply screw terminal 12. Operating status indicator 13. WS2812 RGB colorful LED 14. USB Type-C interface 15. Passive buzzer 16. RESET button 17. BOOT button 18. External antenna socket 19. RS485 matching resistor 20. Relay default control pin setting solder joint |
Control GPIO | Function | Description |
GP0 | BOOT button | BOOT button control pin |
GP21 | BUZZER | Buzzer control pin |
GP38 | RGB | RGB light control pin |
GP1 | CH1 | Relay 1 control pin |
GP2 | CH2 | Relay 2 control pin |
GP41 | CH3 | Relay 3 control pin |
GP42 | CH4 | Relay 4 control pin |
GP45 | CH5 | Relay 5 control pin |
GP46 | CH6 | Relay 6 control pin |
GP17 | TXD | UART TX pin, corresponding to RS485 |
GP18 | RXD | UART RX pin, corresponding to RS485 |
ESP32-S3-Relay-6CH currently provides two development tools and frameworks, Arduino IDE and MicroPython, providing flexible development options, you can choose the right development tool according to your project needs and personal habits.
Arduino IDEArduino IDE is an open source electronic prototyping platform, convenient and flexible, easy to get started. After a simple learning, you can start to develop quickly. At the same time, Arduino has a large global user community, providing an abundance of open source code, project examples and tutorials, as well as rich library resources, encapsulating complex functions, allowing developers to quickly implement various functions. | |
MicroPythonMicropython is a full implementation of the Python 3 programming language that runs directly on embedded hardware such as ESP32, Raspberry Pi Pico, etc. You can run Python scripts directly on the board through REPL, which is very suitable for rapid prototyping. |
Each of these two development approaches has its own advantages, and developers can choose according to their needs and skill levels. Arduino and MicroPython are suitable for beginners and non-professionals because they are easy to learn and quick to get started.
This chapter introduces setting up the Arduino environment, including the Arduino IDE, management of ESP32 boards, installation of related libraries, program compilation and downloading, as well as testing demos. It aims to help users master the development board and facilitate secondary development.
Board name | Board installation requirement | Version number requirement |
---|---|---|
esp32 by Espressif Systems | "Install Offline" / "Install Online" | 2.0.12 |
Library Name | Description | Version | Library Installation Requirement |
---|---|---|---|
ArduinoJson | Lightweight JSON library | v6.21.4 | "Install Online" or "Install Offline" |
PubSubClient | MQTT message subscription publishing library | v2.8.0 | "Install Online" or "Install Offline" |
NTPClient | Network time synchronization client library | v3.2.1 | "Install Online" or "Install Offline" |
File
-> New Sketch
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Hello, World!");
delay(2000);
}
File
-> Save As...
. In the pop-up menu, select the path to save the project, and enter a project name, such as Hello_World, click Save
①. Click to select the dropdown menu option Select Other Board and Port;
②. Search for the required development board model esp32s3 dev module and select;
③. Select COM Port;
④. Save the selection.
①. Compile the program; ②. Compile and download the program; ③. Download successful.
Demo | Basic Description | Dependency Library |
---|---|---|
01_MAIN_WIFI_AP | RS485 interface control, Bluetooth control, Bluetooth send IP, Web page control (short distance) | Can be flashed directly Web pages are only available if they are connected to device WIFI |
02_MAIN_WIFI_STA | RS485 interface control, Bluetooth control, Bluetooth send IP, Web page control (short distance) | Need to modify the WIFI to be connected Web pages can only be used within the intranet |
03_MAIN_WIFI_MQTT | RS485 interface control, Bluetooth control, Bluetooth transmit IP, Waveshare cloud control (long distance) | Need to modify the WIFI to be connected The device must be created in the Waveshare cloud |
04_MAIN_ALL | RS485 interface control, Bluetooth control, Bluetooth send IP, Web page control (short distance), Waveshare cloud control (long distance) | Need to modify the WIFI to be connected The device must be created in the Waveshare cloud Web pages can only be used within the intranet |
Demo description
Precautions
Code analysis
uint8_t *buf
: A pointer to an unsigned 8-bit integer array, which is supposed to store the received data, and the function determines the content of the command based on the value of the first element (buf[0]
) of the array.uint8_t Mode_Flag
: The mode flag is used to represent the data source, and the corresponding data source prompt information (such as Bluetooth data, Wi-Fi data, or RS485 data) is output by judging this flag, and different relay operations are performed according to different commands.Mode_Flag
.switch
statement to perform different operations based on the value of buf[0]
:CH1
to CH6
, the digitalToggle
function is used to switch the level states of the corresponding GPIO pins (such as GPIO_PIN_CH1
, etc.), and the corresponding elements of the Relay_Flag
array are updated to record the change in relay status. The Buzzer_PWM
function is called to control the buzzer, and the corresponding on or off prompt information is output according to the final state of the relay.ALL_ON
command, set all GPIO pins (corresponding to 6 channel relays) to high level (on state), use the memset
function to set all elements of the Relay_Flag
array to 1, indicating that all relays are turned on, output all relay ON prompt information, and control the buzzer.ALL_OFF
command, set all relevant GPIO pins to low level (off state) similarly, update the Relay_Flag
array elements to 0, output a message that all relays are turned off and control the buzzer, and perform two additional buzzer control operations (with a delay in between).buf[0]
does not belong to the above command cases, a prompt message for non-instruction data is output.WIFI_AP
, and then attempt to create a soft AP through WiFi.softAP(ssid, password)
. If it fails, it will loop through prompt and retry until it succeedsipStr
and output it for easy network address recognitionhandleRoot
, handleGetData
, etc.) for multiple paths (such as “/”, “/getData”, etc.) through server.on
, each function should be defined elsewhere for different functional operations like returning pages, getting data, controlling switches etc.server.begin()
to start the Web server and output a startup prompt message.Demo description
Precautions
Code analysis
WIFI_STA
mode and enable sleep mode, then start connecting to the specified network. In the cyclic wait of unsuccessful connection, a point is output as a prompt every half second, and the RGB light briefly turns red on every even number of attempts (except the first attempt). If every 10 attempts fail, the connection is disconnected and reconnected. If the number of attempts exceeds 22, the connection is considered a failure and the loop is exited.WIFI_Connection
to 1, light up the green light for 1 second to indicate success, and then obtain and display the local IP address. Next, register callback functions corresponding to multiple paths for the web server (such as root path, data retrieval, control of different switches, etc.), and finally start the server and output startup prompt, so that the device can receive corresponding control through the web page.WIFI_Connection
to 0, output a prompt to inform that the device can be controlled through Bluetooth debugging assistant, and light a red light to indicate a connection failure statusDemo description
Precautions
Code analysis
CH1
, ALL_ON
etc.) are sent to the device via Bluetooth, Wi-Fi, or RS485. The device parses and executes the corresponding operation after receiving a command. For example, when the command CH1
is received, the function will switch the state of relay 1printf
(e.g., relay status update: "Relay CH1 on") and fed back via the buzzer Buzzer_PWM
). This allows users to see real-time status updatesBluetooth_Init()
, and the device can establish connections with other Bluetooth devices and receive control commandsMQTT_Init()
, the device will connect to the Wi-Fi network and be able to communicate with remote servers through the MQTT protocolAcquisition_time()
function will synchronize the current time to RTC through the network, ensuring that the device has accurate system timeDemo description
Precautions
Operation Command | Command Function |
06 01 | Switch the CH1 relay status of Modbus RTU Relay |
06 02 | Switch the CH2 relay status of Modbus RTU Relay |
06 03 | Switch the CH3 relay status of Modbus RTU Relay |
06 04 | Switch the CH4 relay status of Modbus RTU Relay |
06 05 | Switch the CH5 relay status of Modbus RTU Relay |
06 06 | Switch the CH6 relay status of Modbus RTU Relay |
06 07 | Switch the CH7 relay status of Modbus RTU Relay |
06 08 | Switch the CH8 relay status of Modbus RTU Relay |
06 09 | Turn on all relays of Modbus RTU Relay |
06 0A | Turn off all relays of Modbus RTU Relay |
Parameter | Parameter Description |
RTC_OPEN_Time_Hour | The time to turn on all relays——hours |
RTC_OPEN_Time_Min | The time to turn on all relays——minutes |
RTC_Closs_Time_Hour | The time to turn off all relays——hours |
RTC_Closs_Time_Min | The time to turn off all relays——minutes |
This section focuses on setting up the MicroPython development environment, primarily covering firmware flashing, installation, and the use of Thonny. For the installation part of Thonny, detailed explanations of the installation steps and usage instructions are provided, offering comprehensive and clear guidance for developers to build a MicroPython development environment.
..\ESP32-S3-Relay-6CH-Demo\MicroPython\Firmware
The bin file is a file for testing the onboard function under the Firmware folder that is at the same level as the Arduino and MicroPython folders, and there is no need to flash it here
Demo | Basic Description |
---|---|
main.py | Main function |
ws_bluetooth.py | Bluetooth initialization and command parsing |
ws_gpio.py | RGB, buzzer, relay initialization |
ws_information.py | Global system parameter settings |
ws_relay.py | Implement relay control |
ws_serial.py | 8-ch relay extension |
..\ESP32-S3-Relay-6CH\Firmware\Factory bin
The product can be controlled online through the Homeassistant built on the Raspberry Pi, and the relevant operations can be found in Reference link
①View through Device Manager: Press the Windows + R keys to open the "Run" dialog box; input devmgmt.msc and press Enter to open the Device Manager; expand the "Ports (COM and LPT)" section, where all COM ports and their current statuses will be listed.
②Use the command prompt to view: Open the Command Prompt (CMD), enter the "mode" command, which will display status information for all COM ports.
③Check hardware connections: If you have already connected external devices to the COM port, the device usually occupies a port number, which can be determined by checking the connected hardware.
①Use the dmesg command to view: Open the terminal.
①Use the ls command to view: Enter ls /dev/ttyS* or ls /dev/ttyUSB* to list all serial port devices.
③Use the setserial command to view: Enter setserial -g /dev/ttyS* to view the configuration information of all serial port devices.
Monday-Friday (9:30-6:30) Saturday (9:30-5:30)
Email: services01@spotpear.com