This week, I built on Output Week by designing a microcontroller system where a button on one ESP32 board communicates with another ESP32 board to control a linear actuator. The goal is to integrate this system into my final project for a voice-activated or facial-recognition-enabled door lock.
The primary challenge was establishing a stable Wi-Fi connection between the two ESP32 devices. Some issues encountered included weak Wi-Fi signals, incorrect IP configurations, and inconsistent connections. To address these:
Below are the steps I followed:
#include <WiFi.h> #include <WebServer.h> const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD"; WebServer server(80); const int actuatorPin = 9; void handleExtend() { digitalWrite(actuatorPin, HIGH); server.send(200, "text/plain", "Actuator extended"); delay(1000); digitalWrite(actuatorPin, LOW); } void setup() { Serial.begin(115200); pinMode(actuatorPin, OUTPUT); digitalWrite(actuatorPin, LOW); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); } server.on("/extend", handleExtend); server.begin(); } void loop() { server.handleClient(); }
#include <WiFi.h> #include <HTTPClient.h> const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD"; const char* serverIP = "SERVER_IP_ADDRESS"; const int buttonPin = 20; const int ledPin = 9; void setup() { Serial.begin(115200); pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); } } void loop() { if (digitalRead(buttonPin) == LOW) { digitalWrite(ledPin, HIGH); delay(100); if (WiFi.status() == WL_CONNECTED) { HTTPClient http; String url = String("http://") + serverIP + "/extend"; http.begin(url); int httpResponseCode = http.GET(); http.end(); } delay(1000); digitalWrite(ledPin, LOW); } }