Testing the PIR module

For now, let's test the PIR module to check that it is working. In order to achieve this you will need:

  • An ESP8266 module (NodeMCU, WeMos, or an other board)
  • A PIR module
  • A Breadboard
  • Wires

For the software part use the following sketch:

  • Define the PIR as it will be connected to the D7 pin, set the pirState to LOW assuming that the PIR is OFF, and set the current state to 0:
#define PIN_PIR  D7              
int pirState = LOW;              
int current_value = 0;                     
  • During setup we will declare the D7 pin where the PIR is connected to an input pin:
void setup() { 
  pinMode(PIN_PIR, INPUT);      

Now continually monitor the  ...

Get ESP8266 Home Automation Projects now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.