Hi guys,
i need to connect my Arduino that will check if button is pressed or not.
I needed also if Arduino was connected or not and I chose “notify when hardware goes offline” in notification settings.
Why Arduino goes offline when I press the button on pin 2?
I can use it only if I close serial monitor and run it again.
Another question: when I press button, in serial monitor I see a lot of “Button pressed”, but I press button only one time!!
Hope someone help me…
here code:
#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[] = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip ( 192, 168, 1, 73);
IPAddress dns_ip ( 8, 8, 8, 8);
IPAddress gateway_ip ( 192, 168, 1, 254);
IPAddress subnet_mask(255, 255, 255, 0);
#define W5100_CS 10
#define SDCARD_CS 4
void notifyOnButtonPress()
{
// Invert state, since button is “Active LOW”
int isButtonPressed = !digitalRead(2);
if (isButtonPressed) {
Serial.println(“Button is pressed.”);
// Note:
// We allow 1 notification per 15 seconds for now.
Blynk.notify("Yaaay... button is pressed!");
}
}
void setup()
{
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
Serial.begin(9600);
Blynk.begin(auth, “blynk-cloud.com”, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
// Setup notification button on pin 2
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), notifyOnButtonPress, CHANGE);
}
void loop()
{
Blynk.run();
}