Arduino with WiFi module not communicating with Blynk 2.0 app

Hello. I have tried a simple circuit using an Arduino UNO board with an esp8266 WiFi Module interfaced. I am also using Blynk 2.0. I have troubles communicating with the Blynk app to my Arduino board. The relay is not triggering.

#define BLYNK_TEMPLATE_ID           "TMPLMViRV5PY"
#define BLYNK_DEVICE_NAME           "TEST WIFI"
#define BLYNK_AUTH_TOKEN            "AUTH"



#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 9600
#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;
              }
             else{
              digitalWrite(RELAY_PIN, LOW); // turn off relay 1
              toggleState = 0;
              }
             delay(200);
}

BLYNK_CONNECTED()
{
  // Request the latest state from the server
  Blynk.syncVirtual(VPIN_BUTTON);
}

// When App button is pushed - switch the state

BLYNK_WRITE(VPIN_BUTTON) 
{
  toggleState = param.asInt();
  digitalWrite(RELAY_PIN, toggleState);
}

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

}
void without_internet()
{
  if (digitalRead(BUTTON) == LOW) {
      relayOnOff;
    }

}
void setup()
{

  pinMode(RELAY_PIN, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);
  digitalWrite(RELAY_PIN, toggleState);

  // Debug console
  Serial.begin(115200);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

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

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

If there is any suggestion or any fix that i can do. Any feedback is appreciated

How are things powered? The controller, ESP, relay, or relay board? Schematics would tell.

The ESP8266 WiFi module is connected to the 3.3V pin of the UNO and the Relay is connected to the 5V pin of the UNO. They both share a common ground. And the lock is connected to a 9v power supply battery pack.

      relayOnOff();

in without_internet too

What current does the ESP draw? How hot does the voltage regulator on the UNO get? It might shut down being overloaaded.
Give facts about the 9 volt battery pack.
Powering the relay from the 5 volt pin is bad. Give the relay separate power.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.