I have created a project using esp8266. It will show a notification when the door is open. I have coded from blynk example. But after uploading the code to the device,it starts automatically again and again. I can see, uour device is connected on blynk. May be, it restarts. Sometimes, it is disconnected.
I have used the code below.
[Unformatted portion of code removed by moderator]
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "4k1JfmpomK69_N1LP8goni8DVSVs7F4r";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Safwan";
char pass[] = "@2255222";
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 5 seconds for now.
Blynk.notify("Yaaay... button is pressed!");
// You can also use {DEVICE_NAME} placeholder for device name,
// that will be replaced by your device name on the server side.
//Blynk.notify("Yaaay... {DEVICE_NAME} button is pressed!");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), notifyOnButtonPress, CHANGE);
}
void loop()
{
Blynk.run();
}
@Kayyum_Uddin ,brother it shows in blynk that my device is connected and after a while it shows my device is disconnected. I uploaded the code you have written.
@Kayyum_Uddin
bro.
Can you fix the code please. In my project, i have to connect two wires from magnetic reed switch. 1 in D1 and 1 in GND of esp8266.
When the switch is far from the magnet it will send me a notification. But with this code it sends me a notification when i supply power on the module. It sends wrong notification. It automatically sends a notification after 10 or 16 seconds that the door is open but i did not even open it.
help me please!
Can you fix the code please. In my project, i have to connect two wires from magnetic reed switch. 1 in D1 and 1 in GND of esp8266.
When the switch is far from the magnet it will send me a notification. But with this code it sends me a notification when i supply power on the module. It sends wrong notification. It automatically sends a notification after 10 or 16 seconds that the door is open but i did not even open it.
@kirohan please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```
@kirohan please do not tag Blynk developers in posts like this.
If you do this again your account will be suspended.
Please treat this as your one and only warning on this issue.