Buffer over flow problem

First i controled a led using blynk it worked fine but when i added two more sensor Buffer over flow problem started is there any solution .(I am using ARDUINO uno AND ESP8266)

#define BLYNK_PRINT Serial


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

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "a9********";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********";
char pass[] = "********";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

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

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

#define DHTPIN 5          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
//rpm
int irpin=5;
int enter=0;

 

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.

//switch
// Set your LED and physical button pins here

const int ledPin = 7;
const int btnPin = 8;

BlynkTimer timer;

void checkPhysicalButton();

int ledState = LOW;
int btnState = HIGH;

// Every time we connect to the cloud...
BLYNK_CONNECTED() {
  // Request the latest state from the server
  Blynk.syncVirtual(V2);

  // Alternatively, you could override server state using:
  //Blynk.virtualWrite(V2, ledState);
}

// When App button is pushed - switch the state
BLYNK_WRITE(V2) {
  ledState = param.asInt();
  digitalWrite(ledPin, ledState);
}

void checkPhysicalButton()
{
  if (digitalRead(btnPin) == LOW) {
    // btnState is used to avoid sequential toggles
    if (btnState != LOW) {

      // Toggle LED state
      ledState = !ledState;
      digitalWrite(ledPin, ledState);

      // Update Button Widget
      Blynk.virtualWrite(V2, ledState);
    }
    btnState = LOW;
  } else {
    btnState = HIGH;
  }
}


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

  // 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.com", 8442);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8442);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);

  //switch
  pinMode(ledPin, OUTPUT);
  pinMode(btnPin, INPUT_PULLUP);
  digitalWrite(ledPin, ledState);
//rpm
pinMode(irpin,INPUT);
  
  // Setup a function to be called every 100 ms
  timer.setInterval(100L, checkPhysicalButton);
}

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

}
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
    int c,i,count=0,rpm,v;
  for(i=0;i<=1000;++i)
  {
    c=analogRead(irpin);
    if(c<400)
    {
      enter=1;
      }
      if ( (c>400)&& (c>v)&& (enter==1))
      {
        count++;
        enter=0;
        }
        delay(1);
        v=0;
   
  }
  
  rpm=count*53.5;
  Blynk.virtualWrite(V7, rpm);

}

I fixed you code formatting… you need to use the backtick, not the tilde character.

You are basicly overloading something, either via serial prints or more likely in your Arduino/ESP connection. Search around with Google and on this forum for the keywords and/or error Buffer Overflow, ESP, Arduino,etc.

Have you tried increaing the timer for th checkPhysiclButton to for example 500 or 1000? I also see a delay in your for loop. If added up it can lead to 600ms delay which is not good. Why is there a for loop anyway? Can you try and comment that out and see how it goes. I suspect the problem is there, but not sure.

I tryed by removing the delay in the loop and the result was same . but when i removed the ir sensor and adjusted READING RATE i got the same error 2-5 min later .(i thing the error is because of sending the valve at the same time !!!) Any solution?

Well, there are several possibilities why this could happen. Judging by your sketch I see you are using the ESP as a shield on the Arduino. The problem is 80% in there somewhere. ESP as a shield is notoriously unstable. Especially if you are using softwareserial.

Is there any way you can program the ESP directly without using an Arduino? That would probably solve your problem.

If not, I highly recommend you buy a Wemos D1 Mini. This is the most stable and simple solution for using Wifi. It has a USB connection and you can program it directly from the Arduino IDE. It also has more memory for bigger sketches, runs much more stable and is just a better alternative.

I second that. The NodeMCUs work pretty good as well. It is so much easier working with the DEV boards than trying to piece it all together yourself. Plus the cost difference is not all that much.

The only advantage to the pieced together solution (esp-01 or esp-12e) may be when making a battery powered device, as you can eliminate the unwanted circuity to reduce energy consumption.

1 Like