Hello everyone, I’m having a problem with my project with ARDUINO UNO and I can not solve it.
I set a PIN DIGITAL (ex. PIN 2) that when it is HIGH send me an email, but the problem is when this PIN becomes HIGH, Arduino send me an email but then becomes increasingly ONLINE and therefore unusable.
When Arduino sends the email, it quickly becomes offline … that it disconnect from the Server Blynk and no longer communicates with the sensors and the APP.
#include <Blynk.h>
#define BLYNK_PRINT Serial
/* Set this to a bigger number, to enable sending longer messages */
//#define BLYNK_MAX_SENDBYTES 128
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
#define W5100_CS 10
#define SDCARD_CS 4
IPAddress server_ip (46, 101, 143, 225);
// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xAB, 0xED, 0xAF, 0xEB, 0xDE, 0xBD };
IPAddress arduino_ip ( 192, 168, 1, 13);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip ( 192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 0);
void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***
// Let's send an e-mail when you press the button
// connected to digital pin 2 on your Arduino
int isButtonPressed = !digitalRead(2); // Invert state, since button is "Active LOW"
if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
Blynk.email("your_email@mail.com", "Subject: Button Logger", "You just pushed the button...");
// Or, if you want to use the email specified in the App (like for App Export):
//Blynk.email("Subject: Button Logger", "You just pushed the button...");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
Blynk.begin(auth);
// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}
void loop()
{
Blynk.run();
}
#include <Blynk.h>
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
#define W5100_CS 10
#define SDCARD_CS 4
void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***
// Let's send an e-mail when you press the button
// connected to digital pin 2 on your Arduino
int isButtonPressed = !digitalRead(2); // Invert state, since button is "Active LOW"
if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
Blynk.email("your_email@mail.com", "Subject: Button Logger", "You just pushed the button...");
// Or, if you want to use the email specified in the App (like for App Export):
//Blynk.email("Subject: Button Logger", "You just pushed the button...");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
Blynk.begin(auth);
// You can also specify server:
//Blynk.begin(auth, "blynk-cloud.com", 8442);
//Blynk.begin(auth, IPAddress(192,168,1,100), 8442);
// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepient's "e-mail address", "Subject" and the "message body"
Blynk.email("your_email@mail.com", "Subject", "My Blynk project is online.");
// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}
void loop()
{
Blynk.run();
}
I see you are using a physical button press, and on an interrupt… you might be experiencing button bounce, effectively trying to email multiple times in a single press… and possibly on both rising and falling signals (I haven’t used interrupts enough to be sure on that one).
Either way… not good. Don’t need to use interrupt unless really required for timing precision and use some form of debouncing routine in your code. As referenced here: https://www.arduino.cc/en/Tutorial/Debounce