My device keeps switching online and offline every few sec

Hello everyone,
I am new into Blynk and Arduino Uno
I have a problem somewhere, maybe in my device, or it Blynk console as it keeps switching offline every few sec.
I don’t know what is the problem exactly.
Below is some info, that may help:

  1. sketch
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial

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

char auth[] = BLYNK_AUTH_TOKEN;

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

const int redLedPin          = 7;
const int greenConnectionPin = 8; // The LED on this pin will turn on the the car is connected to Blynk

/*car init*/

const int in1 = 5; // in1,2 for right wheel
const int in2 = 6;
const int in3 = 9; // in3,4 for left wheel
const int in4 = 10;

void moveBackward(int speed) {
  analogWrite(in1, 0);
  analogWrite(in2, speed);
  analogWrite(in3, speed);
  analogWrite(in4, 0);
}

void moveForward(int speed) {
  analogWrite(in1, speed);
  analogWrite(in2, 0);
  analogWrite(in3, 0);
  analogWrite(in4, speed);
}

void turnLeft(int speed) {
  analogWrite(in1, speed);
  analogWrite(in2, 0);
  analogWrite(in3, speed);
  analogWrite(in4, 0);
}

void turnRight(int speed) {
  analogWrite(in1, 0);
  analogWrite(in2, speed);
  analogWrite(in3, 0);
  analogWrite(in4, speed);
}

void stopMove() {
  analogWrite(in1, 0);
  analogWrite(in2, 0);
  analogWrite(in3, 0);
  analogWrite(in4, 0);
}

BLYNK_WRITE(V0)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V0 to a variable
  digitalWrite(redLedPin,pinValue);
}

int Xvalue = 0;
int Yvalue = 0;

BLYNK_WRITE(V1)
{
  Serial.println(millis());
  Xvalue = param.asInt();
  Serial.print("X: ");
  Serial.println(Xvalue);
}

BLYNK_WRITE(V2)
{
  Serial.println(millis());
  Yvalue = param.asInt();
  Serial.print("Y: ");
  Serial.println(Yvalue);  
}

void setup()
{
  // Debug console
  Serial.begin(115200);

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

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

  pinMode(redLedPin,OUTPUT);
  pinMode(greenConnectionPin,OUTPUT);
  digitalWrite(greenConnectionPin, LOW);

   //motor
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);

}

void loop()
{
  Blynk.run();

  if (!Blynk.connected()) {
    digitalWrite(greenConnectionPin, LOW);
    Serial.print("offline!");
    bool result = Blynk.connect();
    Serial.println(result);
  } else {
    digitalWrite(greenConnectionPin, HIGH);
  }

  if (Yvalue >= 5) { // Actually forward
    moveForward(150); 
  } else if (Yvalue <= -5) { // Actually backward
    moveBackward(150);
  } else if (Xvalue >= 5) {
    turnRight(255);  // Actually a right turn
  } else if (Xvalue <= -5) {
    turnLeft(255); // Actually left turn
  } else {
    stopMove();
  }
}
  1. Please have a look for the attached screenshots
    Thanks for your help

@firastayemabed78 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:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

You should read this…

in particular the bit that says…

Basic Principals

Communication Speed (Baud Rate)

Your MCU board (Uno etc) and your peripheral device need to be talking to each other at the same rate. If not then they won’t be able to understand each other.

If you’re using a SoftwareSerial port to communicate with your peripheral then don’t use a baud rate higher than 9600, because the Uno etc doesn’t have enough processing power to emulate a serial port at higher communication speeds.

Pete.

Thank Pete for your answer.
But how can I set the baud rate to 9600, as the AT commands are not responding to my Arduino Uno ?
Can you please help me to set it to 9600

Thanks

What does this mean?

Do you have an FTDI (TTL to USB) adapter?

Pete.

I have USB cable connected to Arduino.
Through Arduino IDE , I can unload the sketch , but I am not able to execute AT commands,
I got no response at all

So is that a “No” to the question…

Pete.

That’s correct, no cable from ttl to usb

In that case I can’t help.

Pete.

Can’t I change the baud rate using a sketch?

No.
There may be ways to use your Arduino to reprogram your ESP-01, but it’s not something I’ve ever tried.
TBH, the use of an Arduino + ESP-01 as an IoT platform is a really bad choice, and you’d be far better using a NodeMCU or ESP32 with built-in WiFi connectivity.
But, if you want to stick with the prehistoric Arduino then picking-up an FTDI to reprogram your ESP-01 is probably a good idea.

Also, I see that you’re using a breadboard to handle the difficult task of hooking-up the ESP-01 to your Arduino.
Breadboards are bad news when it comes to reliability, as they tend to have (or develop after time) high resistance connections.

Pete.

But I have ESP8266
Please have a look for tye photo

Yes, in an ESP-01 package.

Pete.