My project not work after disconnect usb cable

hi friends,
i just start and new in Blynk app…
i start my project to control 6 relay with Blynk app and i copy coding from our friend here (he post that coding 2015). all work fine when i upload coding and test all work (usb cable still connect to my laptop).
but when i disconnect usb cable and just run this project with power adopter all led (i use LED for testing before change to Relay ) blinking.
i use arduino uno and esp8266 wifi module.

Please post your formatted code.

i sorry i still new not sure how to post format coding here…hehehe

here my coding…

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h> // include Blynk ESP8266
#define BLYNK_PRINT Serial  // Comment this out to disable prints and save space

char auth[] = "***************************";
char ssid[] = "********";
char pass[] = "********";

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // ( RX, TX )
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);

//Relay in Pin XX
#define Relay1 10
#define Relay2 9
#define Relay3 8
#define Relay4 7
#define Relay5 6
#define Relay6 5

// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V1)
{
  int RelayStatus1 = param.asInt();
  if (RelayStatus1 == 1) {
    digitalWrite(Relay1, LOW);
  }
  else {
    digitalWrite(Relay1, HIGH);
  }
}

BLYNK_WRITE(V2)
{
  int RelayStatus2 = param.asInt();
  if (RelayStatus2 == 1) {
    digitalWrite(Relay2, LOW);
  }
  else {
    digitalWrite(Relay2, HIGH);
  }
}

BLYNK_WRITE(V3)
{
  int RelayStatus3 = param.asInt();
  if (RelayStatus3 == 1) {
    digitalWrite(Relay3, LOW);
  }
  else {
    digitalWrite(Relay3, HIGH);
  }
}


BLYNK_WRITE(V4)
{
  int RelayStatus4 = param.asInt();
  if (RelayStatus4 == 1) {
    digitalWrite(Relay4, LOW);
  }
  else {
    digitalWrite(Relay4, HIGH);
  }
}

BLYNK_WRITE(V5)
{
  int RelayStatus5 = param.asInt();
  if (RelayStatus5 == 1) {
    digitalWrite(Relay5, LOW);
  }
  else {
    digitalWrite(Relay5, HIGH);
  }
}

BLYNK_WRITE(V6)
{
  int RelayStatus6 = param.asInt();
  if (RelayStatus6 == 1) {
    digitalWrite(Relay6, LOW);
  }
  else {
    digitalWrite(Relay6, HIGH);
  }
}

void setup()
{

  pinMode(Relay1, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay1, HIGH); // Prevents relays from starting up engaged

  pinMode(Relay2, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay2, HIGH); // Prevents relays from starting up engaged

  pinMode(Relay3, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay3, HIGH); // Prevents relays from starting up engaged

  pinMode(Relay4, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay4, HIGH); // Prevents relays from starting up engaged

  pinMode(Relay5, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay5, HIGH); // Prevents relays from starting up engaged

  pinMode(Relay6, OUTPUT); // sets the digital pin as output
  digitalWrite(Relay6, HIGH); // Prevents relays from starting up engaged

  // communication with the host computer
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);

}

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

Glad you worked out how to post formatted code.

My experience with Arduino’s is that the Leonardo is the only one that explicitly waits for serial coms before proceeding with your sketch. So the Uno should be fine without the USB cable.

If it fails without the USB it suggests you have other problems which are hard to establish without Serial Monitor.

How are you powering the Uno and have you moved it further away from the router since you diconnected the USB. Range is not great with many ESP’s.

Suggest you go back to the USB for now and wander around your property, with a laptop and the Uno with shield, to see what Serial Monitor reports.

i use power adapter 12vdc and i just disconnect usb without move my project and my router je 2 meter from my esp8266.
before this i already done with project arduino uno + esp8266 + thingspeak.com all run fine without usb cable.

i think wifi range is no the problem.
it’s any problem with my coding causing it can’t work without usb cable?

I can’t see anything wrong with your code.

You say the LED’s (simulating the relays) are blinking when the USB is not connected. Blynk on and off repeatedly or blink to just off or just on?

What details are you seeing in your app?

Are the app buttons PUSH or SWITCH mode?

From your code it looks like your relays are active low (ergo HIGH off in setup(). Your LED’s are active HIGH and will therefore come on at bootup and if they are blinking it suggests your Uno is continuously restarting the sketch.

Describe the frequency and pattern of the blinking in more detail and what you see in the app.

my led repeatedly blinking.
at my app just normal only just show “device off line”.
i use switch mode.
let me try change arduino uno board first…mybe this one faulty. i updated later…

thanks

after change new uno board all ok now…my first uno board maybe have some problem with power supply module…now try to play around with this coding…thanks to mr Costas…

        BLYNK_WRITE(V1)
        {
          int RelayStatus1 = param.asInt();
          if (RelayStatus1 == 1) {
            digitalWrite(Relay1, LOW);
          }
          else {
            digitalWrite(Relay1, HIGH);
          }
        }

        BLYNK_WRITE(V2)
        {
          int RelayStatus2 = param.asInt();
          if (RelayStatus2 == 1) {
            digitalWrite(Relay2, LOW);
          }
          else {
            digitalWrite(Relay2, HIGH);
          }
        }

        BLYNK_WRITE(V3)
        {
          int RelayStatus3 = param.asInt();
          if (RelayStatus3 == 1) {
            digitalWrite(Relay3, LOW);
          }
          else {
            digitalWrite(Relay3, HIGH);
          }
        }


        BLYNK_WRITE(V4)
        {
          int RelayStatus4 = param.asInt();
          if (RelayStatus4 == 1) {
            digitalWrite(Relay4, LOW);
          }
          else {
            digitalWrite(Relay4, HIGH);
          }
        }

        BLYNK_WRITE(V5)
        {
          int RelayStatus5 = param.asInt();
          if (RelayStatus5 == 1) {
            digitalWrite(Relay5, LOW);
          }
          else {
            digitalWrite(Relay5, HIGH);
          }
        }

        BLYNK_WRITE(V6)
        {
          int RelayStatus6 = param.asInt();
          if (RelayStatus6 == 1) {
            digitalWrite(Relay6, LOW);
          }
          else {
            digitalWrite(Relay6, HIGH);
          }
        }

hi friend…this is i thing command 6 channel control for on/off right ?.
if i want set channel 6 is master switch ( that mean if channel 6 HIGH all channel will be turn off )
what should i do?

BLYNK_WRITE(V6)
        {
          int RelayStatus6 = param.asInt();
          if (RelayStatus6 == 1) {
            digitalWrite(Relay1, LOW);
            digitalWrite(Relay2, LOW);
            digitalWrite(Relay3, LOW);
            digitalWrite(Relay4, LOW);
            digitalWrite(Relay5, LOW);
            digitalWrite(Relay6, LOW);
          }
          else {
            digitalWrite(Relay1, HIGH);
            digitalWrite(Relay2, HIGH);
            digitalWrite(Relay3, HIGH);
            digitalWrite(Relay4, HIGH);
            digitalWrite(Relay5, HIGH);
            digitalWrite(Relay6, HIGH);
          }
        }

i already try this command before this but not work…
let me try 1 more time…
thanks friend…
i update result later