Need help communicating with relay on button app

I am using an Arduino UNO board with an ESP8266 interfaced with it. And i am also using a solenoid lock that is connected to a relay. This is my first time handling these devices so i want to get some help. The relay on activation seems to be working but it does not communicate with the button on my Blynk.Cloud dashboard after the program has initialized. I want to make it so that when the button on the app is pressed. The relay will trigger and so does the solenoid lock.

#define BLYNK_TEMPLATE_ID           "TMPLMViRV5PY"
#define BLYNK_DEVICE_NAME           "TEST WIFI"
#define BLYNK_AUTH_TOKEN            "m-NbVhz5dHeT6AzfMjZ_FhwXqQ8NJl_F"

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "TestSSID";
char pass[] = "TestPassword";

int toggleState = 1;

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

#define ESP8266_BAUD 38400
#define BUTTON 5
#define VPIN_BUTTON V1
#define RELAY_PIN 8
ESP8266 wifi(&EspSerial);

void relayOnOff(int relay){

               if(toggleState == 0){
              digitalWrite(RELAY_PIN, HIGH); // turn on relay 1
              toggleState = 1;
              digitalWrite(RELAY_PIN, LOW); // turn off relay 1
              toggleState = 0;

  // Request the latest state from the server

// When App button is pushed - switch the state

  toggleState = param.asInt();
  digitalWrite(RELAY_PIN, toggleState);

void with_internet(){
  if (digitalRead(BUTTON) == LOW) {
      // Update Button Widget
      Blynk.virtualWrite(VPIN_BUTTON, toggleState);

void without_internet()
  if (digitalRead(BUTTON) == LOW) {

void setup()

  digitalWrite(RELAY_PIN, toggleState);

  // Debug console

  // Set ESP8266 baud rate

//  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  Blynk.begin(auth, wifi, ssid, pass, "", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

void loop()

Is there a particular reason why you’ve chosen this setup?
It’s far from ideal and will cause you some issues.

The Uno doesn’t have enough processing power to emulate a hardware serial port using the SoftwareSerial library at this baud rate. As a result, you’ll suffer disconnections and other issues when communicating with Blynk.

Read this for more info…

These functions aren’t being called, so are redundant…

Thar also means that this function is redundant as well…

In addition, you’ll have no functionality without an internet connection using this code, as you are using Blynk.begin, which is a blocking function. All code execution will stop at the Blynk.begin command if the ESP can’t make a connection with the internet or the Blynk server.

It would be useful to see what your serial monitor shows, and it would help you with debugging if you added some serial print commands to your various functions to allow you to track program flow and variable values.


Thank you for the swift reply. As to answer your question as to why I am using an Arduino is that I was actually testing a simple solenoid lock circuit on 3 devices (Arduino, NodeMCU and Raspberry Pi) in just a simple system where a solenoid lock will lock and unlock from a button press on the app and record their response time. So i was setting up a lock code for every device. But cannot seem to get a working code that can be applied to the 3 devices.

You won’t be able to do that, especially as the Pi doesn’t run C++.

I’d focus on the NodeMCU, at least to begin with.


I understand and thank you for your insight. In terms of this particular Arduino code. Are there any specific codes that i may use or change so that it may successfully communicate with the circuit? Any feedback or suggestion is greatly appreciated.

This is a good example

Your first issue is to reconfigure the ESP-01 to communicate at 9600 baud, and then change your sketch to suit. How you do that will depend on the hardware you have available to you.


I’ve closed this topic as you’ve created another one relating to running similar code on an ESP32 board.