O'Reilly logo

ESP8266 Home Automation Projects by Catalin Batrinu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The ESP8266 PIR security code

For the ESP8266 and PIR module to work with the defined Blynk application, it includes the Blynk header, the Simple timer, and defines the BLYNK_PRINT as serial for debugging purposes.  You need to run the following code:

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

Go to the Mobile application and then to Project Settings and email yourself the app_token:

char app_token[] = "TOKEN_FROM_EMAIL"; 
SimpleTimer timer; 
char ssid[] = "YOUR_WIFI_NETWORK"; 
char pass[] = "YOUR_PASSWORD"; 
int state; 
int counter=0; 
int flag=1; 
WidgetLED led1(V1); 
WidgetLED pirLED(V2); 

This is the timer function that will be called every second to check the status of the PIR ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required