Code for PIR Motion Sensor not showing any output with Blynk

128 Views Asked by At

So in this project, I'm trying to connect my PIR sensor switch on Blynk to switch on/off through my phone. Although this code compiles just fine, I'm not getting any output from the PIR sensor or LED. I connect it through an ESP8266-01 with my Arduino board. So now I'm confused with either my code has an error or just my PIR sensor is not working. Please help. Thank you guys in advance.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

int led = 9;
int sensor =2;
int state = LOW;    //default, no motion detected
int val = 0;       //variable to store sensor data status

char auth[] = "aIUaQ3TPypvl9uajcOgMHhaWpSkc8dkz";
char ssid[] = "im kinda sus";
char pass[] = "ilovearduino";

void setup(){
Serial.begin(115200);     //getting ready to communicate
Blynk.begin(auth, ssid, pass);
pinMode(led,OUTPUT);        //define led as the output
pinMode(sensor, INPUT);      //define sensor as the input
}


void pirSensor(){
val = digitalRead(sensor);    //read sensor input
if(val == HIGH){    
digitalWrite(led,HIGH);     //if value is high, led light up
delay(500);

if(state == LOW){     //if pir state is low
  Serial.println("Motion Detected!");   //print this line
  state = HIGH;   //pir sensor detect motion
}
}
else if(state == HIGH) {
      digitalWrite(led, LOW);   // if not led turn off
      delay(500);
      Serial.println("Motion Stopped!");    // print this line
      state = LOW; 
      }

}

BLYNK_WRITE(V0){
int led = param.asInt(); //led is connected to virtual pin 0
}

void loop(){
Blynk.run();  //blynk starts to run

}
0

There are 0 best solutions below