Remote control extension cord

 

"Polarity"




Current



ESP-01 and Relay Module
Ensure that your circuit will not draw more than the relay is rated for.   I would be inclined to stay well below the maximum current. I would be wary of using these little relays to control a toaster.



If you don't have your esp-01 and relay in a container you may want to consider putting some black tape over the back of the relay board.  There is 120VAC on the back solder connections when the extension cord is plugged in.

Simple Web Page to Control the extension cord

Examples of a light - off

and On




Front Lights Control

  

ESP01 and relay in electrical Box


Lights Off


Lights On


Programming


I use the Arduino IDE to program my ESPs




Since the ESP-01 board does not have built in USB port like the D1-Mini and
the ESP-12E Nodemcu we have to supply one to upload our code to the ESP.
The unit pictured does this.  It is purpose built for the ESP-01 to plug into.
There are two modes selected by the shown switch:

To change modes the ESP-01 needs to be reset via unplugging and plugging
in the USB interface.




ESP-01 attached to the FTDI interface/programmer

// Board is Generic ESP8266 Module

//From: https://www.instructables.com/ESP0101S-RELAY-MODULE-TUTORIAL/
// Modified by Deid Reimer 2020-02-06

#include <esp8266wifi.h>

// Variables for debugging int restartCount = 0; // Number of times the wifi has been restarted. int waitCount = 0; // Number of seconds waiting for input // Credentials const char* ssid = "wifi"; const char* password = "password"; // The relay is connected to GPIO0 #define RELAY 0 // Variables for wifi restart if wifi lost unsigned long previousMillis = 0; unsigned long interval = 30000; // Current status of relay. On boot set low. int value = LOW; // Define the server on port 80 WiFiServer server(80); void setup() { // I set the serial monitor slow because I can't read faster so // what's the point ... Serial.begin(9600); // Set the relay for output and default off pinMode(RELAY, OUTPUT); digitalWrite(RELAY, value); // Connect to the 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"); // Set wifi restart and persistent WiFi.setAutoReconnect(true); WiFi.persistent(true); // Print the IP address Serial.print("Use this URL to connect: "); Serial.print(WiFi.localIP()); Serial.println("/"); // Start the web server server.begin(); Serial.println("Server started"); } void loop() { // Check if a client has connected delay and // restart the loop if not. WiFiClient client = server.available(); if (!client) { //Serial.println("returning"); delay(10); return; } // There is a connection, wait for the client to send a request // and count and restart loop if too long a wait. int j = 0; while (!client.available()) { delay(1000); Serial.println(j++); if (j > 10) { waitCount = j; client.flush(); return; } } Serial.println("new client"); // Read the first line of the request String request = client.readStringUntil('\r'); Serial.println(request); // Trash anything else client.flush(); // Is the reguest ON, HIGH. Yes turn the relay on. if (request.indexOf("/RELAY=ON") != -1) { Serial.println("RELAY=ON"); digitalWrite(RELAY, HIGH); value = HIGH; } // Or of OFF turn the relay off if (request.indexOf("/RELAY=OFF") != -1) { Serial.println("RELAY=OFF"); digitalWrite(RELAY, LOW); value = LOW; } // Return the response - web page. // http part client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); // this is a must. Separates http from html client.println(""); // html part client.println(""); client.println(""); client.println("ESP8266 RELAY Control V1.0"); client.println(""); client.println(""); client.print("Restarts: "); client.println(restartCount); client.print("waitCount: "); client.println(waitCount); client.println(""); client.print("Relay is now: "); // clear wait for data count waitCount = 0; if (value == HIGH) { client.print("On"); } else { client.print("Off"); } client.println(""); client.println("Turn OFF RELAY"); client.println("Turn ON RELAY"); client.println(""); delay(1); Serial.println("Client disconnected"); Serial.println(""); // if WiFi is down, try reconnecting unsigned long currentMillis = millis(); if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >= interval)) { Serial.print(millis()); Serial.println("Reconnecting to WiFi..."); WiFi.disconnect(); WiFi.begin(ssid, password); previousMillis = currentMillis; //Alternatively, you can restart your board //ESP.restart(); } }
2022-02-07