BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk, ESP8266 with pin interrupt


#1

Need help with my Home Security project.
Ran into problems with ESP8266 and PIRs, both transmitting on the 2.4 GHz band, causing interference and false positives.
Have since switched out most of the PIRs, in favor for radar, but it’s still not working to my satisfaction.
Don’t want to miss a single beat and am looking for a “Blynk with pin interrupt” solution.
A timer is simply not an option, in my opinion.
And turning off the WiFi does not work as there are still some PIRs in the system which could get false positives.

Is it possible?


#2

Interrupts work fine with Blynk. What have you tried so far?


#3

This is what I have got so far, probably making it too complicated!
Please look at the code and point me in the right direction. Really need to complete this project.
Thanks in advance.

void Setup() {
.
.
sleep();
}

void loop()
{
#ifdef OTA
ArduinoOTA.handle();
#endif

blynkr();
timer.run();
}

void blynkr()
{

if(MyEEPROM.activated && msm >= MyEEPROM.alarmONTime && msm <= MyEEPROM.alarmOFFTime) // Add keypad
{
Blynk.run();
sensors();
}
}

void sensors()
{
.
.

if (motion == LOW) {
sleep();
delay(100);
Serial.println(“Woke up from sleep - Low”);

}
}

void sleep() {

Serial.println(“Entering Sleep”);
WiFi.mode(WIFI_STA);
WiFi.disconnect();

wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open();
gpio_pin_wakeup_enable(GPIO_ID_PIN(PIR_PIN), GPIO_PIN_INTR_HILEVEL);
/// gpio_pin_wakeup_enable(GPIO_ID_PIN(PING_PIN), GPIO_PIN_INTR_LOLEVEL);

wifi_fpm_do_sleep(0xFFFFFFF);

if(WiFi.status() != WL_CONNECTED)
{
// digitalWrite(LStatus, LOW); // Desliga Saída
delay(250);
WiFi.begin(“","”);
Serial.println(“WiFi.connect”);
}
if(WiFi.status() == WL_CONNECTED && !Blynk.connected())
{
firstConnect = true;
// digitalWrite(LStatus, LOW); // Desliga Saída
delay(250);
Blynk.connect();
Serial.println(“Blynk.connect”);
}
delay(1000);
Serial.println(WiFi.localIP());
Serial.println(“Exiting Sleep”);
}


#4

first, you should study this picture :wink: and format your code to be human readable


#5

Yup please edit your post.

Also it looks like you have some very strange structure to your Blynk code. Doesn’t look right at all.

Will wait for you to edit your post, and please include your entire sketch, top to bottom.


#6

#define BLYNK_PRINT Serial

// Overhead garage door and/or Parking sensor sketch
// Send the sketch version information to the gateway and Controller

#include <SPI.h>
#include <ESP8266_PINS.h>
#include <SimpleTimer.h> // Standard BLYNK libraries
#include <TimeLib.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Required for LIGHT_SLEEP_T delay mode
extern “C” {
#include “gpio.h” //change to where you have saved gpio.h listed below
}

extern “C” {
#include “user_interface.h”
// uint16 readvdd33(void);
}

char SSID[11] = “******”;
char password[13] = "******;

#define PIR_PIN 5 // SonOff/ESP8266 pin D1/5, tied to PIR (motion) sensor.

unsigned long SLEEP_TIME = 8.64e+7; // Sleep time(1 day) between reads (in milliseconds)
//float distance = 0;

//----------------BLYNK Virtual Pins -----
#define DOOR_MOTION_LED V1 // LED, Motion @ garage Door
#define WINDOW_MOTION_LED V2 // LED, Motion @ Garage Window(s)
#define DOOR_OPEN_LED V3 // LED, Garage Door OPEN
#define DOOR_PARTIALLY_OPEN_LED V4 // LED, Garage Door PARTIALLY OPEN
#define DOOR_CLOSED_LED V5 // LED, Garage Door CLOSED
#define CLOSE_DOOR_RELAY V12 // RELAY, for Opening/closing garage door
#define SOUND_LED V13 // LED, loud Sound detected
#define DOOR_OPENING V14 // Garage Door Opening in CM
#define ALARM_LED V15 // LED, ALARM triggered

// Timer for blynking
SimpleTimer timer;

//********************** Misc Variables **********************
int old_motion = 0; // variable to store a request for sleep

void setup()
{
Serial.begin(9600);
Serial.println(“Entering Setup”);

pinMode(PIR_PIN, INPUT_PULLUP); // PIR (motion) sensor pin
digitalWrite(PIR_PIN, LOW); // disable pullups
// pinMode(GREEN_LED, OUTPUT); // sets the digital pin as output
// pinMode(RED_LED, OUTPUT); // sets the digital pin as output
// pinMode(interruptPin, OUTPUT); //
// pinMode(sleepPin, INPUT); // sets the digital pin as input
// pinMode(wakePin, INPUT);

Blynk.begin("*******", SSID, password);

if(Blynk.connected())
{
Serial.println(“Blynk.connected”);
}

Serial.println(“Exiting Setup”);

// printf(“Buffered, will be flushed”);
// fflush(stdout); // Prints to screen or whatever your standard out is

attachInterrupt(digitalPinToInterrupt(PIR_PIN), PIR_HIGH, RISING); // use interrupt PIR_PIN and run function

}

void loop()
{
Blynk.run();
timer.run();
Serial.println(“Alive & well”);
}

void PIR_HIGH()
{
if (1 != old_motion) {
Blynk.virtualWrite(V1, HIGH); // motion detected
old_motion = 1;
detachInterrupt(digitalPinToInterrupt(PIR_PIN));
attachInterrupt(digitalPinToInterrupt(PIR_PIN), PIR_LOW, CHANGE); // use interrupt PIR_PIN and run function
}
}

void PIR_LOW()
{
// if (0 != old_motion) {
Blynk.virtualWrite(V1, LOW);
old_motion = 0;
// }

sleepNow();

}

void sleepNow() {

// Serial.println(“Entering Sleep”);
// WiFi.mode(WIFI_STA);
// WiFi.disconnect();
// digitalWrite(PIR_PIN, LOW);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open();
detachInterrupt(digitalPinToInterrupt(PIR_PIN));
attachInterrupt(digitalPinToInterrupt(PIR_PIN), PIR_HIGH, RISING); // use interrupt PIR_PIN and run function
wifi_fpm_do_sleep(0xFFFFFFF);

if(WiFi.status() != WL_CONNECTED)
{
// delay(250);
WiFi.begin(SSID, password);
// Serial.println(“WiFi.connect”);
}

if(WiFi.status() == WL_CONNECTED && !Blynk.connected())
{
// delay(250);
Blynk.connect();
// Serial.println(“Blynk.connect”);
}

// delay(1000);
// Serial.println(WiFi.localIP());
// Serial.println(“Exiting Sleep”);
}

BLYNK_WRITE(V12)
{
Blynk.virtualWrite(V12, param.asInt());

digitalWrite(V12, HIGH);
delay(500);
digitalWrite(V12, LOW);
delay(5000);
BLYNK_READ(V14);

}

BLYNK_READ(V14)
{

//* distance calc not part of the problem

}


#7

Re examine this picture…

Or copy and paste this before your code:

```ccp

…and this after:

```

Or study the motion GIF example here…

One of these should explain how to properly format your code… then please go BACK and edit your posts in this thread accordingly