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

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);      
  Serial.begin(115200); 
} 

Now continually monitor the  ...

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