Friday, September 22, 2023
Google search engine
HometelecomESP32-ESP8266 – MOTION SENSOR

ESP32-ESP8266 – MOTION SENSOR

1. Introduction

Currently, with the continuous development of science and technology, all daily activities are automated, robots gradually take over many positions in our daily lives. In order to have the correct and efficient operation of automation devices, sensors are one of the key components. Motion sensors are one of them, which can help detect the movement of people or objects, thereby helping mechanical devices have the correct control signals.
In this article, we will show you how to connect and operate the PIR motion sensor with ESP32-ESP8266 using visual studio code included with the IO IDE platform. Through this tutorial, you will be able to apply motion sensors to your projects, making your products smarter.

2. SENSOR-MODULE/EXPANSION BOARD PINOUT DIAGRAM

2.1. Hardware Introduction

2.1.1. Module ESP32

In this project, they will need to use the esp32 module, specifically I chose esp32 wroom devkit v1. Picture below
ESP32-WROOM-32 is a powerful, generic Wi-Fi+BT+BLE MCU module that targets a wide variety of applications, ranging from low-power sensor networks to the most demanding tasks, such as voice encoding, music streaming and MP3 decoding.
At the core of this module is the ESP32-D0WDQ6 chip*. The chip embedded is designed to be scalable and adaptive. There are two CPU cores that can be individually controlled, and the CPU clock frequency is adjustable from 80 MHz to 240 MHz. The chip also has a low-power co-processor that can be used instead of the CPU to save power while performing tasks that do not require much computing power, such as monitoring of peripherals. ESP32 integrates a rich set of peripherals, ranging from capacitive touch sensors, Hall sensors, SD card interface, Ethernet, high-speed SPI, UART, I²S and I²C.

2.1.2. Module ESP8266

Espressif’s ESP8266EX delivers a highly integrated Wi-Fi SoC solution to meet users’ continuous demands for efficient power usage, compact design and reliable performance in the Internet of Things industry.

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.

Besides the Wi-Fi functionalities, ESP8266EX also integrates an enhanced version of Tensilica’s L106 Diamond series 32-bit processor and on-chip SRAM. It can be interfaced with external sensors and other devices through the GPIOs. Software Development Kit (SDK) provides sample codes for various applications.

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);
                                } 

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments