I have done my all connection as well as coding with ESP8266 connected to Arduino Mega 2560, but one error is showing there i.e, ESP is not responding!

ERROR
ESP01 is creating its own wifi and we are even able to connect it with mobile and also during flash it is showing that esp is connected to wifi
But in IDE serial monitor shows
ESP is not responding

THIS IS MY PROGRAM CODE


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

char auth[] = "MJNZGb4y3Mr3Nr6etyiGBw6-sOq-wTn4";
char ssid[] = "Password is 12345";
char pass[] = "9969425503++<<AAKASH.YADAV>>++9869220835.9969738314";

const int outputpin1 = 52;
const int outputpin2 = 53;
int servoPin1 = 8; 
int servoPin2 = 9; 
int servoPin3 = 12;
int servoPin4 = 11;  
int stop1=4;
int stop2=7;
int back1=2;
int back2=5;
int pwm1=3;
int pwm2=6;
int pos=150;
int pos1=30;
int pos2=150;
int val1;
int val2;
boolean trash;
 
#define EspSerial Serial1
#define ESP8266_BAUD 115200
#define bintrig1 22
#define binecho1 23
#define bintrig2 24
#define binecho2 25
#define lefttrig 26
#define leftecho 27
#define righttrig 28
#define rightecho 29
#define rttrig 30
#define rtecho 31
#define rbtrig 32
#define rbecho 33
#define lttrig 34
#define ltecho 35
#define lbtrig 36
#define lbecho 37

ESP8266 wifi(&EspSerial);

BlynkTimer timer;
Servo myservo1;
Servo myservo2;
Servo mainservo;
Servo binservo; 

void myTimerEvent()
{
  Blynk.virtualWrite(V5, millis() / 1000);
}

void setup()
{
  
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
  pinMode(outputpin1, INPUT); 
  pinMode(outputpin2, INPUT); 
  myservo1.attach(11);
  myservo2.attach(12);
  mainservo.attach(8);
  binservo.attach(9);
  binservo.write(0);
  myservo1.write(pos1);
  myservo2.write(pos2);
  mainservo.write(pos);
  pinMode(stop1, OUTPUT); 
  pinMode(stop2, OUTPUT); 
  pinMode(back1, OUTPUT); 
  pinMode(back2, OUTPUT); 
  pinMode(pwm1, OUTPUT); 
  pinMode(pwm2, OUTPUT); 
   
  pinMode(bintrig1,OUTPUT);
  pinMode(binecho1,INPUT);
  pinMode(bintrig2,OUTPUT);
  pinMode(binecho2,INPUT);
   pinMode(lefttrig,OUTPUT);
  pinMode(leftecho,INPUT);
   pinMode(righttrig,OUTPUT);
  pinMode(rightecho,INPUT);
   pinMode(rttrig,OUTPUT);
  pinMode(rtecho,INPUT);
   pinMode(rbtrig,OUTPUT);
  pinMode(rbecho,INPUT);
   pinMode(lttrig,OUTPUT);
  pinMode(ltecho,INPUT);
   pinMode(lbtrig,OUTPUT);
  pinMode(lbecho,INPUT);
}
BLYNK_WRITE(1) 
{
  if (param.asInt()==1) {       
        pin1_activated();   
    } 
    
  }
  BLYNK_WRITE(3) 
{
  if (param.asInt()==1) {       
        forward();
        delay(100);
        Stop();   
    } 
   
  }
BLYNK_WRITE(4) 
{
  if (param.asInt()==1) {       
        backward();
        delay(100);
        Stop(); 
        
    } 
    
  }
  BLYNK_WRITE(5) 
{
  if (param.asInt()==1) {       
        left(); 
        delay(100);
        Stop();
    } 
    
  }
   BLYNK_WRITE(6) 
{
  if (param.asInt()==1) {       
        right();
        delay(100);
        Stop();
    } 
  
  }
 BLYNK_WRITE(7) 
{
  if (param.asInt()==1) {       
        Stop(); 
    } 
    
  }
  BLYNK_WRITE(12) 
{
  if (param.asInt()==1) {       
        forward();   
    } 
    
  }
  BLYNK_WRITE(13) 
{
  if (param.asInt()==1) {       
        backward();   
    } 
    
  }
BLYNK_WRITE(2) 
{
  int x = param[0].asInt();
  int y = param[1].asInt();
  if(y>220)
  {forward();}
  else if(y<35)
  {backward();}
  else if(x>220)
  {right();}
  else if(x<35)
  {left();}
  else
  {Stop();}
}

int autostate;
BLYNK_WRITE(11) 
{
  autostate=param.asInt();
while(autostate==1){
  autonomous();}
 
  
  }
  
