with motion is 0 it is just the opposid
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "c25b0d1f67904865aba9cd5cb70e1a43";
char ssid[] = "ziggo-ap-5788707";
char pass[] = "28,a:B^S[7ZJP";
char server[] = "192.168.178.33";
#define ledPin D5
#define pirPin_1 D1
#define pirPin_2 D2
#define pirPin_3 D6
int x;
SimpleTimer timer;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0);
}
BLYNK_WRITE(V0){
x = param.asInt();
}
void PIRval(){
int val_1 = digitalRead(pirPin_1);
int val_2 = digitalRead(pirPin_2);
int val_3 = digitalRead(pirPin_3);
if ((val_1 == LOW) || (val_2 == LOW) || (val_3 == LOW)) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
void pir(void){
if (x == 1) {
if (digitalRead(pirPin_1) == LOW)
Blynk.notify("ALARM On Pirsensor 1");
if (digitalRead(pirPin_2) == LOW)
Blynk.notify("ALARM On Pirsensor 2");
if (digitalRead(pirPin_3) == LOW)
Blynk.notify("ALARM On Pirsensor 3");
}
}
void setup(){
Blynk.begin (auth, ssid, pass, server, 8080);//local server
// You can change server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(pirPin_1, INPUT_PULLUP);
pinMode(pirPin_2, INPUT_PULLUP);
pinMode(pirPin_3, INPUT_PULLUP);
timer.setInterval(1200L, PIRval);
timer.setInterval(1000L, pir);
}
void loop(){
Blynk.run();
timer.run();
}
i will try i hope it will work
You may also want to look into some type of flag for the notifications. Otherwise they will continuously be sent while it detects motion (unless that is what you want).
i only want to activate it when i leave the house…
understood, hence the arm/disarm button in the app.
But when it is armed, and it detects motion, you will continuously receive notifications until the pir resets itself.
Sounds like your home is now safe.
Just FYI … the ESP8266 has built-in pull-up resistors. You should reliably read HIGH in the absence of motion.
dous this have to be pullup?
You can use that to be safe, but I believe the internal pull-up resisters are enabled by default with the ESP8266.
You should be good to go with the last sketch @Toro_Blanco gave you. As he pointed out, just address the issue with the notifications being sent once a second while motion is detected.
Thnk you @WIckedbeernut and @Toro_Blanco for pointing me in the right direction i have a go at it tonight and tomorrow and i will report back here… THANKS for your help!
Tonight i have tested the code and hardware there are a couple of things i have found out:
The Pirsensor needs min. 5V (evendo on the pirsensor it says 3.3V This causes fluctuations)
The Pirsensor has a jumper for triger and retriger it has to be on trigger with this code
I Adjusted the code to work with only one pir sensor because i did not have a power suply that can deliver 3x 5V… thats why i just added one pirsensor.
the working code is:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
/*-----get your Auth Token in the Blynk App-----
// Go to the Project Settings (nut icon)*/
/*-----Blynk Personal tokens-----*
// 35535e2560d54dd8b40678084529b3ac Home Automation
// c25b0d1f67904865aba9cd5cb70e1a43 Doorbell
// 93b3214a2d4c4b209bf74c6148fcda55 Justins Panic device
// ad749283f7b54285b49c024d6f92f889 Feline Panic device
// e74723f1295a48f99f8f0ca6a45b9c73 frontdoor reed
// 84816a3f4c5e4eb6a3a142055186fc87 Outside Temperature
// 41d19b8d9506491597254dfcccc32435 inside Temperature
// 1f1f38bb5b5342c4855213bc976ceb25 Aquarium Relay*/
char auth[] = "c25b0d1f67904865aba9cd5cb70e1a43";
/*-----Your WiFi credentials-----*
//char ssid[] = "Guest Access";
//char pass[] = "B45342318!";*/
char ssid[] = "ziggo-3332";
char pass[] = "28342[7ZJP";
/*-----Pirsensor setup-----*
* Pin where pir sensor is connected
* on nodemcu best pins to use are:
* D5, D6, D7*/
#define ledPin D4
#define pirPin_1 D5
//#define pirPin_2 D6
//#define pirPin_3 D7
int Alarm_arm_disarm;
SimpleTimer timer;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0);
}
BLYNK_WRITE(V0){
Alarm_arm_disarm = param.asInt();
}
void PIRval(){
int val_1 = digitalRead(pirPin_1);
//int val_2 = digitalRead(pirPin_2);
//int val_3 = digitalRead(pirPin_3);
if (val_1 == HIGH){ //((val_1 == HIGH) || (val_2 == HIGH) || (val_3 == HIGH)) {
digitalWrite(ledPin, LOW);
}
else {
digitalWrite(ledPin, HIGH);
}
}
void pir(void){
if (Alarm_arm_disarm == 1) {
if (digitalRead(pirPin_1) == HIGH)
Blynk.notify("ALARM On Pirsensor 1");
// if (digitalRead(pirPin_2) == HIGH)
// Blynk.notify("ALARM On Pirsensor 2");
// if (digitalRead(pirPin_3) == HIGH)
// Blynk.notify("ALARM On Pirsensor 3");
}
}
void setup()
{
/*-----Serial Communications-----*/
//Debug console
Serial.begin(9600);
/*-----Blynk Server settings-----*
//Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);*/
Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 178, 33), 8080);
pinMode(ledPin, OUTPUT);
pinMode(pirPin_1, INPUT_PULLUP);
// pinMode(pirPin_2, INPUT);
// pinMode(pirPin_3, INPUT);
timer.setInterval(1200L, PIRval);
timer.setInterval(1000L, pir);
}
void loop()
{
Blynk.run();
timer.run();
}
And again Thnk you @WIckedbeernut and @Toro_Blanco for your help!
Be careful, this most likely means it is outputting 5V as well. ESP GPIOs are only rated for 3.3V (although there is some debate about this). I tend to err on the side of caution, and try to stick with 3.3V max on GPIO pins.
The spec says that the supply voltage is 5v to 20v and that the TTL output voltage (the voltage on the pin you’ve labelled “Data Out”) is 3.3v
The function of the trigger/retrigger selector is also explained in the spec:
Pete.
I guess that means you can disregard my previous comment.
The question is whether your power supply can deliver 3 x 65 mA = 195 mA at 5 VDC (plus the current of your NodeMCU and LED). What power supply are you using?
Hello a long time sins my last activety i worked further for my sketch… and i have a working version now but i added 2 sirens that wil be powered by the relays when there is motion detection… but i also want to swith the relay on when a reed sensor is trigerd… haw can i best acomplis that?
here is my code: