BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

ESP-01 and HW-655 Relay not working with Virtual Pin

I have been trying to get a ESP-01 and HW-655 relay board. I understand that the serial code needs to be sent via the esp to another chip on the relay board

I have loaded the blink code that operates the relay using this serial information. Works fine

I have got Blynk talking to the ESP-01 and I can turn the blue LED on and off on GPIO1

Tried using the Virtual pin to run the code to send the serial string. When I press the button on the IOS app nothing happens. The GPIO Pin will turn the LED on perfect.

I am sure I am missing something really simple but can not work it out.

I am using Blynk server and Blynk Library version 0.6.1

'/*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();
}'

This Serial.begin command isn’t for the debug console, it’s for the communication with the “other chip”.

Some other code examples using this hardware use a baud rate of 115200 to communicate with the “other chip” and if this is the baud rate that it’s listening on then you’ll need to match this rate…

Pete.

Thanks for the suggestion. Just tried that and no difference.

This is the communication to the relay that works without blynk

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

int ledState = false;
unsigned long previousMillis = 0;
const long interval = 2000; //  2 seconds

// the setup function runs once when you press reset or power the board
void setup() {
 // initialize serial:
 Serial.begin(9600);
}

// the loop function runs over and over again forever
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;
   }   
 }
}```

@flyonly please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

This line needs to be removed. It’s sending unwanted debug information to your relay controller chip.

Pete.

I have done that. No change

Added the LED into the subroutine to see if it was working. If I turn V0 on the LED does light up. Its like the BLYNK_WRITE(V0) is not sending the Serial.write

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

What baud rate are you using now, and what do you have attached to pin V0, and how is it configured in the app? (screenshot would be useful).

Pete.

Also, GPIO1 on the ESP-01 is the Serial TX pin, so pulsing this with HIGH/LOW data bits will mess-up the serial communications.
Also, if you’ve added a pinMopde(1,OUTPUT) statement (which would be needed to turn the LED on/off via digitalWrite commands) then you need to remove it, as this will also corrupt the serial data communications.

Pete.

I have reset the baud rate to 9600 because it made no difference. It did communicate as a relay blink without Blynk at this rate.

V0 has the serial statement

I only added digitalWrite(1,LOW); as a test.

I do have a second button which is GP1 that I was testing the communication by activating the LED. I will remove this button tonight.

As your working sketch (which you didn’t share until later) uses 9600 then this is the correct baud rate and is what you MUST use.

Yes, anything that messes with GPIO1 will be a problem.

Pete.

Pete

Thank you. You have solved my issue. As soon as I have taken out the GPIO button on the Blynk app the relay works perfect.

Now I want to use a GPIO input to see if the garage door is open or closed with a reed switch. I should use GPIO00 or GPIO02 for that?

Thanks again

GPIO2 is safer. If GPIO0 is pulled LOW at start-up then it will prevent the ESP-01 from booting correctly.

Pete.