1. Introduction
2. SENSOR-MODULE/EXPANSION BOARD PINOUT DIAGRAM
2.1. Hardware Introduction
2.1.1. Module ESP32


2.1.2. Module ESP8266
With the complete and self-contained Wi-Fi networking capabilities, ESP8266EX can perform either as a standalone application or as the slave to a host MCU. When ESP8266EX hosts the application, it promptly boots up from the flash. The integrated high speed cache helps to increase the system performance and optimize the system memory. Also, ESP8266EX can be applied to any microcontroller design as a Wi-Fi adapter through SPI/SDIO or UART interfaces.
With the complete and self-contained Wi-Fi networking capabilities, ESP8266EX can perform either as a standalone application or as the slave to a host MCU. When ESP8266EX hosts the application, it promptly boots up from the flash. The integrated high speed cache helps to increase the system performance and optimize the system memory. Also, ESP8266EX can be applied to any microcontroller design as a Wi-Fi adapter through SPI/SDIO or UART interfaces.
Espressif Systems’ Smart Connectivity Platform (ESCP) enables sophisticated features including:
- Fast switch between sleep and wakeup mode for energy-efficient purpose;
- Adaptive radio biasing for low-power operation
- Advance signal processing
- Spur cancellation and RF coexistence mechanisms for common cellular, Bluetooth, DDR, LVDS, LCD interference mitigation


Motion sensor
A motion sensor (or motion detector) is the linchpin of your security system because it detects when someone is in your home when they shouldn’t be. A motion sensor uses one or multiple technologies to detect movement in an area.
When a sensor detects motion, it sends a signal to your security system’s control panel, which connects to your monitoring center. This alerts you and the monitoring center to a potential threat in your home.
Types of motion sensors:
Passive infrared (PIR)
A passive infrared sensor detects body heat (infrared energy) by looking for changes in temperatures. This is the most-widely-used motion sensor in home security systems. When you arm your system, this activates the motion sensors to report possible threats.
A passive infrared sensor detects body heat (infrared energy) by looking for changes in temperatures. This is the most-widely-used motion sensor in home security systems. When you arm your system, this activates the motion sensors to report possible threats.

Microwave (MW)
This type of sensor sends out microwave pulses and measures the reflections off of moving objects.1 They cover a larger area than infrared sensors but are more expensive and vulnerable to electrical interference.

Dual technology motion sensors
Some motion sensors can combine multiple detection methods in an attempt to reduce false alarms. For example, it’s not uncommon for a dual technology sensor to combine a passive infrared (PIR) sensor with a microwave sensor.
Each sensor type operates in different areas of the spectrum (ranging from passive to active). Dual technology motion sensors are not as likely as other types to cause a false alarm, because both sensors need to trip in order to sound an alarm. However, this does not mean that they never cause false alarms.
In this tutorial, I will use PIR sensor (picture 6)

Specification for PIR Sensor:
+ Voltage: 5V – 20V
+ Power Consumption: 65mA
+ TTL output: 3.3V, 0V
+ Delay time: Adjustable (.3->5min)
+ Lock time: 0.2 sec
+ Trigger methods: L – disable repeat trigger, H enable repeat trigger
+ Sensing range: less than 120 degree, within 7 meters
+ Temperature: – 15 ~ +70
+ Dimension: 32*24 mm, distance between screw 28mm, M2, Lens dimension in diameter: 23mm
PIR Sensor Pinout

2.1.3.Module relay
The relay module is an electrically operated switch that allows you to turn on or off a circuit using voltage and/or current much higher than a microcontroller could handle. There is no connection between the low voltage circuit operated by the microcontroller and the high power circuit. The relay protects each circuit from each other.
Each channel in the module has three connections named NC, COM, and NO. Depending on the input signal trigger mode, the jumper cap can be placed at high level effective mode which ‘closes’ the normally open (NO) switch at high level input and at low level effective mode which operates the same but at low level input.

Relay Module Specification:
+ On-board EL817 photoelectric coupler with photoelectric isolating anti interference ability strong
+ On-board 5V, 10A / 250VAC, 10A / 30VDC relays
+ Relay long life can absorb 100000 times in a row
+ Module can be directly and MCU I/O link, with the output signal indicator
+ Module with diode current protection, short response time
Relay Module PIN Specifications

2.2. ESP32 Connectivity Diagram

ESP32 PIR Circuit Diagram

ESP32 PIR Sensor Actual circuit Diagram

ESP8266 Connectivity Diagram

ESP8266 PIR Motion Sensor Circuit Diagram



Source code:


Source Code ESP32:
#include <Arduino.h>
#define PIN_PIR 25
#define PIN_RELAY 26
void setup()
{
Serial.begin(115200);
z pinMode(PIN_PIR,INPUT); // set pin 7 input
pinMode(PIN_RELAY,OUTPUT); // set pin 2 output
digitalWrite(PIN_RELAY,LOW); // turn off relay
}
void loop()
{
if (digitalRead(PIN_PIR) == true)
{
Serial.println(“have motion”);
digitalWrite(PIN_RELAY,HIGH);
delay(5000); // turn on light 5s
digitalWrite(PIN_RELAY,LOW);
}
}
Source esp8266
#include <Arduino.h>
#define PIN_PIR D2
#define PIN_RELAY D5
void setup()
{
Serial.begin(115200);
pinMode(PIN_PIR,INPUT); // set pin D2 input
pinMode(PIN_RELAY,OUTPUT); // set pin D5 output
digitalWrite(PIN_RELAY,LOW); // turn off relay
}
void loop()
{
if (digitalRead(PIN_PIR) == true)
{
Serial.println(“have motion”);
digitalWrite(PIN_RELAY,HIGH);
delay(5000); // turn on light 5s
digitalWrite(PIN_RELAY,LOW);
}
}