void autonomous(){
  int ldistance,rdistance,rtdistance,rbdistance,ltdistance,lbdistance,lduration,rduration,rtduration,rbduration,ltduration,lbduration;
   digitalWrite (lefttrig, HIGH);
   delayMicroseconds (1000);
   digitalWrite (lefttrig, LOW);
   lduration = pulseIn (leftecho, HIGH);
   ldistance = (lduration/2) / 29.1;
  
   digitalWrite (righttrig, HIGH);
   delayMicroseconds (1000);
   digitalWrite (righttrig, LOW);
   rduration = pulseIn (rightecho, HIGH);
   rdistance = (rduration/2) / 29.1;

  digitalWrite (rttrig, HIGH);
   delayMicroseconds (1000);
   digitalWrite (rttrig, LOW);
   rtduration = pulseIn (rtecho, HIGH);
   rtdistance = (rtduration/2) / 29.1;

   digitalWrite (rbtrig, HIGH);
   delayMicroseconds (1000);
   digitalWrite (rbtrig, LOW);
   rbduration = pulseIn (rbecho, HIGH);
   rbdistance = (rbduration/2) / 29.1;
  
  digitalWrite (lttrig, HIGH);
   delayMicroseconds (1000);
   digitalWrite (lttrig, LOW);
   ltduration = pulseIn (ltecho, HIGH);
   ltdistance = (ltduration/2) / 29.1;

   digitalWrite (lbtrig, HIGH);
   delayMicroseconds (1000);
   digitalWrite (lbtrig, LOW);
   lbduration = pulseIn (lbecho, HIGH);
   lbdistance = (lbduration/2) / 29.1;
while(ldistance<0){
  ldistance=399;}
  while(rdistance<0){
  rdistance=399;}
  while(rtdistance<0){
  rtdistance=399;}
  while(ltdistance<0){
  ltdistance=399;}
  while(rbdistance<0){
  rbdistance=399;}
  while(lbdistance<0){
  lbdistance=399;}


  aforward();
if(rtdistance<28||ltdistance<28){
    Stop();
    if(rdistance>28&&ldistance>28){
        if(rdistance>=ldistance){
          aright();
          delay(4000);
          Stop();}
          else if(rdistance<ldistance){
            aleft();
            delay(4000);
            Stop();}}
     else if(rdistance<28||ldistance<28){
         if(rdistance<28&&ldistance>28){
          aleft();
          delay(4000);
          Stop();}
          else if(rdistance>28&&ldistance<28){
            aright();
            delay(4000);
            Stop();}
            else if(rdistance<28&&ldistance<28){
              aright();
              delay(8000);
              Stop();}}       
        }
  
 if(lbdistance<20||rbdistance<20&&rtdistance>28&&ltdistance>28){
  Stop();
  delay(100);
  if(lbdistance<20&&rbdistance<20){
    abackward();
    delay(1300);
    Stop();
    pin1_activated();
    delay(1000);}
  else if(lbdistance<20&&rbdistance>20){
    aleft();
    delay(300);
    Stop();
    abackward();
    delay(1300);
    Stop();
    pin1_activated();
    delay(1000);}

   else if(lbdistance>20&&rbdistance<20){
    aright();
    delay(300);
    Stop();
    abackward();
    delay(1300);
    Stop();
   pin1_activated();
    delay(1000);}   
  }
  else {
    aforward();}
  
  
  



}

void Stop()
{
  analogWrite(pwm1, 0);
  analogWrite(pwm2, 0);
}

void left(){
  analogWrite(pwm1, 127);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
  analogWrite(pwm2, 127);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
  }
void aleft(){
  analogWrite(pwm1, 30);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
  analogWrite(pwm2, 30);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
  }
void right(){
  analogWrite(pwm1, 127);
  digitalWrite(back1, HIGH);
  analogWrite(pwm2, 127);
  digitalWrite(back2, HIGH); 
  }
  void aright(){
  analogWrite(pwm1, 30);
  digitalWrite(back1, HIGH);
  analogWrite(pwm2, 30);
  digitalWrite(back2, HIGH); 
  }

void backward(){
  analogWrite(pwm1, 127);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
  analogWrite(pwm2, 127);
  digitalWrite(back2, HIGH); 
  }  
void abackward(){
  analogWrite(pwm1, 30);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
  analogWrite(pwm2, 30);
  digitalWrite(back2, HIGH); 
  }  
  void forward(){
  analogWrite(pwm2, 127);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
  analogWrite(pwm1, 127);
  digitalWrite(back1, HIGH);
  }
void aforward(){
  analogWrite(pwm2, 30);
  digitalWrite(back1, LOW);
  digitalWrite(back2, LOW); 
  analogWrite(pwm1, 30);
  digitalWrite(back1, HIGH);
  }
