esp8266 motion sensor Interfacing | esp8266 Tutorial


Hey guys, welcome back to Techatronic. Hope you are doing fine. So today we will discuss the working of an esp8266 motion sensor. Well, I hope you know what a PIR sensor is.

HTML Image as link

If not then don’t worry we will give you a brief introduction to it. Before starting I would like to give you a superb offer that our E-book on Arduino is now available at a special discount. This E-book has 10+ interesting projects with well-explained code and working.

So PIR stands for passive infrared and it is used for detecting the motion of the body in its range. They are available in different ranges and sizes.

The PIR sensor that we use in this project is of small size and range. Make the connections as per the diagram given below and then upload the code.

HTML Image as link
esp8266 motion sensor system

esp8266 motion sensor Working

Initially, both the LEDs are turned on and later they will glow according to the signals that are generated by the PIR sensor.

If the PIR sensor detects some movement in its range then both the LEDs will glow and the buzzer also starts beeping else only one LED will glow and the buzzer is silent.

In this esp8266 tutorial,

we will make a useful system. This system is very useful for making various security systems and alert systems. You can also add more components to the circuit to enhance security.

You can also see the values generated by the PIR sensor on the serial monitor screen. We have attached some screenshots below. You can also read the Arduino-based home security system using Arduino made by us.

pir motion sensor

Simulation on Serial monitor

esp8266 serial monitor
esp8266 serial monitor

Components Required

  • ESP8266 nodemcu board
  • PIR motion sensor
  • Buzzer
  • Two LEDs and a breadboard
  • Jumper wires
  • 220-ohm resistor
  • USB cable for uploading the code
esp8266 serial pir monitor component

esp8266 motion sensor Circuit Diagram

esp8266 motion sensor circuit diagram

Connection diagram

Nodemcu esp8266PIR Motion Sensor
D2 PinOUT Pin
Nodemcu esp8266Buzzer
D7 PinPositive
GND Negative
ArduinoLED GLED R220 Ohm Resistor
D7 PinAnode Pin  
D6 Pin Anode Pin 
 Cathode PinCathode PinTerminal 1
GND  Terminal 2
  • Connect three jumper wires to the PIR motion sensor.
  • Join the VCC pin of the PIR sensor with the VIN pin of the nodemcu.
  • Attach the GND pin of the PIR sensor to the GND pin of the nodemcu.
  • Connect the OUT pin of the PIR sensor with the digital-1 pin of the nodemcu.
  • Take the buzzer and join its positive leg with the digital-7 pin of the nodemcu.
  • Attach the negative leg of the buzzer with the GND pin of the nodemcu.
  • esp8266 motion sensor interfacing is quite easy.
  • After it takes two LEDs and places them on the breadboard.
  • Connect the positive leg of the first LED with the digital-5 pin of the nodemcu and the positive leg of the second LED with the digital-6 pin of the nodemcu.
  • Join the negative legs of both the LEDs with the GND pin of the nodemcu via 220-ohm resistors.
  • Now proceed forward to the code section.

PCBWay PCB Prototyping Services

I have assembled the whole circuit on a breadboard. As you know breadboard assembly is not effective for this type of projects. So, PCBWay offers Rapid PCB Prototyping for Your Research Work. I personally, recommend PCBWay because you can get your first-try boards right in 24 hours!

PCBWay website

The prototyping stage is the most critical period of time for engineers, students, and hobbyists. PCBWay not only makes your boards quick but also makes your job right as well as cost-effective. This greatly reduces your cost and shortens the time for developing your electronic products.

PCBWay can provide 2 Layer PCBs to highly advanced HDI and flex boards. Even though the PCBs they produce differ a lot regarding functionality and areas of use. I am impressed with the quality of the boards, the delivery time, and the cost-effectiveness.

esp8266 motion sensor Code

NOTE: Please upload the code which is given below to the nodemcu.

 int val = 0 ;  
 void setup()  
   Serial.begin(9600); // sensor buart rate  
   pinMode(14,HIGH);  // Green led Pin Connected To D5 Pin   
   pinMode(13,HIGH);  // Buzzer Pin Connected To D7 Pin   
   pinMode(12,HIGH);  // Red Led Connected To D6 Pin    
 void loop()   
  val = digitalRead(5); // PIR Sensor output pin connected to D1   
  Serial.println(val);  // see the value in serial m0nitor in Arduino IDE  
  delay(200);      // for timer  
  if(val == 1 )  
   digitalWrite(14,HIGH); // Green LED ON  
   digitalWrite(13,HIGH); // Buzzer ON  
   digitalWrite(12,LOW);  // Red LED ON  
   digitalWrite(14,LOW);  // Green LED OFF  
   digitalWrite(13,LOW);  // Buzzer OFF  
   digitalWrite(12,HIGH); // Red LED ON  
esp8266 motion sensor system

We hope that you like this esp8266 tutorial and understand the complete procedure that we are trying to explain here. For any doubts regarding this project please ping us in the comments section given below. Also, do check out more such amazing tutorials on Arduino and Raspberry Pi.


Video sample

Spread the love

Leave a Comment