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

Alarm with multiple pir sensors

#21

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.

0 Likes

#22

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

0 Likes

#23

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.

0 Likes

#24

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?

0 Likes

#25

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.

0 Likes

#26

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

0 Likes

#27

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

0 Likes

#28

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

0 Likes

#29

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.

0 Likes

#30

What motion sensor are you using?

0 Likes

#31

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.

0 Likes

#32

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.

0 Likes

#33

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…

0 Likes

#34

7groot

0 Likes

#35

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

0 Likes

#36

0 Likes

#37

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

0 Likes

#38

This is with motion?

0 Likes

#39

without motion so its Always HIGH

0 Likes

#40

What about with motion?

0 Likes