Alarm with multiple pir sensors

This code is getting the value from the switch widget and assigning it to the variable ‘x’. If your switch is set-up in the normal way then this will be. 0 (off) or a 1 (on).

As I said in an earlier post, it would help if you used meaningful variable names rather than just ‘x’. If your button on V0 is used to activate/deactivate the alarm system then change the name of variable ‘x’ to ‘alarm_activated’. That way, your code will be much more readable.

Pete.

i will adjust that i think it will be better to read but it will not explane why this code does not work?

can u elaborate a bit on this. Is it not connecting to the wifi, server, etc.? Are you not getting the notifications? Are your relays not working?

The more information you provide the better we can help.

if i turn on the button in the app (v0) the alarm gets activated with notifications but even if i dont connect pir sensors i still get messages that there is motion on pirsensor 1,2,3 random without any sensor connected so the code is doing that on its own?

Guess it would help if a read it a little better.

pinMode(pirPin_1, INPUT);
  pinMode(pirPin_2, INPUT);
  pinMode(pirPin_3, INPUT);

are these wired with pull-down resistors (as you are looking for the pins to become HIGH)? If not then the pins are floating and that may be causing your issue.

no they are not wired as pulldown resistors and i used the scheme Security alarm system

i only used pins that are safe to use…:roll_eyes:

It is not about them being safe. It is about there state, either HIGH/LOW.

https://www.mouser.com/blog/dont-leave-your-pins-floating

You need to connect your motion sensors.

Try this …

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
 
#define pirPin_1 D1
#define pirPin_2 D2
#define pirPin_3 D6

BlynkTimer timer;

void PIRval(void) {
   int val_1 = digitalRead(pirPin_1);
   int val_2 = digitalRead(pirPin_2);
   int val_3 = digitalRead(pirPin_3);
   
   Serial.printf("val_1: %d, val_2: %d, val_3: %d\n", val_1, val_2, val_3);
}

void setup(void) {
   Serial.begin(9600);

   pinMode(pirPin_1, INPUT);
   pinMode(pirPin_2, INPUT);
   pinMode(pirPin_3, INPUT);

   timer.setInterval(1000L, PIRval);
}

void loop(){
   timer.run();
}

We need to get your motion sensors working, then we can worry about Blynk.

What motion sensor are you using?

He will still have an issue if he doesn’t implement pull-down resistors. As the 3 input pins will be floating. His serial monitor will be putting out 0 and 1 randomly.

If he adds a relay/led it will chatter/pulse when the PIR is not detecting motion.

That is a good question. And if they happen to be able to send a LOW signal upon detection of motion, he can use the ESP’s builtin pull-up resistors and save on the hardware/wiring requirements.

Hi i had seen this video i uses his training he explanes so good and thank for pointing this out … ik think my sensors are high all the time thas what we gone try with wickedbeernut sugestion…

7groot

Just run my sketch and see if the state changes from high to low with motion.

so that is the problem! thank you! but how to use it with the pir sensor then?

This is with motion?

without motion so its Always HIGH

What about with motion?