I believe he wants to enable or disable the PIR sensing with a button (in switch mode). But too much happening in the main loop.
actually, it doesn’t seems to happen too much in main loop. there are some condition checks, that is hardly needs to much cpu time.
contrary to what a lots of people think, it is not necessary causing errors if you have lots of code in main loop. it depends what it does. for example in my current project i have around 500 lines of code in my main loop, and it works flawlessly with blynk! i think we should speak about these theories in some dedicated topics…
can we call that picture FTFC?
i guess you can figure out the meaning…
I thank everyone for the advice.
Made by this method and it worked
BLYNK_WRITE(V0)
{
x = param.asInt();
}
void loop()
{
Blynk.run();
pir();
val = digitalRead(pirPin);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
if (pirState == LOW) {
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW);
if (pirState == HIGH){
pirState = LOW;
}
}
}
void pir(){
if (x == 1)
{
if (digitalRead(pirPin) == HIGH){
Blynk.notify("MOTION detect!!!");
}
}
}
hi mr …what is the board type? nodemcu?
yes
why is not working for me…pir cannot response.can you share wiring schema?
thx
try to use this code here
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "**************************";
char ssid[] = "*********";
char pass[] = "********";
char server[] = "192.168.1.100";// your local server, otherwise it should be commented
#define ledPin 16
#define pirPin 14
int pirState;
int val = 0;
int x = 0;
SimpleTimer timer;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0);
}
BLYNK_WRITE(V0){
x = param.asInt();
}
void PIRval(){
val = digitalRead(pirPin);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
if (pirState == LOW){
pirState = HIGH;
}
else {
digitalWrite(ledPin, LOW);
}
if (pirState == HIGH){
pirState = LOW;
}
}
}
void pir(){
if (x == 1){
if (digitalRead(pirPin) == HIGH){
Blynk.notify("ALARM!!!");
}
}
}
void setup(){
Blynk.begin (auth, ssid, pass, server);//local server
// You can change server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
timer.setInterval(1000L, PIRval);
}
void loop(){
Blynk.run();
timer.run();
}
16= D0
14= D5
im edit
char server[ ]= "192.168.1.100";
to
//char server[ ] = "192.168.1.100";
and
Blynk.begin (auth, ssid, pass, server);
edit to (because im not use local server)
Blynk.begin (auth, ssid, pass);
but im move pin to D0 for led and D5 for pir input…R3 is blank (not use)
Why is not working for too me with nodemcu lolin?
something wrong?
thx for advice
I do not use resistors with PIR sensor
i will try again with your suggestion…can provide the wiring advice that works normally?
I will come to the house in the evening and again check the scheme for work capacity.
made corrections and checked, now everything is working
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "**************************";
char ssid[] = "*********";
char pass[] = "********";
char server[] = "192.168.1.100";// your local server, otherwise it should be commented
#define ledPin 12
#define pirPin 14
int pirState;
int val;
int x;
SimpleTimer timer;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0);
}
BLYNK_WRITE(V0){
x = param.asInt();
}
void PIRval(){
val = digitalRead(pirPin);
if (val == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
void pir(){
if (x == 1){
if (digitalRead(pirPin) == HIGH){
Blynk.notify("ALARM!!!");
}
}
}
void setup(){
Blynk.begin (auth, ssid, pass, server);//local server
// You can change server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
timer.setInterval(1000L, PIRval);
timer.setInterval(1000L, pir);
}
void loop(){
Blynk.run();
timer.run();
}
https://youtu.be/uVXJXGBoCHY
wow thx very much…
what happend if my pir sensor keep sent high signal frequently although there are no motion in front of my pir sensor. Sometime i work like normally.
gydota, which widgets did you use in Blynk’s settings?
Greetings
Hi!
Only Button(virtualPin 0) & Notification.
Hi!
Where do I find “#include <SimpleTimer.h>” to be included in the sketch?
When compiling this error appears: SimpleTimer.h: No such file or directory
Greetings
Don’t need it anymore… BlynkTimer is built into the Library now.
Darn pesky Docs and Announcements… no good unless actually read
Solved!
Thank’s
You’re welcome!