Doesn¨t stop sending mails

I try to send a mail when de PIR sensor is activated. But wen I charge the program starts to send emails and doesnt stop.I dont now how can i solve this.

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

char auth[] = "3859c00afb3b4ddeabeac179be498541";
char ssid[] = "WIFI ";
char pass[] = "946255638";

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(10, 11); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

void setup()
  // Debug console

  // Set ESP8266 baud rate

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

void loop()
  int value= digitalRead(A0);
  if(value == HIGH)
    "", "Subject: Button Logger", "You just pushed the button...");



Hi Alex95,
Try to write this part outside the void loop. To do that you need to create a new void, It can be: void email();

when A0 goes high, call a new function that sends the mail, and keeps the time the email was sent, and does not send another email until the desired time between emails has elapsed.

In your code, while the A0 is high it will try to send send thousands of emails per second. Blynk will probably only send one every 5 seconds, but you dont want that many either.

@Alex95 As mentioned, you need to use logic code, flags and timers to regulate the sending of emails… or anything else that can potentially happen too much too fast.

There have been many topics about this already and there is sure to be some examples floating around you can search for. Here is a generic timed action example I put together that, with some study, you could work into a “send email only once every X amount of time as needed” process

Also, you need to understand how to avoid populating such code in your void loop() when running timing and communications sensitive applications like Blink and other IoT.