Story
If you have a Wi-Fi connection, you may encounter some problems with your Wi-Fi router, such as disconnecting from the internet. Most of the time, you can fix this issue by power cycling your router.
To make this process easier, I've created a wireless switch that lets you turn the router off and on without needing to be near it. Press a button at your desk, and the router will be turned off for two seconds, and then it will turn back on automatically.
Both the sender and receiver are made using the Seed Studio Xiao ESP32C3. Right now, we use the ESP-Now protocol to communicate with the sender and receiver. One of the main advantages of using ESP-Now is that no extra wireless communication circuit is needed; the ESP32 devices talk directly to each other, which makes the project less complicated overall.
Supplies
TX Parts
- Seeedstudio XIAO ESP32C3
- OMRON 12x12x7.3mm Tactile 4 Pin Push Button Switch
- USB C cable
- Super glue
RX Parts
- Seeedstudio XIAO ESP32C3
- Mini 360 Step-Down Buck Converter Power Module
- IRLZ44N Mosfet
- 10K Resister
- 2*2.1 x 5.5mm DC Power Jack Socket Female - Panel Mount
- DC to DC cable
- B-7000 Glue
Tools Used
- Soldering kit
- Wire cutter
- Third-Hand Soldering Tool
- Screwdriver
- Tweezer
- Nose Plier
- 3d printer (grey, orange PLA)
Step 1: Designing in Fusion 360
Design is broken down into several levels for easy 3d printing
Step 2: 3D Printing
Due to its complex nature, I designed the object in parts, so we will need to assemble it after 3D printing. I used orange PLA and grey PLA. 3D printed all models in my cubic printer. In 0.2mm layer height and 30% infill
Step 3: Finding the MAC Address of Your XIAO ESP32C3
We are using the ESP-NOW protocol for communication between the transmitter (TX) and receiver (RX). For this, the transmitter (TX) needs to know the unique MAC address of the RX ESP32. You will need to run the following code on your ESP32C3 receiver (XIAO) to find its MAC address. After running this program, the MAC address will be displayed on the serial monitor.
My MAC address is 64:E8:33:8A:22:54
Code for finding the MAC address
#include<WiFi.h>#include<esp_wifi.h>voidreadMacAddress(){uint8_t baseMac[6];esp_err_t ret = esp_wifi_get_mac(WIFI_IF_STA, baseMac);if (ret == ESP_OK) { Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x\n", baseMac[0], baseMac[1], baseMac[2], baseMac[3], baseMac[4], baseMac[5]); } else { Serial.println("Failed to read MAC address"); }}voidsetup(){ Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.STA.begin(); Serial.print("[DEFAULT] ESP32 Board MAC Address: ");readMacAddress();}voidloop(){}
Step 4: TX Code
Before uploading the code we need to enter the MAC address of the our receiver which is 64:E8:33:8A:22:54 for me we need to add a 0x before it,
Then it will be 0x64, 0xE8, 0x33, 0x8A, 0x22, 0x54
Put that in this line of the code
// MAC address of the receiver
uint8_t receiverAddress[] = {0x64, 0xE8, 0x33, 0x8A, 0x22, 0x54};
TX code
#include<WiFi.h>#include<esp_now.h>// MAC address of the receiver (RX) ESP32uint8_t rx_mac[] = {0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX}; // Replace with actual MAC addressvoidsetup(){ Serial.begin(115200);// Initialize WiFi in STA mode WiFi.mode(WIFI_STA);// Initialize ESP-NOWif (esp_now_init() != ESP_OK) { Serial.println("ESP-NOW initialization failed");while (true); }// Register peeresp_now_peer_info_t peerInfo;memcpy(peerInfo.peer_addr, rx_mac, 6); peerInfo.channel = 0; // use the current channel peerInfo.encrypt = false;if (esp_now_add_peer(&peerInfo) != ESP_OK) { Serial.println("Failed to add peer");while (true); }// Register callback functionesp_now_register_send_cb(onDataSent);// Setup button pinpinMode(D0, INPUT_PULLUP);}voidloop(){if (digitalRead(D0) == LOW) { // Button pressed// Send signal to power cycleuint8_t data[] = {0x01}; // Signal to RXesp_now_send(rx_mac, data, sizeof(data));delay(1000); // Debounce delay }}voidonDataSent(constuint8_t *mac_addr, esp_now_send_status_t status){if (status == ESP_NOW_SEND_SUCCESS) { Serial.println("Data...Read more »