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

How can I Manually switch the PIR sensor

#1

hello Every one :slight_smile:
I am asking if how can manually switch on/off the PiR
I want it send me notification only when I switch the virtual LED on
this may code

WidgetLED led8_pir(V20);
void PRCS() // function
{
pir=1-(digitalRead(49));
if ((pir == LOW )&&( V20==HIGH))
{

   Blynk.notify("Movement Detected!");
  }

}
void loop()
{
BLYNK_WRITE(V21) {
if (param.asInt()) {

led8_pir.on();
} else {
led8_pir.off();
}
}

0 Likes

#2

What micro controller do you user? ESP8266 disturbs PIRs and generates false detections. Only for information…

0 Likes

#3

hello bernd331 :slight_smile:
I ma use Arduino mega 2560

0 Likes

#4

@bernd331
Could you explain what you mean by “ESP8266 disturbs PIRs and generates false detections”? Is there some sort of RF or electrical interference going on?

0 Likes

#5

I have seen that if I connect a PIR HS-SR501 to an ESP8266 I get false positives from the PIR.

The Internet says that the 2.4GHz interferences with the PIR-Sensor. There are a lot of tips out in the internet what to do to supress the false positives.But I have seen that in long term the fals positives always exists. In best case I got 2 or 3 false positives per hour. This best case was when I supplied the PIR with a seperate power supply and put the PIR in a metal box.

If somebody find’s a solution please let me knew :slight_smile:

Greetz, Bernd

0 Likes

#6

Assuming you want to be able to set a switch on the dashboard to determine when you get notified of motion from the PIR, you could do something like this: (this is a code fragment, of course, and not tested in any way)

#include <SimpleTimer.h>

#define LED                V0
#define SWITCH            V1
#define STATUS_DELAY    2000L            // 2 seconds in msec
#define PIR_PIN            2                // Uno or Mega interrupt-enabled GPIO pin

WidgetLED Indicator(LED);
SimpleTimer timer;

bool enabled = false;
volatile bool motion = false;
bool sendUpdate = false;

// configure dashboard button V1 as a SWITCH
BLYNK_WRITE (SWITCH) {
    enabled = param.asInt();
}

void motionDetected ( void ) {
    motion = true;
}

// only send notifications at specified intervals to avoid flood errors
void sendNotify ( void ) {
    if ( sendUpdate ) {
        Blynk.notify("Motion detected");
        sendUpdate = false;
    }
}

void setup ( void ) {
    ...
    attachInterrupt(digitalPinToInterrupt(PIR_PIN), motionDetected, RISING);
    timer.setInterval(STATUS_DELAY, sendNotify);
    Indicator.off();
}

void loop ( void ) {
    ...
    Blynk.run();
    timer.run();
    if ( enabled ) {
        if ( motion ) {
            // switch on the dashboard LED, set the flag to get a notification on next timer cycle, and reset motion flag
            Indicator.on();
            motion = false;
            sendUpdate = true;
        } else {
            Indicator.off();
        }
    }
}

Enjoy.

RD7

0 Likes

#7

@Rom3oDelta7
Thank you for sharing this code, I am using this code on esp8266. But the problem is when I enable the SWITCH i get push notification straight away even though there is no movement and its keep coming in every two second as STATUS_DELAY.I just want to get the notification only if there is any motion detected. What should I add to get this ?? TIA

0 Likes

#8

did u ever find a fix for this i tried search and no luck???

0 Likes

#9

Which parts of “untested code fragment” (not to mention a not particularly well devised and messy loop) and date code indicating the rather old age of this topic are confusing :stuck_out_tongue:

@coz773… if you have actual Blynk code of your own that you need some advice with, I recommend you create a newer relevant topic, show what you have and what you have tried… and go into this looking for guidance, not some magic solution for what is essentially a logic if else() question, not a distinctly searchable “fix” :wink:

0 Likes

closed #10
0 Likes