So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By pilol34
#75567 Hi Xury;

Between 2 projects I looked for your request and I prepared this little code. As requested, I use the ASCII string "RELAY1=" followed by "0" or "1" to activate the relay. This ASCII chain is not case sensitive.

To enable the relay, you can use:
    RELAY1=1
    Relay1=1
    RelAy1=1
    etc.
and to turn off the relay:
    RELAY1=0
    Relay1=0
    etc.
I hope this will please you.

Regards, Pilol34.

File: LcWifiRelayUartAsciiV1_0.hex
Code: Select all:0300000002017387
:03000B00020100EF
:10010000C0D0C0E075D00820010B20B019D2017D0D
:10011000047F092126DD0F7D03A2B0EB13FBDF0670
:1001200033F9C201D203DC1D7C03300018EE7009E4
:10013000C2B1880A7E09020145EAD313FA92B1DE00
:1001400004C200D202D0E0D0D032F5F0E52305237E
:10015000543F2434F8E5F0F622E4936006A312013C
:100160004A215922C200C201D202C203E4750C0323
:10017000F50D22787FE4F6D8FD75817F75D0107576
:100180008900758E80758A80758CFED28CD2A9D23A
:10019000B9D2AF12016475B1FB75B203C2B2754436
:1001A00000300217E5226523543F600FC202E522AA
:1001B0000522543F2434F88608D200300332C203AB
:1001C0009001F2E54493601CF9E509B4600221D482
:1001D00040029420697004054421A1E54460BF7584
:1001E000440021C0E5096430C31370B292B2219E6D
:1001F00021A152454C4159313D00A00101A2A0016D
:1002000000A1B00100B1B00000B04F4E0A004F464F
:10021000460A0001004C4320576966692052656C0C
:100220006179204153434949202D206669726D77D9
:100230006172652056312E30206279204C6F7569CD
:09024000732050696C6F6E0A0016
:00000001FF
User avatar
By Etts
#75646 Reprogramming the STC15F104W works brilliantly!! Thanks.
Seems the MCU was not programmed.
BTW, found an English programmer that works with the STC15F104W and on Windows 10 here:
http://www.stcisp.com/STC-ISP_update_%20history.html
file is directly downloadable here: http://www.stcisp.com/_download_stcisp_new.html
Had to remove R4 as well.
Now only problem is getting CIPSERVER to start automatically when power is cycled.
(Apologies for not following any standards here. :D Noob in this forum)
User avatar
By Charles Misiec
#76178 I just got relay on/off running without any modification on the hardware. I used Arduino IDE to load the code to ESP01. No additional wiring is necessary.

Follow below example of code of simple Access Point and Web server with buttons to ON/OFF blue led and the relay from LC Technology.

Observe the declaration of const at the top of code:
const byte miBufferON[] = {0xA0, 0x01, 0x01, 0xA2};
const byte miBufferOFF[] = {0xA0, 0x01, 0x00, 0xA1};

Later on
Serial.write(miBufferOFF, sizeof(miBufferOFF));
Serial.write(miBufferON, sizeof(miBufferON));



/*
* NodeMCU/ESP8266 act as AP (Access Point) and simplest Web Server
* to control GPIO (on-board LED)
* Connect to AP "arduino-er", password = "password"
* Open browser, visit 192.168.4.1
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#define LoadPin 2// GPIO2

const char *ssid = "arduino-er";
const char *password = "password";
int stateLED = LOW;
const byte miBufferON[] = {0xA0, 0x01, 0x01, 0xA2};
const byte miBufferOFF[] = {0xA0, 0x01, 0x00, 0xA1};

ESP8266WebServer server(80);

void handleRoot() {
response();
}

void handleLedOn() {
stateLED = LOW;
digitalWrite(LoadPin, stateLED);
Serial.write(miBufferON, sizeof(miBufferON));
response();
}

void handleLedOff() {
stateLED = HIGH;
Serial.write(miBufferOFF, sizeof(miBufferOFF));
digitalWrite(LoadPin, stateLED);
response();
}

const String HtmlHtml = "<html><head>"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /></head>";
const String HtmlHtmlClose = "</html>";
const String HtmlTitle = "<h1>CONTROLE REMOTO VIA CELULAR</h1><br/>\n";
const String HtmlLedStateLow = "<big>LED is now <b>ON</b></big><br/>\n";
const String HtmlLedStateHigh = "<big>LED is now <b>OFF</b></big><br/>\n";
const String HtmlButtons =
"<a href=\"LEDOn\"><button style=\"display: block; width: 100%;\">ON</button></a><br/>"
"<a href=\"LEDOff\"><button style=\"display: block; width: 100%;\">OFF</button></a><br/>";

void response(){
String htmlRes = HtmlHtml + HtmlTitle;
if(stateLED == LOW){
htmlRes += HtmlLedStateLow;
}else{
htmlRes += HtmlLedStateHigh;
}

htmlRes += HtmlButtons;
htmlRes += HtmlHtmlClose;

server.send(200, "text/html", htmlRes);
}

void setup() {
delay(1000);
Serial.begin(9600);
Serial.println();

WiFi.softAP(ssid, password);

IPAddress apip = WiFi.softAPIP();
Serial.print("visit: \n");
Serial.println(apip);
server.on("/", handleRoot);
server.on("/LEDOn", handleLedOn);
server.on("/LEDOff", handleLedOff);
server.begin();
Serial.println("HTTP server beginned");
pinMode(LoadPin, OUTPUT);
digitalWrite(LoadPin, stateLED);
}

void loop() {
server.handleClient();
}
User avatar
By Dean24
#76557 I just got one of these ESP-01 plus 1 ch relays from China a couple days ago. The back of the relay bd says they are up to V3 now. but of course I couldn't get it to work. I wanted to use the Blynk app for my iPhone as it looked a reasonably straight forward task and I was familiar with the Arduino bd but not the ESP8266.

After a lot of reading and trial and error (including this thread) I could get as far as toggling the GPIO0 or GPIO2 but didn't want to hack the board as so many on this thread have done by connecting the GPIO to a transistor to drive the relay. I found once the blynk app had written to drive the GPIO0 or 2, I could no longer get my arduino code to then read these pins and drive the relay via a serial write to the onboard chip. Not having used Blynk before I didn't realize the potential to write to virtual pins.

So, once I setup my Blynk button to turn V0 virtual pin on or off, this following bit of arduino code flashed to the generic 8266 bd on the relay bd worked like a charm. Note: I unplugged the 8266 bd and temporarily tied GPIO0 to ground and then plugged it into a USB to ESP8266 WiFi module Adaptor to load the code via the Arduino app.

Hope this helps somebody to take a few less steps than I did.

/*control relay looking at virtual pin sent from Blynk and serial writing commands to chip onboard Relay board - works */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "yourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "yourSSID";
char pass[] = "yourPassword";

byte relON[] = {0xA0, 0x01, 0x01, 0xA2}; //Hex command to send to serial for open relay
byte relOFF[] = {0xA0, 0x01, 0x00, 0xA1}; //Hex command to send to serial for close relay

void setup()
{
// Debug console
Serial.begin(9600);


Blynk.begin(auth, ssid, pass);
// You can also specify server: (Blynk sample code)
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}

// Relay on off
BLYNK_WRITE(V0) {
int button = param.asInt(); // read button
if (button == 1) {
Serial.write(relON, sizeof(relON));
}
else {
Serial.write(relOFF, sizeof(relOFF));
}
}

void loop()
{
Blynk.run();
}