ESP8266 Relay Module not working with Blynk [solved]

This is my first project with ESP and Blync and I’m stuck trying to get it work… So hardware is ESP01, serial communication with lctech.cc 4ch relay board (also tested on 1ch), Blynk cloud server, Blynk library v0.5.3
What is confusing for me - this code https://www.esp8266.com/viewtopic.php?p=66327#p66327 is working so my hardware is not damaged
BUT
this code with Blynk library ESP8266 Relay Module working with Blynk not…
Code is pretty easy so what is wrong? Please advice me what to test more or give me right direction

(I just started with and 8266)… mine hung the first time with Blynk too…

i had the wrong auth code… (and hadn’t turned on the serail monitor for debug output)…

please post your code , what is wrong?
connexion ? auth ? other ?
detail your issue

I provided exact links with exact code that I used except of course my wifi and auth. My Blynk Android app shows that my project is online so there is no auth problems. This is my Blynk code:

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

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

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

// Your WiFi credentials.
char ssid[] = "ssid";
char pass[] = "pw";

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt();
  if (pinValue == 1) {
    Serial.write(rel1ON, sizeof(rel1ON));
  } else {
    Serial.write(rel1OFF, sizeof(rel1OFF));
  }
}

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

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

when I click Blynk app button for virtual pin V1 blue light on ESP01 also makes one blink
this code is working that is relay is blinking:

void loop() {
 unsigned long currentMillis = millis();
  if(currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;   
    if (ledState == true) {
      Serial.write(relON, sizeof(relON));     // turns the relay ON
      ledState = false;
    } else {
      Serial.write(relOFF, sizeof(relOFF));   // turns the relay OFF
      ledState = true;
    }    
  }                      // wait for a second
}

Just because someone has posted some code, it doesn’t mean that it actually works.
The code you’e using includes the software serial library, which isn’t actually used, which leads me to believe that the code was slightly dodgy.

Pete.

Give some more info @brasta. is your relay active high or low?
are you using gpio2 pin to trigger your relay?
are you using a transistor in your circuit?
did you flash the esp-01 using the correct settings etc?

the second sketch i think relates to a specific relay module , which i think uses gpio 0 and not gpio 2, try it and see?

@brasta: I’ve tested the code and it sends out the data on the Serial.
Your button in the app is assigned to V1 and set to “Switch”, right?

Then which part of this topic https://community.blynk.cc/t/esp8266-relay-module-working-with-blynk/22051 marked as “Solved” ? :slight_smile:

In my first post i wrote that I have ESP8266 relay module in which ESP01 communicates with relay board in serial sending TX command and this code work as espected that is it turn on and of my relay:

..
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
..
Serial.write(relON, sizeof(relON));     // turns the relay ON
Serial.write(relOFF, sizeof(relOFF));   // turns the relay OFF
..

Using Blynk these lines of code do not turn on or off relay…

1 Like

yes

I’v got it work! Problem is strange but it seems that it related with communication chip on relay board. Relay started to work when I changed

Serial.begin(9600);

to

Serial.begin(115200);

I’d assume that the original topic was marked as solved at the point when the OP felt that the original question had been answered. Three months later the code you’re trying to use was tagged on to the end of the topic by a user who hasn’t posted anything else, and has spent the grand total of 25 minutes in the forum.

Anyway, glad you’ve got it working. Did you remove the software serial declaration?

Pete.

if you are talking about this line then yes
#include <SoftwareSerial.h>

1 Like

Estou com um problema semelhante o código descrito funciona com um esp-8266 c/ um relé, mas não funciona com uma placa semelhante c/ 4 relé

I’d recommend that you start a new topic and explain in detail EXACTLY what type of board you are using and how you have wired and powered your relays, whether the relays are active HIGH or LOW, and post your code (correctly formatted of course).

Pete.