HW-655 ESP-01 WiFi Relay Board Fix

by Patronic in Circuits > Arduino

1088 Views, 0 Favorites, 0 Comments

HW-655 ESP-01 WiFi Relay Board Fix

Screenshot_20230704-081945_Samsung Internet.jpg
board3.jpg

Some years ago, I purchased a couple of ESP8266 HW-655 Relay Boards.

After a lot of trial and effort I could not get them to work with suggested Arduino sketches.

I came to the conclusion that the STC micro was not programmed.

Well recently, I decided to modify the boards to work directly from the ESP-01; and make a program to operate it

Supplies

Tools needed : pliers, soldering Iron, solder wick and solder.

Component Replacement

board1.jpg

First step was to remove any parts that impeded the GPIO ports.

The NPN driver which I replaced with 5cent 2N7002, remove the drive resistors and STC chip;


Wiring

board2.jpg

I then linked the GPIO 0 port via the moved10k resistor to the gate of the FET.

Then I had to rebuild the RELAY.INO to act as a Server.

See the pictures and copy the modified sketch with hints from Rui Santos:

Good Luck!!

INO file to copy

Code.ino

Screenshot_20230704-082009_Samsung Internet.jpg
Ashampoo_Snap_2023.07.04_09h26m51s_004_.jpg



/*********
ESP-01 RELAY;  some snippets from Rui Santos
********/

#include <ESP8266WiFi.h>
 
const char* ssid = "xxxxxxxxxxx"; // fill in here your router or wifi SSID
const char* password = "xxxxxxxxxx"; // fill in here your router or wifi password
#define RELAY 2                    // relay connected to GPIO2 = 2  OR GPIO0 = 0
WiFiServer server(80);

void setup() 
 {
 Serial.begin(115200); // must be same baudrate with the Serial Monitor
  pinMode(RELAY,OUTPUT);
  digitalWrite(RELAY, LOW);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) //while unconnected loop .....
      {delay(500);
      Serial.print("."); } 
      
  // Start the server
  Serial.println("");               //if connected START up
  Serial.println("WiFi connected");
  server.begin();
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
  }
 
//*******************************

void loop() {

// Check if a client has connected
  WiFi.setAutoReconnect(true);
  WiFi.persistent(true);
  WiFiClient client = server.available();
  {delay(300); }      //reqired to wait for previous request to clear
  if (!client)
  {return;}


// Wait until the client sends some data
  while(!client.available())
  {delay(1); }

// Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

 // Match the request
  int STATE = LOW;
  if (request.indexOf("/RELAY=ON") != -1)  
  {Serial.println("RELAY=ON");
  digitalWrite(RELAY,HIGH);
  STATE = HIGH;}
  if (request.indexOf("/RELAY=OFF") != -1)  
  {Serial.println("RELAY=OFF");
  digitalWrite(RELAY,LOW);
  STATE = LOW;}

// Display the HTML web page
  client.println("<!DOCTYPE html><html><body style=background-color:#00cccc;>");     //1c87c9      
  client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
  client.println("<link rel=\"icon\" href=\"data:,\">");

// CSS to style the on/off buttons 
  client.println("<style>html {font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
  client.println(".button {background-color: #195B6A; border: none; color: white; padding: 16px 40px;");
  client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
  client.println(".button2 {background-color: #ff0000;}</style></head>");          // red $ff $xx $xx R G B
 
// Web Page Heading
  client.println("<br />");    // Print a line space
  client.println("<h1> RELAY CONTROL </h1>");

// Current Relay Status set boxes
  client.println("<h1><br>"); //<body> <h1> is headline <br> Print 1 line space
  client.println("Turn RELAY<a href=\"/RELAY=ON\"> ON</a> <br><br>"); 
  client.println("Turn RELAY<a href=\"/RELAY=OFF\">OFF</a><br><br>");
  if (STATE == LOW)
        {client.println("<p><button class=\"button\">RELAY OFF</button></a></p>");}
  else 
        { client.println("<p><button class=\"button button2\">RELAY ON</button></a></p>");}

  // Command executed
  // client.stop(); // Dot know if this works
   // Clear the request variable
     request = "";
}