void pin1_activated(){

 delay(1000);
    
    for (pos = 150; pos >= 45; pos -= 1) {
    mainservo.write(pos);              
    delay(7);                    
  }
    delay(1000);
    for (pos1=30,pos2=150;pos1>=0,pos2<=180;pos1-=1,pos2+=1){
    myservo1.write(pos1);
    myservo2.write(pos2);
    delay(15);}
    
    delay(1000);
    
for (pos = 45; pos <= 105; pos += 1) { 
    // in steps of 1 degree
    mainservo.write(pos);          
    delay(10);                     
  }
    
    delay(3000);
    val1=digitalRead(outputpin1);
   
    val2=digitalRead(outputpin2);
    
    if(val1==LOW||val2==LOW){
      binservo.write(180);
      delay(2000);
      }
      if(val1==HIGH&&val2==HIGH){
        binservo.write(0);
        delay(2000);
        }
       delay(4000); 
    for (pos = 105; pos <= 150; pos += 1) {    
    mainservo.write(pos);              
    delay(10);                       
  }
  delay(1000);
   for(pos1=0,pos2=180;pos1<=30,pos2>=150;pos1+=1,pos2-=1){
    myservo2.write(pos2);
    myservo1.write(pos1);
    delay(15);}
    delay(1000);
   
   }
   
   void Blynk_Delay(int milli)
{
  int end_time = millis() + milli;
  while (millis() < end_time)
  {
if (Blynk.connected())
{
  Blynk.run();
}
yield();
  }
}
void loop()
{
  int bin1duration,bin1distance;
digitalWrite (bintrig1, HIGH);
   delayMicroseconds (1000);
   digitalWrite (bintrig1, LOW);
   bin1duration = pulseIn (binecho1, HIGH);
   bin1distance = (bin1duration/2) / 29.1;
   Blynk.virtualWrite(V8,bin1distance);
   if(bin1distance<20){
   Blynk.virtualWrite(V9,"METALLIC BIN FULL");
   delay(1000);}
   else if(bin1distance>20){
    Blynk.virtualWrite(V9," ");
   delay(1000);}
   int bin2duration,bin2distance;
digitalWrite (bintrig2, HIGH);
   delayMicroseconds (1000);
   digitalWrite (bintrig2, LOW);
   bin2duration = pulseIn (binecho2, HIGH);
   bin2distance = (bin2duration/2) / 29.1;
   Blynk.virtualWrite(V10,bin2distance);
   if(bin2distance<20){
   Blynk.virtualWrite(V9,"NON METALLIC BIN FULL");
   delay(1000);}
   else if(bin2distance>20){
    Blynk.virtualWrite(V9," ");
   delay(1000);}

   
 Blynk.run();
 
  val1=digitalRead(outputpin1);
   delay(10);
    val2=digitalRead(outputpin2);
    delay(10);
 timer.run(); 
}```

Please edit your post and add triple backticks ( ``` ) before and after your sketch.

1 Like

Void loop must be cleaned like this, use timer to call functions

void loop()
{
Blynk.run();
timer.run();
}
2 Likes

Yes, also avoid using delay, you’re using a lots of them.

2 Likes

Sure and yield() has nothing to do in Blynk code :wink:

2 Likes

@Gunner sir please look into my problem,
i am hoping you will help me in finding the solution for this problem

It seems like you don’t want our help and you don’t want to listen to us so good luck

1 Like

Naah brother!!
Ur talkin about the program error and i am looking for the solution
That is I want to connect the esp8266 with the WiFi

The “ESP is not responding” message is usually caused by one of the following issues…

  • Your ESP-01 isn’t running the factory AT firmware. If the device has had a sketch uploaded to it at some point in the past then this will have overwritten the AT firmware, and you’ll need to reinstate the AT firmware.

  • Your ESP-01 isn’t connected correctly. This could be that the wrong pins have been used, or you’ve not connected Tx —> Rx and Rx —> Tx

  • You are trying to communicate with the ESP-01 at the incorrect baud rate. The default baud rate for the ESP-01 varies depending on the AT firmware version, and can be changed via an AT command.

  • The ESP-01 isn’t receiving sufficient power to enable it to function correctly.

Once you’ve figured out which one (or more) of these issues is causing your problem and then fixed it, you will then encounter multiple other problems including disconnections and lack of responsiveness because of the way that you’ve written your sketch.

You should read this:
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

Pete.

2 Likes

You can start with a simple sketch just to make sure everything is working fine

1 Like

Hello bro your problem is the baudrate I guess this is the code for garbage collecting robot .u have to change the baudrate to 115200 for esp and Arduino.
I too working with this code . But for me the automatic mode is not working perfectly blynk disconnects . Have u completed this project help me .

Hi,
Firstly i advise you to follow admins’ comments. Your blynk not going to work normally if you even solve coding problem.

About coding try this example :

//blynk auth information
#define BLYNK_TEMPLATE_ID “xxxxxxxxx”
#define BLYNK_DEVICE_NAME “xxxxxxxxxxxx”
#define BLYNK_AUTH_TOKEN “xxxxxxxxx”

// Send Blynk user messages to the hardware serial port…
#define BLYNK_PRINT Serial

//blynk library
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

//blynk auth
char auth[] = BLYNK_AUTH_TOKEN;

// wifi password, login
char ssid[] = “xxxxxxxx”;
char pass[] = “xxxxxxxx”;



// Define your ESP8266 baud rate:
#define ESP8266_BAUD 115200

// Tell the Blynk library to use the Hardware Serial port 1 for WiFi…
ESP8266 wifi(&Serial3);

BlynkTimer timer;

void setup()

{


// Initialise the debug serial port
   Serial.begin(115200);

// Initialise the Hardware serial1 port…
   Serial3.begin(ESP8266_BAUD);
   delay(10);
  Blynk.begin(auth, wifi, ssid, pass);


}

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